summaryrefslogtreecommitdiffstats
path: root/tools/json_schema_compiler/compiler.py
diff options
context:
space:
mode:
authorcalamity@chromium.org <calamity@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-28 05:51:44 +0000
committercalamity@chromium.org <calamity@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-28 05:51:44 +0000
commit25cbf601111a7c4bc0f24ea1e8fc8b0f688ce9d6 (patch)
tree1961d2f1f52421d8714f13ca91e8c615ea0f15cd /tools/json_schema_compiler/compiler.py
parente324f6b9b93237c1488694b2a94cff0f8ec85460 (diff)
downloadchromium_src-25cbf601111a7c4bc0f24ea1e8fc8b0f688ce9d6.zip
chromium_src-25cbf601111a7c4bc0f24ea1e8fc8b0f688ce9d6.tar.gz
chromium_src-25cbf601111a7c4bc0f24ea1e8fc8b0f688ce9d6.tar.bz2
json_schema_compiler: Added wider support for OBJECTs and ENUMs. Used the new 'dependencies' property in the jsons. Refactored to avoid code duplication. Added tests for new features and where tests were lacking.
BUG= TEST=unit_tests --gtest_filter=JsonSchemaCompiler* Review URL: http://codereview.chromium.org/9456007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123909 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/json_schema_compiler/compiler.py')
-rw-r--r--tools/json_schema_compiler/compiler.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/tools/json_schema_compiler/compiler.py b/tools/json_schema_compiler/compiler.py
index 6d3dd63..7965d18 100644
--- a/tools/json_schema_compiler/compiler.py
+++ b/tools/json_schema_compiler/compiler.py
@@ -28,7 +28,7 @@ import sys
if __name__ == '__main__':
parser = optparse.OptionParser(
description='Generates a C++ model of an API from JSON schema',
- usage='usage: %prog [option]... schema [referenced_schema]...')
+ usage='usage: %prog [option]... schema')
parser.add_option('-r', '--root', default='.',
help='logical include root directory. Path to schema files from specified'
'dir will be the include path.')
@@ -44,24 +44,27 @@ if __name__ == '__main__':
root_namespace = opts.namespace
schema = os.path.normpath(args[0])
- referenced_schemas = args[1:]
api_model = model.Model()
- # Load type dependencies into the model.
- for referenced_schema_path in referenced_schemas:
- with open(referenced_schema_path, 'r') as referenced_schema_file:
- referenced_api_defs = json.loads(referenced_schema_file.read())
-
- for namespace in referenced_api_defs:
- api_model.AddNamespace(namespace,
- os.path.relpath(referenced_schema_path, opts.root))
# Actually generate for source file.
with open(schema, 'r') as schema_file:
api_defs = json.loads(schema_file.read())
for target_namespace in api_defs:
+ referenced_schemas = target_namespace.get('dependencies', [])
+ # Load type dependencies into the model.
+ for referenced_schema in referenced_schemas:
+ referenced_schema_path = os.path.join(
+ os.path.dirname(schema), referenced_schema + '.json')
+ with open(referenced_schema_path, 'r') as referenced_schema_file:
+ referenced_api_defs = json.loads(referenced_schema_file.read())
+
+ for namespace in referenced_api_defs:
+ api_model.AddNamespace(namespace,
+ os.path.relpath(referenced_schema_path, opts.root))
+
# Gets the relative path from opts.root to the schema to correctly determine
# the include path.
relpath = os.path.relpath(schema, opts.root)