OLD | NEW |
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 hashlib | 10 import hashlib |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 return self._GenerateModule(args, remaining_args, generator_modules, | 168 return self._GenerateModule(args, remaining_args, generator_modules, |
169 RelativePath(filename, args.depth)) | 169 RelativePath(filename, args.depth)) |
170 | 170 |
171 def _GenerateModule(self, args, remaining_args, generator_modules, | 171 def _GenerateModule(self, args, remaining_args, generator_modules, |
172 rel_filename): | 172 rel_filename): |
173 # Return the already-generated module. | 173 # Return the already-generated module. |
174 if rel_filename.path in self._processed_files: | 174 if rel_filename.path in self._processed_files: |
175 return self._processed_files[rel_filename.path] | 175 return self._processed_files[rel_filename.path] |
176 tree = self._parsed_files[rel_filename.path] | 176 tree = self._parsed_files[rel_filename.path] |
177 | 177 |
178 dirname, name = os.path.split(rel_filename.path) | 178 dirname = os.path.dirname(rel_filename.path) |
179 | 179 |
180 # Process all our imports first and collect the module object for each. | 180 # Process all our imports first and collect the module object for each. |
181 # We use these to generate proper type info. | 181 # We use these to generate proper type info. |
182 imports = {} | 182 imports = {} |
183 for parsed_imp in tree.import_list: | 183 for parsed_imp in tree.import_list: |
184 rel_import_file = FindImportFile( | 184 rel_import_file = FindImportFile( |
185 RelativePath(dirname, rel_filename.source_root), | 185 RelativePath(dirname, rel_filename.source_root), |
186 parsed_imp.import_filename, args.import_directories) | 186 parsed_imp.import_filename, args.import_directories) |
187 imports[parsed_imp.import_filename] = self._GenerateModule( | 187 imports[parsed_imp.import_filename] = self._GenerateModule( |
188 args, remaining_args, generator_modules, rel_import_file) | 188 args, remaining_args, generator_modules, rel_import_file) |
189 | 189 |
190 module = translate.OrderedModule(tree, name, imports) | 190 # Set the module path as relative to the source root. |
| 191 # Normalize to unix-style path here to keep the generators simpler. |
| 192 module_path = rel_filename.relative_path().replace('\\', '/') |
| 193 |
| 194 module = translate.OrderedModule(tree, module_path, imports) |
191 | 195 |
192 if args.scrambled_message_id_salt: | 196 if args.scrambled_message_id_salt: |
193 ScrambleMethodOrdinals(module.interfaces, args.scrambled_message_id_salt) | 197 ScrambleMethodOrdinals(module.interfaces, args.scrambled_message_id_salt) |
194 | 198 |
195 # Set the path as relative to the source root. | |
196 module.path = rel_filename.relative_path() | |
197 | |
198 # Normalize to unix-style path here to keep the generators simpler. | |
199 module.path = module.path.replace('\\', '/') | |
200 | |
201 if self._should_generate(rel_filename.path): | 199 if self._should_generate(rel_filename.path): |
202 AddComputedData(module) | 200 AddComputedData(module) |
203 for language, generator_module in generator_modules.iteritems(): | 201 for language, generator_module in generator_modules.iteritems(): |
204 generator = generator_module.Generator( | 202 generator = generator_module.Generator( |
205 module, args.output_dir, typemap=self._typemap.get(language, {}), | 203 module, args.output_dir, typemap=self._typemap.get(language, {}), |
206 variant=args.variant, bytecode_path=args.bytecode_path, | 204 variant=args.variant, bytecode_path=args.bytecode_path, |
207 for_blink=args.for_blink, | 205 for_blink=args.for_blink, |
208 use_once_callback=args.use_once_callback, | 206 use_once_callback=args.use_once_callback, |
209 use_new_js_bindings=args.use_new_js_bindings, | 207 use_new_js_bindings=args.use_new_js_bindings, |
210 export_attribute=args.export_attribute, | 208 export_attribute=args.export_attribute, |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 "-o", "--output_dir", dest="output_dir", default=".", | 367 "-o", "--output_dir", dest="output_dir", default=".", |
370 help="output directory for precompiled templates") | 368 help="output directory for precompiled templates") |
371 precompile_parser.set_defaults(func=_Precompile) | 369 precompile_parser.set_defaults(func=_Precompile) |
372 | 370 |
373 args, remaining_args = parser.parse_known_args() | 371 args, remaining_args = parser.parse_known_args() |
374 return args.func(args, remaining_args) | 372 return args.func(args, remaining_args) |
375 | 373 |
376 | 374 |
377 if __name__ == "__main__": | 375 if __name__ == "__main__": |
378 sys.exit(main()) | 376 sys.exit(main()) |
OLD | NEW |