| Index: tools/json_schema_compiler/compiler.py
|
| diff --git a/tools/json_schema_compiler/compiler.py b/tools/json_schema_compiler/compiler.py
|
| index 1773d4b136123b24db6a58f1330554adb9636ffc..98f44d743e43d72eeaa9692c4a999e139c864da4 100755
|
| --- a/tools/json_schema_compiler/compiler.py
|
| +++ b/tools/json_schema_compiler/compiler.py
|
| @@ -40,13 +40,13 @@ def GenerateSchema(generator,
|
| root_namespace,
|
| dart_overrides_dir,
|
| impl_dir):
|
| - schema_loader = SchemaLoader(
|
| - os.path.dirname(os.path.relpath(os.path.normpath(filenames[0]), root)),
|
| - os.path.dirname(filenames[0]))
|
| # Merge the source files into a single list of schemas.
|
| api_defs = []
|
| for filename in filenames:
|
| schema = os.path.normpath(filename)
|
| + schema_loader = SchemaLoader(
|
| + os.path.dirname(os.path.relpath(os.path.normpath(filename), root)),
|
| + os.path.dirname(filename))
|
| api_def = schema_loader.LoadSchema(os.path.split(schema)[1])
|
|
|
| # If compiling the C++ model code, delete 'nocompile' nodes.
|
| @@ -60,15 +60,25 @@ def GenerateSchema(generator,
|
| # is the default one.
|
| default_namespace = None
|
|
|
| + # If we have files from multiple source paths, we'll use the common parent
|
| + # path as the source directory.
|
| + src_path = None
|
| +
|
| # Load the actual namespaces into the model.
|
| for target_namespace, schema_filename in zip(api_defs, filenames):
|
| relpath = os.path.relpath(os.path.normpath(schema_filename), root)
|
| namespace = api_model.AddNamespace(target_namespace,
|
| relpath,
|
| include_compiler_options=True)
|
| +
|
| if default_namespace is None:
|
| default_namespace = namespace
|
|
|
| + if src_path is None:
|
| + src_path = namespace.source_file_dir
|
| + else:
|
| + src_path = os.path.commonprefix((src_path, namespace.source_file_dir))
|
| +
|
| path, filename = os.path.split(schema_filename)
|
| short_filename, extension = os.path.splitext(filename)
|
|
|
| @@ -76,14 +86,13 @@ def GenerateSchema(generator,
|
| type_generator = CppTypeGenerator(api_model,
|
| schema_loader,
|
| default_namespace=default_namespace)
|
| -
|
| if generator == 'cpp-bundle':
|
| cpp_bundle_generator = CppBundleGenerator(root,
|
| api_model,
|
| api_defs,
|
| type_generator,
|
| root_namespace,
|
| - namespace.source_file_dir,
|
| + src_path,
|
| impl_dir)
|
| generators = [
|
| ('generated_api.cc', cpp_bundle_generator.api_cc_generator),
|
| @@ -115,8 +124,10 @@ def GenerateSchema(generator,
|
| for filename, generator in generators:
|
| code = generator.Generate(namespace).Render()
|
| if destdir:
|
| - with open(os.path.join(destdir, namespace.source_file_dir,
|
| - filename), 'w') as f:
|
| + output_dir = os.path.join(destdir, src_path)
|
| + if not os.path.exists(output_dir):
|
| + os.makedirs(output_dir)
|
| + with open(os.path.join(output_dir, filename), 'w') as f:
|
| f.write(code)
|
| output_code += [filename, '', code, '']
|
|
|
|
|