Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: mojo/public/bindings/mojom_bindings_generator.py

Issue 177183002: Mojo: Include "path/to/foo.mojom.h" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove unnecessary abspath Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """The frontend for the Mojo bindings system.""" 6 """The frontend for the Mojo bindings system."""
7 7
8 8
9 import argparse 9 import argparse
10 import imp 10 import imp
(...skipping 26 matching lines...) Expand all
37 elif generator_name.endswith(".py"): 37 elif generator_name.endswith(".py"):
38 pass 38 pass
39 else: 39 else:
40 print "Unknown generator name %s" % generator_name 40 print "Unknown generator name %s" % generator_name
41 sys.exit(1) 41 sys.exit(1)
42 generator_module = imp.load_source(os.path.basename(generator_name)[:-3], 42 generator_module = imp.load_source(os.path.basename(generator_name)[:-3],
43 generator_name) 43 generator_name)
44 generators.append(generator_module) 44 generators.append(generator_module)
45 return generators 45 return generators
46 46
47
47 def ProcessFile(args, generator_modules, filename, processed_files): 48 def ProcessFile(args, generator_modules, filename, processed_files):
48 # Ensure we only visit each file once. 49 # Ensure we only visit each file once.
49 if filename in processed_files: 50 if filename in processed_files:
50 if processed_files[filename] is None: 51 if processed_files[filename] is None:
51 raise Exception("Circular dependency: " + filename) 52 raise Exception("Circular dependency: " + filename)
52 return processed_files[filename] 53 return processed_files[filename]
53 processed_files[filename] = None 54 processed_files[filename] = None
54 55
55 dirname, name = os.path.split(filename) 56 dirname, name = os.path.split(filename)
56 name = os.path.splitext(name)[0]
57 # TODO(darin): There's clearly too many layers of translation here! We can 57 # TODO(darin): There's clearly too many layers of translation here! We can
58 # at least avoid generating the serialized Mojom IR. 58 # at least avoid generating the serialized Mojom IR.
59 tree = mojo_parser.Parse(filename) 59 tree = mojo_parser.Parse(filename)
60 mojom = mojo_translate.Translate(tree, name) 60 mojom = mojo_translate.Translate(tree, name)
61 if args.debug_print_intermediate: 61 if args.debug_print_intermediate:
62 pprint.PrettyPrinter().pprint(mojom) 62 pprint.PrettyPrinter().pprint(mojom)
63 63
64 # Process all our imports first and collect the module object for each. 64 # Process all our imports first and collect the module object for each.
65 # We use these to generate proper type info. 65 # We use these to generate proper type info.
66 for import_data in mojom['imports']: 66 for import_data in mojom['imports']:
67 import_filename = os.path.join(dirname, import_data['filename']) 67 import_filename = os.path.join(dirname, import_data['filename'])
68 import_data['module'] = ProcessFile( 68 import_data['module'] = ProcessFile(
69 args, generator_modules, import_filename, processed_files) 69 args, generator_modules, import_filename, processed_files)
70 70
71 module = mojom_data.OrderedModuleFromData(mojom) 71 module = mojom_data.OrderedModuleFromData(mojom)
72
73 # Set the path as relative to the source root.
74 module.path = os.path.relpath(os.path.abspath(filename),
75 os.path.abspath(args.depth))
76
77 # Normalize to unix-style path here to keep the generators simpler.
78 module.path = module.path.replace('\\', '/')
79
72 for generator_module in generator_modules: 80 for generator_module in generator_modules:
73 generator = generator_module.Generator(module, args.include_dir, 81 generator = generator_module.Generator(module, args.output_dir)
74 args.output_dir)
75 generator.GenerateFiles() 82 generator.GenerateFiles()
76 83
77 processed_files[filename] = module 84 processed_files[filename] = module
78 return module 85 return module
79 86
87
80 def Main(): 88 def Main():
81 parser = argparse.ArgumentParser( 89 parser = argparse.ArgumentParser(
82 description="Generate bindings from mojom files.") 90 description="Generate bindings from mojom files.")
83 parser.add_argument("filename", nargs="+", 91 parser.add_argument("filename", nargs="+",
84 help="mojom input file") 92 help="mojom input file")
85 parser.add_argument("-i", "--include_dir", dest="include_dir", default=".", 93 parser.add_argument("-d", "--depth", dest="depth", default=".",
86 help="include path for #includes") 94 help="depth from source root")
87 parser.add_argument("-o", "--output_dir", dest="output_dir", default=".", 95 parser.add_argument("-o", "--output_dir", dest="output_dir", default=".",
88 help="output directory for generated files") 96 help="output directory for generated files")
89 parser.add_argument("-g", "--generators", dest="generators_string", 97 parser.add_argument("-g", "--generators", dest="generators_string",
90 metavar="GENERATORS", default="c++,javascript", 98 metavar="GENERATORS", default="c++,javascript",
91 help="comma-separated list of generators") 99 help="comma-separated list of generators")
92 parser.add_argument("--debug_print_intermediate", action="store_true", 100 parser.add_argument("--debug_print_intermediate", action="store_true",
93 help="print the intermediate representation") 101 help="print the intermediate representation")
94 args = parser.parse_args() 102 args = parser.parse_args()
95 103
96 generator_modules = LoadGenerators(args.generators_string) 104 generator_modules = LoadGenerators(args.generators_string)
97 105
98 if not os.path.exists(args.output_dir): 106 if not os.path.exists(args.output_dir):
99 os.makedirs(args.output_dir) 107 os.makedirs(args.output_dir)
100 108
101 for filename in args.filename: 109 for filename in args.filename:
102 ProcessFile(args, generator_modules, filename, {}) 110 ProcessFile(args, generator_modules, filename, {})
103 111
104 return 0 112 return 0
105 113
106 114
107 if __name__ == "__main__": 115 if __name__ == "__main__":
108 sys.exit(Main()) 116 sys.exit(Main())
OLDNEW
« no previous file with comments | « mojo/public/bindings/mojom_bindings_generator.gypi ('k') | mojo/public/bindings/pylib/generate/mojom.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698