OLD | NEW |
---|---|
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 posixpath | 5 import posixpath |
6 | 6 |
7 from api_schema_graph import APISchemaGraph | 7 from api_schema_graph import APISchemaGraph |
8 from branch_utility import BranchUtility, ChannelInfo | 8 from branch_utility import BranchUtility, ChannelInfo |
9 from compiled_file_system import CompiledFileSystem, SingleFile, Unicode | |
9 from extensions_paths import API_PATHS, JSON_TEMPLATES | 10 from extensions_paths import API_PATHS, JSON_TEMPLATES |
10 from features_bundle import FeaturesBundle | 11 from features_bundle import FeaturesBundle |
11 from file_system import FileNotFoundError | 12 from file_system import FileNotFoundError |
13 from schema_util import ProcessSchema | |
12 from third_party.json_schema_compiler.memoize import memoize | 14 from third_party.json_schema_compiler.memoize import memoize |
13 from third_party.json_schema_compiler.model import UnixName | 15 from third_party.json_schema_compiler.model import UnixName |
14 | 16 |
15 | 17 |
16 _DEVTOOLS_API = 'devtools_api.json' | 18 _DEVTOOLS_API = 'devtools_api.json' |
17 _EXTENSION_API = 'extension_api.json' | 19 _EXTENSION_API = 'extension_api.json' |
18 # The version where api_features.json is first available. | 20 # The version where api_features.json is first available. |
19 _API_FEATURES_MIN_VERSION = 28 | 21 _API_FEATURES_MIN_VERSION = 28 |
20 # The version where permission_ and manifest_features.json are available and | 22 # The version where permission_ and manifest_features.json are available and |
21 # presented in the current format. | 23 # presented in the current format. |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 api_info = self._json_fs.GetFromFile( | 137 api_info = self._json_fs.GetFromFile( |
136 JSON_TEMPLATES + 'api_availabilities.json').Get().get(api_name) | 138 JSON_TEMPLATES + 'api_availabilities.json').Get().get(api_name) |
137 if api_info is None: | 139 if api_info is None: |
138 return None | 140 return None |
139 if api_info['channel'] == 'stable': | 141 if api_info['channel'] == 'stable': |
140 return AvailabilityInfo( | 142 return AvailabilityInfo( |
141 self._branch_utility.GetStableChannelInfo(api_info['version'])) | 143 self._branch_utility.GetStableChannelInfo(api_info['version'])) |
142 return AvailabilityInfo( | 144 return AvailabilityInfo( |
143 self._branch_utility.GetChannelInfo(api_info['channel'])) | 145 self._branch_utility.GetChannelInfo(api_info['channel'])) |
144 | 146 |
147 @memoize | |
148 def _CreateAPISchemaFileSystem(self, file_system): | |
149 '''Creates a CompiledFileSystem for parsing raw JSON or IDL API schema | |
150 data and formatting it so that it can be used to create APISchemaGraphs. | |
151 ''' | |
152 # When processing the API schemas, we retain inlined types in the schema | |
153 # so that there are not missing nodes in the APISchemaGraphs when trying | |
154 # to lookup availability. | |
155 def comp_func(path, data): | |
not at google - send to devlin
2014/07/16 20:03:49
s/comp_func/process_schema/
| |
156 return ProcessSchema(path, data, retain_inlined_types=True) | |
157 return self._compiled_fs_factory.Create(file_system, | |
158 SingleFile(Unicode(comp_func)), | |
159 CompiledFileSystem, | |
160 category='api-schema') | |
161 | |
145 def _GetAPISchema(self, api_name, file_system, version): | 162 def _GetAPISchema(self, api_name, file_system, version): |
146 '''Searches |file_system| for |api_name|'s API schema data, and processes | 163 '''Searches |file_system| for |api_name|'s API schema data, and processes |
147 and returns it if found. | 164 and returns it if found. |
148 ''' | 165 ''' |
149 api_filename = _GetAPISchemaFilename(api_name, file_system, version) | 166 api_filename = _GetAPISchemaFilename(api_name, file_system, version) |
150 if api_filename is None: | 167 if api_filename is None: |
151 # No file for the API could be found in the given |file_system|. | 168 # No file for the API could be found in the given |file_system|. |
152 return None | 169 return None |
153 | 170 |
154 schema_fs = self._compiled_fs_factory.ForAPISchema(file_system) | 171 schema_fs = self._CreateAPISchemaFileSystem(file_system) |
155 api_schemas = schema_fs.GetFromFile(api_filename).Get() | 172 api_schemas = schema_fs.GetFromFile(api_filename).Get() |
156 matching_schemas = [api for api in api_schemas | 173 matching_schemas = [api for api in api_schemas |
157 if api['namespace'] == api_name] | 174 if api['namespace'] == api_name] |
158 # There should only be a single matching schema per file, or zero in the | 175 # There should only be a single matching schema per file, or zero in the |
159 # case of no API data being found in _EXTENSION_API. | 176 # case of no API data being found in _EXTENSION_API. |
160 assert len(matching_schemas) <= 1 | 177 assert len(matching_schemas) <= 1 |
161 return matching_schemas or None | 178 return matching_schemas or None |
162 | 179 |
163 def _HasAPISchema(self, api_name, file_system, version): | 180 def _HasAPISchema(self, api_name, file_system, version): |
164 '''Whether or not an API schema for |api_name| exists in the given | 181 '''Whether or not an API schema for |api_name| exists in the given |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 # Continue looping until there are no longer differences between this | 373 # Continue looping until there are no longer differences between this |
357 # version and trunk. | 374 # version and trunk. |
358 return version_stat != trunk_stat | 375 return version_stat != trunk_stat |
359 | 376 |
360 self._file_system_iterator.Ascending( | 377 self._file_system_iterator.Ascending( |
361 self.GetAPIAvailability(api_name).channel_info, | 378 self.GetAPIAvailability(api_name).channel_info, |
362 update_availability_graph) | 379 update_availability_graph) |
363 | 380 |
364 self._node_level_object_store.Set(api_name, availability_graph) | 381 self._node_level_object_store.Set(api_name, availability_graph) |
365 return availability_graph | 382 return availability_graph |
OLD | NEW |