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 from collections import Mapping | 5 from collections import Mapping |
6 import posixpath | 6 import posixpath |
7 | 7 |
8 from api_schema_graph import APISchemaGraph | 8 from api_schema_graph import APISchemaGraph |
9 from branch_utility import BranchUtility | 9 from branch_utility import BranchUtility |
10 from extensions_paths import API, JSON_TEMPLATES | 10 from extensions_paths import ( |
| 11 API, CHROME_API, JSON_TEMPLATES, API_FEATURES, MANIFEST_FEATURES, |
| 12 PERMISSION_FEATURES) |
11 from third_party.json_schema_compiler.model import UnixName | 13 from third_party.json_schema_compiler.model import UnixName |
12 | 14 |
13 | 15 |
14 _EXTENSION_API = 'extension_api.json' | 16 _EXTENSION_API = 'extension_api.json' |
15 | 17 |
16 # The version where api_features.json is first available. | 18 # The version where api_features.json is first available. |
17 _API_FEATURES_MIN_VERSION = 28 | 19 _API_FEATURES_MIN_VERSION = 28 |
18 # The version where permission_ and manifest_features.json are available and | 20 # The version where permission_ and manifest_features.json are available and |
19 # presented in the current format. | 21 # presented in the current format. |
20 _ORIGINAL_FEATURES_MIN_VERSION = 20 | 22 _ORIGINAL_FEATURES_MIN_VERSION = 20 |
21 # API schemas are aggregated in extension_api.json up to this version. | 23 # API schemas are aggregated in extension_api.json up to this version. |
22 _EXTENSION_API_MAX_VERSION = 17 | 24 _EXTENSION_API_MAX_VERSION = 17 |
23 # The earliest version for which we have SVN data. | 25 # The earliest version for which we have SVN data. |
24 _SVN_MIN_VERSION = 5 | 26 _SVN_MIN_VERSION = 5 |
25 | 27 |
26 | 28 |
27 def _GetChannelFromFeatures(api_name, json_fs, filename): | 29 def _GetChannelFromFeatures(api_name, json_fs, filename): |
28 '''Finds API channel information from the features |filename| within the the | 30 '''Finds API channel information from the features |filename| within the the |
29 given |json_fs|. Returns None if channel information for the API cannot be | 31 given |json_fs|. Returns None if channel information for the API cannot be |
30 located. | 32 located. |
31 ''' | 33 ''' |
32 feature = json_fs.GetFromFile(API + filename).Get().get(api_name) | 34 feature = json_fs.GetFromFile(filename).Get().get(api_name) |
33 if feature is None: | 35 if feature is None: |
34 return None | 36 return None |
35 if isinstance(feature, Mapping): | 37 if isinstance(feature, Mapping): |
36 # The channel information exists as a solitary dict. | 38 # The channel information exists as a solitary dict. |
37 return feature.get('channel') | 39 return feature.get('channel') |
38 # The channel information dict is nested within a list for whitelisting | 40 # The channel information dict is nested within a list for whitelisting |
39 # purposes. Take the newest channel out of all of the entries. | 41 # purposes. Take the newest channel out of all of the entries. |
40 return BranchUtility.NewestChannel(entry.get('channel') for entry in feature) | 42 return BranchUtility.NewestChannel(entry.get('channel') for entry in feature) |
41 | 43 |
42 | 44 |
43 def _GetChannelFromApiFeatures(api_name, json_fs): | 45 def _GetChannelFromApiFeatures(api_name, json_fs): |
44 return _GetChannelFromFeatures(api_name, json_fs, '_api_features.json') | 46 return _GetChannelFromFeatures(api_name, json_fs, API_FEATURES) |
45 | 47 |
46 | 48 |
47 def _GetChannelFromManifestFeatures(api_name, json_fs): | 49 def _GetChannelFromManifestFeatures(api_name, json_fs): |
48 # _manifest_features.json uses unix_style API names. | 50 # _manifest_features.json uses unix_style API names. |
49 api_name = UnixName(api_name) | 51 api_name = UnixName(api_name) |
50 return _GetChannelFromFeatures(api_name, json_fs, '_manifest_features.json') | 52 return _GetChannelFromFeatures(api_name, json_fs, MANIFEST_FEATURES) |
51 | 53 |
52 | 54 |
53 def _GetChannelFromPermissionFeatures(api_name, json_fs): | 55 def _GetChannelFromPermissionFeatures(api_name, json_fs): |
54 return _GetChannelFromFeatures(api_name, json_fs, '_permission_features.json') | 56 return _GetChannelFromFeatures(api_name, json_fs, PERMISSION_FEATURES) |
55 | 57 |
56 | 58 |
57 class AvailabilityFinder(object): | 59 class AvailabilityFinder(object): |
58 '''Generates availability information for APIs by looking at API schemas and | 60 '''Generates availability information for APIs by looking at API schemas and |
59 _features files over multiple release versions of Chrome. | 61 _features files over multiple release versions of Chrome. |
60 ''' | 62 ''' |
61 | 63 |
62 def __init__(self, | 64 def __init__(self, |
63 branch_utility, | 65 branch_utility, |
64 compiled_fs_factory, | 66 compiled_fs_factory, |
(...skipping 23 matching lines...) Expand all Loading... |
88 return self._branch_utility.GetStableChannelInfo(api_info['version']) | 90 return self._branch_utility.GetStableChannelInfo(api_info['version']) |
89 else: | 91 else: |
90 return self._branch_utility.GetChannelInfo(api_info['channel']) | 92 return self._branch_utility.GetChannelInfo(api_info['channel']) |
91 | 93 |
92 def _GetApiSchemaFilename(self, api_name, file_system, version): | 94 def _GetApiSchemaFilename(self, api_name, file_system, version): |
93 '''Gets the name of the file which may contain the schema for |api_name| in | 95 '''Gets the name of the file which may contain the schema for |api_name| in |
94 |file_system|, or None if the API is not found. Note that this may be the | 96 |file_system|, or None if the API is not found. Note that this may be the |
95 single _EXTENSION_API file which all APIs share in older versions of Chrome, | 97 single _EXTENSION_API file which all APIs share in older versions of Chrome, |
96 in which case it is unknown whether the API actually exists there. | 98 in which case it is unknown whether the API actually exists there. |
97 ''' | 99 ''' |
98 def under_api_path(path): | 100 def find_schema_under_path(api_name, path): |
99 return API + path | 101 # |file_system| will cache the results from the ReadSingle() call. |
| 102 if not file_system.Exists(path).Get(): |
| 103 return None |
| 104 filenames = file_system.ReadSingle(path).Get() |
| 105 for ext in ('json', 'idl'): |
| 106 filename = '%s.%s' % (api_name, ext) |
| 107 if filename in filenames: |
| 108 return path + filename |
| 109 if _EXTENSION_API in filenames: |
| 110 return path + _EXTENSION_API |
| 111 # API schema data could not be found in any .json or .idl file. |
| 112 return None |
100 | 113 |
101 if version == 'trunk' or version > _ORIGINAL_FEATURES_MIN_VERSION: | 114 if version == 'trunk' or version > _ORIGINAL_FEATURES_MIN_VERSION: |
102 # API schema filenames switch format to unix_hacker_style. | 115 # API schema filenames switch format to unix_hacker_style. |
103 api_name = UnixName(api_name) | 116 api_name = UnixName(api_name) |
104 | 117 |
105 # |file_system| will cache the results from the ReadSingle() call. | 118 filename = find_schema_under_path(api_name, API) |
106 filenames = file_system.ReadSingle(API).Get() | 119 if filename is not None: |
107 | 120 return filename |
108 for ext in ('json', 'idl'): | 121 return find_schema_under_path(api_name, CHROME_API) |
109 filename = '%s.%s' % (api_name, ext) | |
110 if filename in filenames: | |
111 return under_api_path(filename) | |
112 if _EXTENSION_API in filenames: | |
113 return under_api_path(_EXTENSION_API) | |
114 # API schema data could not be found in any .json or .idl file. | |
115 return None | |
116 | 122 |
117 def _GetApiSchema(self, api_name, file_system, version): | 123 def _GetApiSchema(self, api_name, file_system, version): |
118 '''Searches |file_system| for |api_name|'s API schema data, and processes | 124 '''Searches |file_system| for |api_name|'s API schema data, and processes |
119 and returns it if found. | 125 and returns it if found. |
120 ''' | 126 ''' |
121 api_filename = self._GetApiSchemaFilename(api_name, file_system, version) | 127 api_filename = self._GetApiSchemaFilename(api_name, file_system, version) |
122 if api_filename is None: | 128 if api_filename is None: |
123 # No file for the API could be found in the given |file_system|. | 129 # No file for the API could be found in the given |file_system|. |
124 return None | 130 return None |
125 | 131 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 | 286 |
281 # Continue looping until there are no longer differences between this | 287 # Continue looping until there are no longer differences between this |
282 # version and trunk. | 288 # version and trunk. |
283 return version_stat != trunk_stat | 289 return version_stat != trunk_stat |
284 | 290 |
285 self._file_system_iterator.Ascending(self.GetApiAvailability(api_name), | 291 self._file_system_iterator.Ascending(self.GetApiAvailability(api_name), |
286 update_availability_graph) | 292 update_availability_graph) |
287 | 293 |
288 self._node_level_object_store.Set(api_name, availability_graph) | 294 self._node_level_object_store.Set(api_name, availability_graph) |
289 return availability_graph | 295 return availability_graph |
OLD | NEW |