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

Side by Side Diff: mojo/public/tools/bindings/run_code_generators.py

Issue 1566203002: Only generate code for files that are specified, not their imports. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « mojo/public/tools/bindings/mojom_bindings_generator_v2.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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='Filter on the set of .mojom files for which code '
27 '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",
35 default="c++,dart,go,javascript,java,python", 38 default="c++,dart,go,javascript,java,python",
36 help="comma-separated list of generators") 39 help="comma-separated list of generators")
37 parser.add_argument("-d", "--depth", dest="depth", default=".", 40 parser.add_argument("-d", "--depth", dest="depth", default=".",
38 help="relative path to the root of the source tree.") 41 help="relative path to the root of the source tree.")
42 parser.add_argument("--no-gen-imports", action="store_true",
43 help="Generate code only for the files that are "
44 "specified on the command line. By default, code "
45 "is generated for all specified files and their "
46 "transitive imports.")
39 parser.add_argument("--generate-type-info", dest="generate_type_info", 47 parser.add_argument("--generate-type-info", dest="generate_type_info",
40 action="store_true", 48 action="store_true",
41 help="generate mojom type descriptors") 49 help="generate mojom type descriptors")
42 parser.add_argument("--no-generate-type-info", dest="generate_type_info", 50 parser.add_argument("--no-generate-type-info", dest="generate_type_info",
43 action="store_false", 51 action="store_false",
44 help="do not generate mojom type descriptors") 52 help="do not generate mojom type descriptors")
45 parser.set_defaults(generate_type_info=True) 53 parser.set_defaults(generate_type_info=True)
46 54
47 return parser.parse_known_args() 55 return parser.parse_known_args()
48 56
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 160
153 if args.file_graph == '-': 161 if args.file_graph == '-':
154 fp = sys.stdin 162 fp = sys.stdin
155 else: 163 else:
156 fp = open(args.file_graph) 164 fp = open(args.file_graph)
157 165
158 mojom_file_graph = ReadMojomFileGraphFromFile(fp) 166 mojom_file_graph = ReadMojomFileGraphFromFile(fp)
159 modules = mojom_translator.TranslateFileGraph(mojom_file_graph) 167 modules = mojom_translator.TranslateFileGraph(mojom_file_graph)
160 168
161 generator_modules = LoadGenerators(args.generators_string) 169 generator_modules = LoadGenerators(args.generators_string)
170 filenames = set(os.path.basename(filename) for filename in args.filenames)
162 171
163 for _, module in modules.iteritems(): 172 for _, module in modules.iteritems():
173 # If filenames are specified on the command line, only generate code for
174 # the specified mojom files.
175 # TODO(azani): This is not as robust as we would like since files with the
176 # same name but different paths or files resolved through links might not
177 # be correctly identified by module.name.
178 if args.no_gen_imports and filenames and module.name not in filenames:
179 continue
164 FixModulePath(module, os.path.abspath(args.depth)) 180 FixModulePath(module, os.path.abspath(args.depth))
165 for generator_module in generator_modules: 181 for generator_module in generator_modules:
166 generator = generator_module.Generator(module, args.output_dir) 182 generator = generator_module.Generator(module, args.output_dir)
167 183
168 # Look at unparsed args for generator-specific args. 184 # Look at unparsed args for generator-specific args.
169 filtered_args = [] 185 filtered_args = []
170 if hasattr(generator_module, 'GENERATOR_PREFIX'): 186 if hasattr(generator_module, 'GENERATOR_PREFIX'):
171 prefix = '--' + generator_module.GENERATOR_PREFIX + '_' 187 prefix = '--' + generator_module.GENERATOR_PREFIX + '_'
172 filtered_args = [arg for arg in remaining_args 188 filtered_args = [arg for arg in remaining_args
173 if arg.startswith(prefix)] 189 if arg.startswith(prefix)]
174 if args.generate_type_info: 190 if args.generate_type_info:
175 filtered_args.append("--generate_type_info") 191 filtered_args.append("--generate_type_info")
176 192
177 generator.GenerateFiles(filtered_args) 193 generator.GenerateFiles(filtered_args)
178 194
179 195
180 if __name__ == "__main__": 196 if __name__ == "__main__":
181 sys.exit(main()) 197 sys.exit(main())
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/mojom_bindings_generator_v2.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698