Chromium Code Reviews| Index: tools/json_schema_compiler/compiler.py |
| diff --git a/tools/json_schema_compiler/compiler.py b/tools/json_schema_compiler/compiler.py |
| index ff91ccf1c02f8d5d4a528a1674b4dc20d879f805..b70d84cd005b90e8100f2324dbee31b7e6fbf674 100755 |
| --- a/tools/json_schema_compiler/compiler.py |
| +++ b/tools/json_schema_compiler/compiler.py |
| @@ -18,6 +18,7 @@ Usage example: |
| import optparse |
| import os |
| +import shlex |
| import sys |
| from cpp_bundle_generator import CppBundleGenerator |
| @@ -25,6 +26,7 @@ from cpp_generator import CppGenerator |
| from cpp_type_generator import CppTypeGenerator |
| from dart_generator import DartGenerator |
| import json_schema |
| +from cpp_namespace_environment import CppNamespaceEnvironment |
| from model import Model |
| from schema_loader import SchemaLoader |
| @@ -38,14 +40,17 @@ def GenerateSchema(generator, |
| destdir, |
| cpp_namespace_pattern, |
| dart_overrides_dir, |
| - impl_dir): |
| + impl_dir, |
| + include_rules): |
| # Merge the source files into a single list of schemas. |
| api_defs = [] |
| for file_path in file_paths: |
| schema = os.path.normpath(file_path) |
| schema_loader = SchemaLoader( |
| os.path.dirname(os.path.relpath(schema, root)), |
| - os.path.dirname(file_path)) |
| + os.path.dirname(file_path), |
| + include_rules, |
| + cpp_namespace_pattern) |
| api_def = schema_loader.LoadSchema(os.path.split(schema)[1]) |
| # If compiling the C++ model code, delete 'nocompile' nodes. |
| @@ -68,7 +73,9 @@ def GenerateSchema(generator, |
| relpath = os.path.relpath(os.path.normpath(file_path), root) |
| namespace = api_model.AddNamespace(target_namespace, |
| relpath, |
| - include_compiler_options=True) |
| + include_compiler_options=True, |
| + environment=CppNamespaceEnvironment( |
| + cpp_namespace_pattern)) |
| if default_namespace is None: |
| default_namespace = namespace |
| @@ -100,7 +107,7 @@ def GenerateSchema(generator, |
| ('generated_schemas.h', cpp_bundle_generator.schemas_h_generator) |
| ] |
| elif generator == 'cpp': |
| - cpp_generator = CppGenerator(type_generator, cpp_namespace_pattern) |
| + cpp_generator = CppGenerator(type_generator) |
| generators = [ |
| ('%s.h' % filename_base, cpp_generator.h_generator), |
| ('%s.cc' % filename_base, cpp_generator.cc_generator) |
| @@ -146,6 +153,10 @@ if __name__ == '__main__': |
| help='Adds custom dart from files in the given directory (Dart only).') |
| parser.add_option('-i', '--impl-dir', dest='impl_dir', |
| help='The root path of all API implementations') |
| + parser.add_option('-I', '--include-rules', |
| + help='A list of paths to include when searching for referenced objects,' |
| + ' with the namespace separated by a \':\'. Example: ' |
| + '/foo/bar:Foo::Bar::%(namespace)s') |
| (opts, file_paths) = parser.parse_args() |
| @@ -158,8 +169,17 @@ if __name__ == '__main__': |
| raise Exception( |
| "Unless in bundle mode, only one file can be specified at a time.") |
| + def split_path_and_namespace(path_and_namespace): |
| + if ':' not in path_and_namespace: |
| + raise ValueError('Invalid include rule "%s". Rules must be of ' |
| + 'the form path:namespace' % path_and_namespace) |
| + path, namespace = path_and_namespace.split(':', 1) |
| + return (path, namespace) |
|
not at google - send to devlin
2014/08/27 23:14:20
You can just return path_and_namespace.split(':',
lfg
2014/08/28 18:57:10
Done.
|
| + |
| + include_rules = map(split_path_and_namespace, shlex.split(opts.include_rules)) |
| + |
| result = GenerateSchema(opts.generator, file_paths, opts.root, opts.destdir, |
| opts.namespace, opts.dart_overrides_dir, |
| - opts.impl_dir) |
| + opts.impl_dir, include_rules) |
| if not opts.destdir: |
| print result |