OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 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 # This script accepts the output of version 2 of the mojom parser and uses that | 6 # This script accepts the output of version 2 of the mojom parser and uses that |
7 # data to invoke the code generators. | 7 # data to invoke the code generators. |
8 | 8 |
9 import argparse | 9 import argparse |
10 import imp | 10 import imp |
11 import os | 11 import os |
12 import sys | 12 import sys |
13 | 13 |
14 | 14 |
15 def _ParseCLIArgs(): | 15 def _ParseCLIArgs(): |
16 """Parses the command line arguments. | 16 """Parses the command line arguments. |
17 | 17 |
18 Returns: | 18 Returns: |
19 tuple<Namespace, list<str>> The first value of the tuple is a Namespace | 19 tuple<Namespace, list<str>> The first value of the tuple is a Namespace |
20 holding the value of the optional args. The second value of the tuple is | 20 holding the value of the optional args. The second value of the tuple is |
21 a list of the remaining arguments. | 21 a list of the remaining arguments. |
22 """ | 22 """ |
23 parser = argparse.ArgumentParser( | 23 parser = argparse.ArgumentParser( |
24 description='Generate bindings from mojom parser output.') | 24 description='Generate bindings from mojom parser output.') |
25 parser.add_argument('filenames', nargs='*', | |
26 help='Mojom files to be generated. If empty, every file' | |
rudominer
2016/01/07 22:25:49
"Mojom files to be generated" is not a precise des
| |
27 'in the provided graph will be generated.') | |
25 parser.add_argument('-f', '--file-graph', dest='file_graph', | 28 parser.add_argument('-f', '--file-graph', dest='file_graph', |
26 help='Location of the parser output. "-" for stdin. ' | 29 help='Location of the parser output. "-" for stdin. ' |
27 '(default "-")', default='-') | 30 '(default "-")', default='-') |
28 parser.add_argument('-p', '--python-sdk-dir', dest='python_sdk_dir', | 31 parser.add_argument('-p', '--python-sdk-dir', dest='python_sdk_dir', |
29 default=None, | 32 default=None, |
30 help='Location of the compiled python bindings') | 33 help='Location of the compiled python bindings') |
31 parser.add_argument("-o", "--output-dir", dest="output_dir", default=".", | 34 parser.add_argument("-o", "--output-dir", dest="output_dir", default=".", |
32 help="output directory for generated files") | 35 help="output directory for generated files") |
33 parser.add_argument("-g", "--generators", dest="generators_string", | 36 parser.add_argument("-g", "--generators", dest="generators_string", |
34 metavar="GENERATORS", | 37 metavar="GENERATORS", |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 | 148 |
146 if args.file_graph == '-': | 149 if args.file_graph == '-': |
147 fp = sys.stdin | 150 fp = sys.stdin |
148 else: | 151 else: |
149 fp = open(args.file_graph) | 152 fp = open(args.file_graph) |
150 | 153 |
151 mojom_file_graph = ReadMojomFileGraphFromFile(fp) | 154 mojom_file_graph = ReadMojomFileGraphFromFile(fp) |
152 modules = mojom_translator.TranslateFileGraph(mojom_file_graph) | 155 modules = mojom_translator.TranslateFileGraph(mojom_file_graph) |
153 | 156 |
154 generator_modules = LoadGenerators(args.generators_string) | 157 generator_modules = LoadGenerators(args.generators_string) |
158 filenames = set(os.path.basename(filename) for filename in args.filenames) | |
155 | 159 |
156 for _, module in modules.iteritems(): | 160 for _, module in modules.iteritems(): |
161 # If filenames are specified on the command line, only generate code for | |
162 # the specified mojom files. | |
163 # TODO(azani): This is not as robust as we would like since files with the | |
164 # same name but different paths or files resolved through links might not | |
165 # be correctly identified by module.name. | |
166 if filenames and module.name not in filenames: | |
167 continue | |
157 FixModulePath(module, os.path.abspath(args.depth)) | 168 FixModulePath(module, os.path.abspath(args.depth)) |
158 for generator_module in generator_modules: | 169 for generator_module in generator_modules: |
159 generator = generator_module.Generator(module, args.output_dir) | 170 generator = generator_module.Generator(module, args.output_dir) |
160 | 171 |
161 # Look at unparsed args for generator-specific args. | 172 # Look at unparsed args for generator-specific args. |
162 filtered_args = [] | 173 filtered_args = [] |
163 if hasattr(generator_module, 'GENERATOR_PREFIX'): | 174 if hasattr(generator_module, 'GENERATOR_PREFIX'): |
164 prefix = '--' + generator_module.GENERATOR_PREFIX + '_' | 175 prefix = '--' + generator_module.GENERATOR_PREFIX + '_' |
165 filtered_args = [arg for arg in remaining_args | 176 filtered_args = [arg for arg in remaining_args |
166 if arg.startswith(prefix)] | 177 if arg.startswith(prefix)] |
167 | 178 |
168 generator.GenerateFiles(filtered_args) | 179 generator.GenerateFiles(filtered_args) |
169 | 180 |
170 | 181 |
171 if __name__ == "__main__": | 182 if __name__ == "__main__": |
172 sys.exit(main()) | 183 sys.exit(main()) |
OLD | NEW |