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

Side by Side Diff: tools/json_schema_compiler/schema_loader.py

Issue 197873009: Support scoped types in PPAPI IDL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed compiling. Created 6 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import os 5 import os
6 import sys 6 import sys
7 7
8 import idl_schema 8 import idl_schema
9 import json_schema 9 import json_schema
10 from model import Model 10 from model import Model
(...skipping 13 matching lines...) Expand all
24 24
25 def ResolveType(self, full_name, default_namespace): 25 def ResolveType(self, full_name, default_namespace):
26 name_parts = full_name.rsplit('.', 1) 26 name_parts = full_name.rsplit('.', 1)
27 if len(name_parts) == 1: 27 if len(name_parts) == 1:
28 if full_name not in default_namespace.types: 28 if full_name not in default_namespace.types:
29 return None 29 return None
30 return default_namespace 30 return default_namespace
31 namespace_name, type_name = name_parts 31 namespace_name, type_name = name_parts
32 real_name = None 32 real_name = None
33 for ext in ['json', 'idl']: 33 for ext in ['json', 'idl']:
34 filename = '%s.%s' % (namespace_name, ext) 34 filename = '%s.%s' % (namespace_name.replace('.', '_'), ext)
35 filepath = os.path.join(self._real_path, filename); 35 filepath = os.path.join(self._real_path, filename);
36 if os.path.exists(filepath): 36 if os.path.exists(filepath):
37 real_name = filename 37 real_name = filename
38 break 38 break
39 if real_name is None: 39 if real_name is None:
40 return None 40 return None
41 namespace = Model().AddNamespace( 41 namespace = Model().AddNamespace(
42 self.LoadSchema(real_name)[0], 42 self.LoadSchema(real_name)[0],
43 os.path.join(self._display_path, real_name)) 43 os.path.join(self._display_path, real_name))
44 if type_name not in namespace.types: 44 if type_name not in namespace.types:
45 return None 45 return None
46 return namespace 46 return namespace
47 47
48 def LoadSchema(self, schema): 48 def LoadSchema(self, schema):
49 '''Load a schema definition. The schema parameter must be a file name 49 '''Load a schema definition. The schema parameter must be a file name
50 without any path component - the file is loaded from the path defined by 50 without any path component - the file is loaded from the path defined by
51 the real_path argument passed to the constructor.''' 51 the real_path argument passed to the constructor.'''
52 schema_filename, schema_extension = os.path.splitext(schema) 52 schema_filename, schema_extension = os.path.splitext(schema)
53 53
54 schema_path = os.path.join(self._real_path, schema); 54 schema_path = os.path.join(self._real_path, schema);
55 if schema_extension == '.json': 55 if schema_extension == '.json':
56 api_defs = json_schema.Load(schema_path) 56 api_defs = json_schema.Load(schema_path)
57 elif schema_extension == '.idl': 57 elif schema_extension == '.idl':
58 api_defs = idl_schema.Load(schema_path) 58 api_defs = idl_schema.Load(schema_path)
59 else: 59 else:
60 sys.exit('Did not recognize file extension %s for schema %s' % 60 sys.exit('Did not recognize file extension %s for schema %s' %
61 (schema_extension, schema)) 61 (schema_extension, schema))
62 62
63 return api_defs 63 return api_defs
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698