summaryrefslogtreecommitdiffstats
path: root/tools/json_schema_compiler/compiler.py
diff options
context:
space:
mode:
authorrkc@chromium.org <rkc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-12 18:17:44 +0000
committerrkc@chromium.org <rkc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-12 18:17:44 +0000
commitc9fa3e6cd7b52c74697906f1da3afc287e588ecb (patch)
tree5e5350db5b2e10bfc0a48196c7ecc578cbf12cfe /tools/json_schema_compiler/compiler.py
parent28e282c556c3fa106012c089badb6af7eb42be2c (diff)
downloadchromium_src-c9fa3e6cd7b52c74697906f1da3afc287e588ecb.zip
chromium_src-c9fa3e6cd7b52c74697906f1da3afc287e588ecb.tar.gz
chromium_src-c9fa3e6cd7b52c74697906f1da3afc287e588ecb.tar.bz2
Chromium side changes to add the ledger API.
R=isherman@chromium.org, kalman@chromium.org BUG=346488 Review URL: https://codereview.chromium.org/232183002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269820 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/json_schema_compiler/compiler.py')
-rwxr-xr-xtools/json_schema_compiler/compiler.py25
1 files changed, 18 insertions, 7 deletions
diff --git a/tools/json_schema_compiler/compiler.py b/tools/json_schema_compiler/compiler.py
index 1773d4b..98f44d7 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, '']