summaryrefslogtreecommitdiffstats
path: root/tools/json_schema_compiler
diff options
context:
space:
mode:
authorkalman <kalman@chromium.org>2015-07-23 11:27:22 -0700
committerCommit bot <commit-bot@chromium.org>2015-07-23 18:28:16 +0000
commite58e6223146f09405229146fce6c1bfe6b71e4ce (patch)
tree8f32850890b2057b11cfdf2bc02cdba3a12c3e1d /tools/json_schema_compiler
parentf340ae7cfdf33370ea3aed173ab2e86fe8415936 (diff)
downloadchromium_src-e58e6223146f09405229146fce6c1bfe6b71e4ce.zip
chromium_src-e58e6223146f09405229146fce6c1bfe6b71e4ce.tar.gz
chromium_src-e58e6223146f09405229146fce6c1bfe6b71e4ce.tar.bz2
Generate all extension schema namespaces as "api" and instead vary the generated bundle names.
At the moment the 3 modules that use extension API schemas, those in extensions/common/api, chrome/common/extensions/api, and extensions/shell/api, are generated with different C++ namespaces: "core_api", "api", and "shell::api" respectively. This is a pointless distinction to make since as far as JS is concerned they must all go on the window.chrome object, therefore namespace conflicts are impossible. It just ends up adding code noise. The only problem it solves is that all bundle compiles are generated to the same name, "GeneratedSchemas" and "GeneratedFunctionRegistry". This patch solves that a different way, by adding a JSON schema compiler option to give those generated classes a prefix such that they are "GeneratedSchemas", "ChromeGeneratedSchemas", and "ShellGeneratedSchemas" respectively. This lets us to a global substitution from "core_api" to just "api". R=rockot@chromium.org, dpranke@chromium.org TBR=ben@chromium.org Review URL: https://codereview.chromium.org/1226353004 Cr-Commit-Position: refs/heads/master@{#340119}
Diffstat (limited to 'tools/json_schema_compiler')
-rwxr-xr-xtools/json_schema_compiler/compiler.py9
-rw-r--r--tools/json_schema_compiler/cpp_bundle_generator.py31
2 files changed, 30 insertions, 10 deletions
diff --git a/tools/json_schema_compiler/compiler.py b/tools/json_schema_compiler/compiler.py
index f3c4009..1ed407b 100755
--- a/tools/json_schema_compiler/compiler.py
+++ b/tools/json_schema_compiler/compiler.py
@@ -39,6 +39,7 @@ def GenerateSchema(generator_name,
root,
destdir,
cpp_namespace_pattern,
+ bundle_name,
impl_dir,
include_rules):
# Merge the source files into a single list of schemas.
@@ -97,6 +98,7 @@ def GenerateSchema(generator_name,
api_defs,
type_generator,
cpp_namespace_pattern,
+ bundle_name,
src_path,
impl_dir)
if generator_name == 'cpp-bundle-registration':
@@ -153,6 +155,10 @@ if __name__ == '__main__':
help='root directory to output generated files.')
parser.add_option('-n', '--namespace', default='generated_api_schemas',
help='C++ namespace for generated files. e.g extensions::api.')
+ parser.add_option('-b', '--bundle-name', default='',
+ help='A string to prepend to generated bundle class names, so that '
+ 'multiple bundle rules can be used without conflicting. '
+ 'Only used with one of the cpp-bundle generators.')
parser.add_option('-g', '--generator', default=GENERATORS[0],
choices=GENERATORS,
help='The generator to use to build the output code. Supported values are'
@@ -188,6 +194,7 @@ if __name__ == '__main__':
shlex.split(opts.include_rules))
result = GenerateSchema(opts.generator, file_paths, opts.root, opts.destdir,
- opts.namespace, opts.impl_dir, include_rules)
+ opts.namespace, opts.bundle_name, opts.impl_dir,
+ include_rules)
if not opts.destdir:
print result
diff --git a/tools/json_schema_compiler/cpp_bundle_generator.py b/tools/json_schema_compiler/cpp_bundle_generator.py
index 708d30f..a039368 100644
--- a/tools/json_schema_compiler/cpp_bundle_generator.py
+++ b/tools/json_schema_compiler/cpp_bundle_generator.py
@@ -40,12 +40,14 @@ class CppBundleGenerator(object):
api_defs,
cpp_type_generator,
cpp_namespace_pattern,
+ bundle_name,
source_file_dir,
impl_dir):
self._root = root
self._model = model
self._api_defs = api_defs
self._cpp_type_generator = cpp_type_generator
+ self._bundle_name = bundle_name
self._source_file_dir = source_file_dir
self._impl_dir = impl_dir
@@ -118,8 +120,8 @@ class CppBundleGenerator(object):
def _GenerateFunctionRegistryRegisterAll(self):
c = code.Code()
c.Append('// static')
- c.Sblock('void GeneratedFunctionRegistry::RegisterAll('
- 'ExtensionFunctionRegistry* registry) {')
+ c.Sblock('void %s::RegisterAll(ExtensionFunctionRegistry* registry) {' %
+ self._GenerateBundleClass('GeneratedFunctionRegistry'))
for namespace in self._model.namespaces.values():
namespace_ifdefs = self._GetPlatformIfdefs(namespace)
if namespace_ifdefs is not None:
@@ -144,6 +146,12 @@ class CppBundleGenerator(object):
c.Eblock("}")
return c
+ def _GenerateBundleClass(self, class_name):
+ '''Generates the C++ class name to use for a bundle class, taking into
+ account the bundle's name.
+ '''
+ return self._bundle_name + class_name
+
class _APIHGenerator(object):
"""Generates the header for API registration / declaration"""
@@ -161,7 +169,8 @@ class _APIHGenerator(object):
c.Append()
c.Concat(cpp_util.OpenNamespace(self._bundle._cpp_namespace))
c.Append()
- c.Append('class GeneratedFunctionRegistry {')
+ c.Append('class %s {' %
+ self._bundle._GenerateBundleClass('GeneratedFunctionRegistry'))
c.Sblock(' public:')
c.Append('static void RegisterAll('
'ExtensionFunctionRegistry* registry);')
@@ -235,7 +244,8 @@ class _SchemasHGenerator(object):
c.Append()
c.Concat(cpp_util.OpenNamespace(self._bundle._cpp_namespace))
c.Append()
- c.Append('class GeneratedSchemas {')
+ c.Append('class %s {' %
+ self._bundle._GenerateBundleClass('GeneratedSchemas'))
c.Sblock(' public:')
c.Append('// Determines if schema named |name| is generated.')
c.Append('static bool IsGenerated(std::string name);')
@@ -287,8 +297,6 @@ class _SchemasCCGenerator(object):
for i in xrange(0, len(json_content), max_length)]
c.Append('const char %s[] = "%s";' %
(_FormatNameAsConstant(namespace.name), '" "'.join(segments)))
- c.Append('}')
- c.Concat(cpp_util.OpenNamespace(self._bundle._cpp_namespace))
c.Append()
c.Sblock('struct Static {')
c.Sblock('Static() {')
@@ -303,15 +311,20 @@ class _SchemasCCGenerator(object):
c.Append()
c.Append('base::LazyInstance<Static> g_lazy_instance;')
c.Append()
+ c.Append('} // namespace')
+ c.Append()
+ c.Concat(cpp_util.OpenNamespace(self._bundle._cpp_namespace))
+ c.Append()
c.Append('// static')
- c.Sblock('base::StringPiece GeneratedSchemas::Get('
- 'const std::string& name) {')
+ c.Sblock('base::StringPiece %s::Get(const std::string& name) {' %
+ self._bundle._GenerateBundleClass('GeneratedSchemas'))
c.Append('return IsGenerated(name) ? '
'g_lazy_instance.Get().schemas[name] : "";')
c.Eblock('}')
c.Append()
c.Append('// static')
- c.Sblock('bool GeneratedSchemas::IsGenerated(std::string name) {')
+ c.Sblock('bool %s::IsGenerated(std::string name) {' %
+ self._bundle._GenerateBundleClass('GeneratedSchemas'))
c.Append('return g_lazy_instance.Get().schemas.count(name) > 0;')
c.Eblock('}')
c.Append()