| 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_models import GetNodeCategories | 7 from api_models import GetNodeCategories |
| 8 from api_schema_graph import APISchemaGraph | 8 from api_schema_graph import APISchemaGraph |
| 9 from branch_utility import BranchUtility, ChannelInfo | 9 from branch_utility import BranchUtility, ChannelInfo |
| 10 from compiled_file_system import CompiledFileSystem, SingleFile, Unicode | 10 from compiled_file_system import CompiledFileSystem, SingleFile, Unicode |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 '''Generates availability information for APIs by looking at API schemas and | 110 '''Generates availability information for APIs by looking at API schemas and |
| 111 _features files over multiple release versions of Chrome. | 111 _features files over multiple release versions of Chrome. |
| 112 ''' | 112 ''' |
| 113 | 113 |
| 114 def __init__(self, | 114 def __init__(self, |
| 115 branch_utility, | 115 branch_utility, |
| 116 compiled_fs_factory, | 116 compiled_fs_factory, |
| 117 file_system_iterator, | 117 file_system_iterator, |
| 118 host_file_system, | 118 host_file_system, |
| 119 object_store_creator, | 119 object_store_creator, |
| 120 platform): | 120 platform, |
| 121 process_schema_factory): |
| 121 self._branch_utility = branch_utility | 122 self._branch_utility = branch_utility |
| 122 self._compiled_fs_factory = compiled_fs_factory | 123 self._compiled_fs_factory = compiled_fs_factory |
| 123 self._file_system_iterator = file_system_iterator | 124 self._file_system_iterator = file_system_iterator |
| 124 self._host_file_system = host_file_system | 125 self._host_file_system = host_file_system |
| 125 self._object_store_creator = object_store_creator | 126 self._object_store_creator = object_store_creator |
| 126 def create_object_store(category): | 127 def create_object_store(category): |
| 127 return object_store_creator.Create( | 128 return object_store_creator.Create( |
| 128 AvailabilityFinder, category='/'.join((platform, category))) | 129 AvailabilityFinder, category='/'.join((platform, category))) |
| 129 self._top_level_object_store = create_object_store('top_level') | 130 self._top_level_object_store = create_object_store('top_level') |
| 130 self._node_level_object_store = create_object_store('node_level') | 131 self._node_level_object_store = create_object_store('node_level') |
| 131 self._json_fs = compiled_fs_factory.ForJson(self._host_file_system) | 132 self._json_fs = compiled_fs_factory.ForJson(self._host_file_system) |
| 132 self._platform = platform | 133 self._platform = platform |
| 134 # When processing the API schemas, we retain inlined types in the schema |
| 135 # so that there are not missing nodes in the APISchemaGraphs when trying |
| 136 # to lookup availability. |
| 137 self._process_schema = process_schema_factory.Create(True) |
| 133 | 138 |
| 134 def _GetPredeterminedAvailability(self, api_name): | 139 def _GetPredeterminedAvailability(self, api_name): |
| 135 '''Checks a configuration file for hardcoded (i.e. predetermined) | 140 '''Checks a configuration file for hardcoded (i.e. predetermined) |
| 136 availability information for an API. | 141 availability information for an API. |
| 137 ''' | 142 ''' |
| 138 api_info = self._json_fs.GetFromFile( | 143 api_info = self._json_fs.GetFromFile( |
| 139 JSON_TEMPLATES + 'api_availabilities.json').Get().get(api_name) | 144 JSON_TEMPLATES + 'api_availabilities.json').Get().get(api_name) |
| 140 if api_info is None: | 145 if api_info is None: |
| 141 return None | 146 return None |
| 142 if api_info['channel'] == 'stable': | 147 if api_info['channel'] == 'stable': |
| 143 return AvailabilityInfo( | 148 return AvailabilityInfo( |
| 144 self._branch_utility.GetStableChannelInfo(api_info['version'])) | 149 self._branch_utility.GetStableChannelInfo(api_info['version'])) |
| 145 return AvailabilityInfo( | 150 return AvailabilityInfo( |
| 146 self._branch_utility.GetChannelInfo(api_info['channel'])) | 151 self._branch_utility.GetChannelInfo(api_info['channel'])) |
| 147 | 152 |
| 148 @memoize | 153 @memoize |
| 149 def _CreateAPISchemaFileSystem(self, file_system): | 154 def _CreateAPISchemaFileSystem(self, file_system): |
| 150 '''Creates a CompiledFileSystem for parsing raw JSON or IDL API schema | 155 '''Creates a CompiledFileSystem for parsing raw JSON or IDL API schema |
| 151 data and formatting it so that it can be used to create APISchemaGraphs. | 156 data and formatting it so that it can be used to create APISchemaGraphs. |
| 152 ''' | 157 ''' |
| 153 # When processing the API schemas, we retain inlined types in the schema | |
| 154 # so that there are not missing nodes in the APISchemaGraphs when trying | |
| 155 # to lookup availability. | |
| 156 def process_schema(path, data): | 158 def process_schema(path, data): |
| 157 return ProcessSchema(path, data, retain_inlined_types=True) | 159 return self._process_schema.Process(path, data) |
| 158 return self._compiled_fs_factory.Create(file_system, | 160 return self._compiled_fs_factory.Create(file_system, |
| 159 SingleFile(Unicode(process_schema)), | 161 SingleFile(Unicode(process_schema)), |
| 160 CompiledFileSystem, | 162 CompiledFileSystem, |
| 161 category='api-schema') | 163 category='api-schema') |
| 162 | 164 |
| 163 def _GetAPISchema(self, api_name, file_system, version): | 165 def _GetAPISchema(self, api_name, file_system, version): |
| 164 '''Searches |file_system| for |api_name|'s API schema data, and processes | 166 '''Searches |file_system| for |api_name|'s API schema data, and processes |
| 165 and returns it if found. | 167 and returns it if found. |
| 166 ''' | 168 ''' |
| 167 api_filename = _GetAPISchemaFilename(api_name, file_system, version) | 169 api_filename = _GetAPISchemaFilename(api_name, file_system, version) |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 # Continue looping until there are no longer differences between this | 448 # Continue looping until there are no longer differences between this |
| 447 # version and trunk. | 449 # version and trunk. |
| 448 return version_stat != trunk_stat | 450 return version_stat != trunk_stat |
| 449 | 451 |
| 450 self._file_system_iterator.Ascending( | 452 self._file_system_iterator.Ascending( |
| 451 self.GetAPIAvailability(api_name).channel_info, | 453 self.GetAPIAvailability(api_name).channel_info, |
| 452 update_availability_graph) | 454 update_availability_graph) |
| 453 | 455 |
| 454 self._node_level_object_store.Set(api_name, availability_graph) | 456 self._node_level_object_store.Set(api_name, availability_graph) |
| 455 return availability_graph | 457 return availability_graph |
| OLD | NEW |