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..8a6679394ef31eeee9a315547704bd52758abde9 100755 |
| --- a/tools/json_schema_compiler/compiler.py |
| +++ b/tools/json_schema_compiler/compiler.py |
| @@ -19,6 +19,7 @@ Usage example: |
| import optparse |
| import os |
| import sys |
| +import shlex |
|
not at google - send to devlin
2014/08/25 22:22:47
Alphabetic order.
lfg
2014/08/26 16:15:22
Done.
|
| from cpp_bundle_generator import CppBundleGenerator |
| from cpp_generator import CppGenerator |
| @@ -38,14 +39,17 @@ def GenerateSchema(generator, |
| destdir, |
| cpp_namespace_pattern, |
| dart_overrides_dir, |
| - impl_dir): |
| + impl_dir, |
| + includes): |
| # 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), |
| + includes, |
| + cpp_namespace_pattern) |
| api_def = schema_loader.LoadSchema(os.path.split(schema)[1]) |
| # If compiling the C++ model code, delete 'nocompile' nodes. |
| @@ -68,6 +72,7 @@ def GenerateSchema(generator, |
| relpath = os.path.relpath(os.path.normpath(file_path), root) |
| namespace = api_model.AddNamespace(target_namespace, |
| relpath, |
| + cpp_namespace_pattern, |
| include_compiler_options=True) |
| if default_namespace is None: |
| @@ -100,7 +105,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 +151,8 @@ 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', #dest='include', |
| + help='A list of paths to include when searching for referenced objects') |
|
not at google - send to devlin
2014/08/25 22:22:47
Comment should also mention that convention of : s
lfg
2014/08/26 16:15:22
Done.
|
| (opts, file_paths) = parser.parse_args() |
| @@ -158,8 +165,15 @@ if __name__ == '__main__': |
| raise Exception( |
| "Unless in bundle mode, only one file can be specified at a time.") |
| + includes = [] |
| + if opts.include: |
| + include_split = shlex.split(opts.include) |
| + for i in include_split: |
| + path, namespace = i.split(':', 1) |
|
not at google - send to devlin
2014/08/25 22:22:47
This assumes that there is a ':' in the name. Mayb
lfg
2014/08/26 16:15:22
Done.
|
| + includes.append( { 'path': path, 'namespace': namespace } ) |
|
not at google - send to devlin
2014/08/25 22:22:47
How about:
def split_path_and_namespace(path_and_
lfg
2014/08/26 16:15:21
Done.
|
| + |
| result = GenerateSchema(opts.generator, file_paths, opts.root, opts.destdir, |
| opts.namespace, opts.dart_overrides_dir, |
| - opts.impl_dir) |
| + opts.impl_dir, includes) |
| if not opts.destdir: |
| print result |