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

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
« no previous file with comments | « tools/json_schema_compiler/cc_generator.py ('k') | tools/json_schema_compiler/cpp_generator.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_schema_compiler/compiler.py
diff --git a/tools/json_schema_compiler/compiler.py b/tools/json_schema_compiler/compiler.py
index 38899286d215158c7701ff7cda84285f927e0f01..7a2e4dd6f1593ed3a4ae95b03631d3a483ffd5c0 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,15 +40,18 @@ def GenerateSchema(generator_name,
destdir,
cpp_namespace_pattern,
dart_overrides_dir,
- impl_dir):
+ impl_dir,
+ include_rules):
# 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 = os.path.relpath(file_path, root)
schema_loader = SchemaLoader(
- os.path.dirname(os.path.relpath(schema, root)),
- os.path.dirname(file_path))
- api_def = schema_loader.LoadSchema(os.path.split(schema)[1])
+ root,
+ os.path.dirname(schema),
+ include_rules,
+ cpp_namespace_pattern)
+ api_def = schema_loader.LoadSchema(schema)
# If compiling the C++ model code, delete 'nocompile' nodes.
if generator_name == 'cpp':
@@ -68,7 +73,9 @@ def GenerateSchema(generator_name,
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
@@ -105,7 +112,7 @@ def GenerateSchema(generator_name,
('generated_schemas.h', cpp_bundle_generator.schemas_h_generator)
]
elif generator_name == '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)
@@ -156,6 +163,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',
+ 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()
@@ -169,8 +180,19 @@ 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)
+
+ include_rules = []
+ if opts.include_rules:
+ include_rules = map(split_path_and_namespace,
+ shlex.split(opts.include_rules))
+
result = GenerateSchema(opts.generator, file_paths, opts.root, opts.destdir,
opts.namespace, opts.dart_overrides_dir,
- opts.impl_dir)
+ opts.impl_dir, include_rules)
if not opts.destdir:
print result
« no previous file with comments | « tools/json_schema_compiler/cc_generator.py ('k') | tools/json_schema_compiler/cpp_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698