Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 re | 6 import re |
| 7 import sys | 7 import sys |
| 8 | 8 |
| 9 import idl_schema | 9 import idl_schema |
| 10 import json_schema | 10 import json_schema |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 path, | 47 path, |
| 48 include_rules, | 48 include_rules, |
| 49 cpp_namespace_pattern): | 49 cpp_namespace_pattern): |
| 50 self._root = root | 50 self._root = root |
| 51 self._include_rules = [(path, cpp_namespace_pattern)] | 51 self._include_rules = [(path, cpp_namespace_pattern)] |
| 52 self._include_rules.extend(include_rules) | 52 self._include_rules.extend(include_rules) |
| 53 | 53 |
| 54 def ResolveNamespace(self, full_namespace): | 54 def ResolveNamespace(self, full_namespace): |
| 55 filenames = GenerateFilenames(full_namespace) | 55 filenames = GenerateFilenames(full_namespace) |
| 56 for path, cpp_namespace in self._include_rules: | 56 for path, cpp_namespace in self._include_rules: |
| 57 cpp_namespace_environment = None | |
| 58 if cpp_namespace: | |
| 59 cpp_namespace_environment = CppNamespaceEnvironment(cpp_namespace) | |
| 57 for filename in reversed(filenames): | 60 for filename in reversed(filenames): |
| 58 filepath = os.path.join(path, filename); | 61 filepath = os.path.join(path, filename); |
| 59 if os.path.exists(os.path.join(self._root, filepath)): | 62 if os.path.exists(os.path.join(self._root, filepath)): |
| 60 return Model().AddNamespace( | 63 return Model().AddNamespace( |
| 61 self.LoadSchema(filepath)[0], | 64 self.LoadSchema(filepath)[0], |
| 62 filepath, | 65 filepath, |
| 63 environment=CppNamespaceEnvironment(cpp_namespace)) | 66 environment=cpp_namespace_environment) |
| 64 return None | 67 return None |
| 65 | 68 |
| 66 def ResolveType(self, full_name, default_namespace): | 69 def ResolveType(self, full_name, default_namespace): |
| 67 name_parts = full_name.rsplit('.', 1) | 70 name_parts = full_name.rsplit('.', 1) |
| 68 if len(name_parts) == 1: | 71 if len(name_parts) == 1: |
| 69 if full_name not in default_namespace.types: | 72 if full_name not in default_namespace.types: |
| 70 return None | 73 return None |
| 71 return default_namespace | 74 return default_namespace |
| 72 full_namespace, type_name = full_name.rsplit('.', 1) | 75 full_namespace, type_name = full_name.rsplit('.', 1) |
| 73 namespace = self.ResolveNamespace(full_namespace) | 76 namespace = self.ResolveNamespace(full_namespace) |
| 74 if namespace and type_name in namespace.types: | 77 if namespace and type_name in namespace.types: |
| 75 return namespace | 78 return namespace |
| 76 return None | 79 return None |
| 77 | 80 |
| 78 def LoadSchema(self, schema): | 81 def LoadSchema(self, schema): |
| 79 '''Load a schema definition. The schema parameter must be a file name | 82 '''Load a schema definition. The schema parameter must be a file name |
| 80 with the full path relative to the root.''' | 83 with the full path relative to the root.''' |
| 81 schema_filename, schema_extension = os.path.splitext(schema) | 84 schema_extension = os.path.splitext(schema)[1] |
|
not at google - send to devlin
2015/01/14 22:44:41
ditto
| |
| 82 | 85 |
| 83 schema_path = os.path.join(self._root, schema) | 86 schema_path = os.path.join(self._root, schema) |
| 84 if schema_extension == '.json': | 87 if schema_extension == '.json': |
| 85 api_defs = json_schema.Load(schema_path) | 88 api_defs = json_schema.Load(schema_path) |
| 86 elif schema_extension == '.idl': | 89 elif schema_extension == '.idl': |
| 87 api_defs = idl_schema.Load(schema_path) | 90 api_defs = idl_schema.Load(schema_path) |
| 88 else: | 91 else: |
| 89 sys.exit('Did not recognize file extension %s for schema %s' % | 92 sys.exit('Did not recognize file extension %s for schema %s' % |
| 90 (schema_extension, schema)) | 93 (schema_extension, schema)) |
| 91 | 94 |
| 92 return api_defs | 95 return api_defs |
| OLD | NEW |