Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Unified Diff: tools/json_schema_compiler/compiler.py

Issue 487533005: Add support for references in different paths in apis (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..448109eb8b18e33e76eab65efed8bd9633b853f9 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,
+ 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,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', #dest='include',
not at google - send to devlin 2014/08/26 20:16:06 Remove #dest comment
lfg 2014/08/26 21:18:43 Done.
+ 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,18 @@ 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)
+ return path_and_namespace.split(':', 1)
+
+ includes = [{'path': path, 'namespace': namespace}
+ for rule in shlex.split(opts.include_rules)
+ for path, namespace in [ split_path_and_namespace(rule) ]]
not at google - send to devlin 2014/08/26 20:16:06 Ah ok. So writing this singleton list thing is a b
lfg 2014/08/26 21:18:43 Done.
+
result = GenerateSchema(opts.generator, file_paths, opts.root, opts.destdir,
opts.namespace, opts.dart_overrides_dir,
- opts.impl_dir)
+ opts.impl_dir, includes)
not at google - send to devlin 2014/08/26 20:16:06 (call this include_rules)
lfg 2014/08/26 21:18:43 Done.
if not opts.destdir:
print result

Powered by Google App Engine
This is Rietveld 408576698