summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormsimonides@opera.com <msimonides@opera.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-30 15:29:34 +0000
committermsimonides@opera.com <msimonides@opera.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-30 15:29:34 +0000
commit43294450f9b201a266c0e0413c92f8e16f1982ee (patch)
treeb3c3c049526dcc459e2c4fe38d66194fc3fcf8f6
parent4407c69561bfd8b7d5872b6e026716466d64bd38 (diff)
downloadchromium_src-43294450f9b201a266c0e0413c92f8e16f1982ee.zip
chromium_src-43294450f9b201a266c0e0413c92f8e16f1982ee.tar.gz
chromium_src-43294450f9b201a266c0e0413c92f8e16f1982ee.tar.bz2
Make SchemaLoader independent of current working directory.
The SchemaLoader looks for schema files in the current directory. This isn't very robust and may cause problems for other products than Chromium if they run the script from a GYP file in another directory. The SchemaLoader is supplied two arguments now: the path to API files relative to the root path (for use in #includes) and the regular path to API files (for file access). BUG= Review URL: https://codereview.chromium.org/23534063 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@225977 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-xtools/json_schema_compiler/compiler.py9
-rw-r--r--tools/json_schema_compiler/schema_loader.py27
2 files changed, 24 insertions, 12 deletions
diff --git a/tools/json_schema_compiler/compiler.py b/tools/json_schema_compiler/compiler.py
index ddab77e..edd183d 100755
--- a/tools/json_schema_compiler/compiler.py
+++ b/tools/json_schema_compiler/compiler.py
@@ -38,15 +38,14 @@ def GenerateSchema(generator,
destdir,
root_namespace,
dart_overrides_dir):
- schema_loader = SchemaLoader(os.path.dirname(os.path.relpath(
- os.path.normpath(filenames[0]), root)))
+ schema_loader = SchemaLoader(
+ os.path.dirname(os.path.relpath(os.path.normpath(filenames[0]), root)),
+ os.path.dirname(filenames[0]))
# Merge the source files into a single list of schemas.
api_defs = []
for filename in filenames:
schema = os.path.normpath(filename)
- schema_filename, schema_extension = os.path.splitext(schema)
- path, short_filename = os.path.split(schema_filename)
- api_def = schema_loader.LoadSchema(schema)
+ api_def = schema_loader.LoadSchema(os.path.split(schema)[1])
# If compiling the C++ model code, delete 'nocompile' nodes.
if generator == 'cpp':
diff --git a/tools/json_schema_compiler/schema_loader.py b/tools/json_schema_compiler/schema_loader.py
index c434dc1..80f1d3f 100644
--- a/tools/json_schema_compiler/schema_loader.py
+++ b/tools/json_schema_compiler/schema_loader.py
@@ -11,9 +11,16 @@ from model import Model
class SchemaLoader(object):
'''Resolves a type name into the namespace the type belongs to.
+
+ Properties:
+ - |display_path| path to the directory with the API header files, intended for
+ use with the Model.
+ - |real_path| path to the directory with the API header files, used for file
+ access.
'''
- def __init__(self, api_path):
- self._api_path = api_path
+ def __init__(self, display_path, real_path):
+ self._display_path = display_path
+ self._real_path = real_path
def ResolveType(self, full_name, default_namespace):
name_parts = full_name.rsplit('.', 1)
@@ -25,24 +32,30 @@ class SchemaLoader(object):
real_name = None
for ext in ['json', 'idl']:
filename = '%s.%s' % (namespace_name, ext)
- if os.path.exists(filename):
+ filepath = os.path.join(self._real_path, filename);
+ if os.path.exists(filepath):
real_name = filename
break
if real_name is None:
return None
- namespace = Model().AddNamespace(self.LoadSchema(real_name)[0],
- os.path.join(self._api_path, real_name))
+ namespace = Model().AddNamespace(
+ self.LoadSchema(real_name)[0],
+ os.path.join(self._display_path, real_name))
if type_name not in namespace.types:
return None
return namespace
def LoadSchema(self, schema):
+ '''Load a schema definition. The schema parameter must be a file name
+ without any path component - the file is loaded from the path defined by
+ the real_path argument passed to the constructor.'''
schema_filename, schema_extension = os.path.splitext(schema)
+ schema_path = os.path.join(self._real_path, schema);
if schema_extension == '.json':
- api_defs = json_schema.Load(schema)
+ api_defs = json_schema.Load(schema_path)
elif schema_extension == '.idl':
- api_defs = idl_schema.Load(schema)
+ api_defs = idl_schema.Load(schema_path)
else:
sys.exit('Did not recognize file extension %s for schema %s' %
(schema_extension, schema))