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

Unified Diff: tools/json_schema_compiler/compiler.py

Issue 12522004: Lazily load extension API schemas (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: take out dependencies Created 7 years, 9 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 cac08eea2cca83b1d364716245b1feb084c749d6..f51bcc0f1735081af43818642072c3f496b36dcf 100755
--- a/tools/json_schema_compiler/compiler.py
+++ b/tools/json_schema_compiler/compiler.py
@@ -48,6 +48,33 @@ def _LoadSchema(schema):
return api_defs
+class TypeNamespaceResolver(object):
not at google - send to devlin 2013/03/22 22:10:12 pull into separate file?
cduvall 2013/03/22 22:52:29 Done.
+ '''Resolves a type name into the namespace the type belongs to.
+ '''
+ def __init__(self, api_path):
+ self._api_path = api_path
+
+ def Resolve(self, full_name, default_namespace):
+ name_parts = full_name.rsplit('.', 1)
+ if len(name_parts) == 1:
+ if full_name not in default_namespace.types:
+ return None
not at google - send to devlin 2013/03/22 22:10:12 can this be an assertion?
cduvall 2013/03/22 22:52:29 Still returning None, to be handled in CppTypeGene
+ return default_namespace
+ namespace_name, type_name = name_parts
+ json_name = '%s.json' % namespace_name
+ idl_name = '%s.idl' % namespace_name
+ if os.path.exists(json_name):
+ real_name = json_name
+ elif os.path.exists(idl_name):
+ real_name = idl_name
+ else:
+ return None
not at google - send to devlin 2013/03/22 22:10:12 I think a structure like real_name = None for ext
cduvall 2013/03/22 22:52:29 Done.
+ namespace = Model().AddNamespace(_LoadSchema(real_name)[0],
+ os.path.join(self._api_path, real_name))
+ if type_name not in namespace.types:
+ return None
not at google - send to devlin 2013/03/22 22:10:12 can this be an assertion?
cduvall 2013/03/22 22:52:29 Same as above.
+ return namespace
+
def GenerateSchema(generator,
filenames,
root,
@@ -68,33 +95,8 @@ def GenerateSchema(generator,
api_defs.extend(api_def)
api_model = Model()
-
- # Load type dependencies into the model.
- #
- # HACK(kalman): bundle mode doesn't work with dependencies, because not all
- # schemas work in bundle mode.
- #
- # TODO(kalman): load dependencies lazily (get rid of the 'dependencies' list)
- # and this problem will go away.
- if generator != 'cpp-bundle':
- for target_namespace in api_defs:
- for referenced_schema in target_namespace.get('dependencies', []):
- split_schema = referenced_schema.split(':', 1)
- if len(split_schema) > 1:
- if split_schema[0] != 'api':
- continue
- else:
- referenced_schema = split_schema[1]
-
- referenced_schema_path = os.path.join(
- os.path.dirname(schema), '%s.json' % UnixName(referenced_schema))
- referenced_api_defs = json_schema.Load(referenced_schema_path)
-
- for namespace in referenced_api_defs:
- api_model.AddNamespace(
- namespace,
- os.path.relpath(referenced_schema_path, root),
- include_compiler_options=True)
+ type_namespace_resolver = TypeNamespaceResolver(
+ os.path.dirname(os.path.relpath(schema, root)))
# For single-schema compilation make sure that the first (i.e. only) schema
# is the default one.
@@ -125,6 +127,7 @@ def GenerateSchema(generator,
# Construct the type generator with all the namespaces in this model.
type_generator = CppTypeGenerator(api_model,
+ type_namespace_resolver,
default_namespace=default_namespace)
if generator == 'cpp-bundle':

Powered by Google App Engine
This is Rietveld 408576698