OLD | NEW |
1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2014 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 base64 |
5 import https | 6 import https |
6 import utils | 7 import utils |
7 | 8 |
8 | 9 |
9 DEPS_FILE_URL = 'https://src.chromium.org/chrome/trunk/src/DEPS?p=%s' | 10 DEPS_FILE_URL_SVN = 'https://src.chromium.org/chrome/trunk/src/DEPS?p=%s' |
| 11 DEPS_FILE_URL_GIT = ( |
| 12 'https://chromium.googlesource.com/chromium/src/+/%s/DEPS?format=text') |
10 | 13 |
11 | 14 |
12 class _VarImpl(object): | 15 class _VarImpl(object): |
| 16 |
13 def __init__(self, local_scope): | 17 def __init__(self, local_scope): |
14 self._local_scope = local_scope | 18 self._local_scope = local_scope |
15 | 19 |
16 def Lookup(self, var_name): | 20 def Lookup(self, var_name): |
17 if var_name in self._local_scope.get('vars', {}): | 21 if var_name in self._local_scope.get('vars', {}): |
18 return self._local_scope['vars'][var_name] | 22 return self._local_scope['vars'][var_name] |
19 raise Exception('Var is not defined: %s' % var_name) | 23 raise Exception('Var is not defined: %s' % var_name) |
20 | 24 |
21 | 25 |
22 def _ParseDEPS(content): | 26 def _ParseDEPS(content): |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 if name in components_renamed: | 67 if name in components_renamed: |
64 return components_renamed[name].lower() | 68 return components_renamed[name].lower() |
65 else: | 69 else: |
66 return name.lower() | 70 return name.lower() |
67 | 71 |
68 # Unknown path, return the whole path as component name. | 72 # Unknown path, return the whole path as component name. |
69 return '_'.join(path.split('/')) | 73 return '_'.join(path.split('/')) |
70 | 74 |
71 | 75 |
72 def _GetContentOfDEPS(chromium_revision): | 76 def _GetContentOfDEPS(chromium_revision): |
73 return https.SendRequest(DEPS_FILE_URL % chromium_revision) | 77 if utils.IsGitHash(chromium_revision): |
| 78 url = DEPS_FILE_URL_GIT |
| 79 else: |
| 80 url = DEPS_FILE_URL_SVN |
| 81 return https.SendRequest(url % chromium_revision) |
74 | 82 |
75 | 83 |
76 def GetChromiumComponents(chromium_revision, | 84 def GetChromiumComponents(chromium_revision, |
77 os_platform='unix', | 85 os_platform='unix', |
78 deps_file_downloader=_GetContentOfDEPS): | 86 deps_file_downloader=_GetContentOfDEPS): |
79 """Return a list of components used by Chrome of the given revision. | 87 """Return a list of components used by Chrome of the given revision. |
80 | 88 |
81 Args: | 89 Args: |
82 chromium_revision: The revision of the Chrome build. | 90 chromium_revision: The revision of the Chrome build. |
83 os_platform: The target platform of the Chrome build, eg. win, mac, etc. | 91 os_platform: The target platform of the Chrome build, eg. win, mac, etc. |
84 deps_file_downloader: A function that takes the chromium_revision as input, | 92 deps_file_downloader: A function that takes the chromium_revision as input, |
85 and returns the content of the DEPS file. The returned | 93 and returns the content of the DEPS file. The returned |
86 content is assumed to be trusted input and will be | 94 content is assumed to be trusted input and will be |
87 evaluated as python code. | 95 evaluated as python code. |
| 96 |
| 97 Returns: |
| 98 A map from component path to parsed component name, repository URL, |
| 99 repository type and revision. |
88 """ | 100 """ |
89 if os_platform.lower() == 'linux': | 101 if os_platform.lower() == 'linux': |
90 os_platform = 'unix' | 102 os_platform = 'unix' |
91 | 103 |
| 104 is_git_hash = utils.IsGitHash(chromium_revision) |
| 105 |
92 # Download the content of DEPS file in chromium. | 106 # Download the content of DEPS file in chromium. |
93 deps_content = deps_file_downloader(chromium_revision) | 107 deps_content = deps_file_downloader(chromium_revision) |
94 | 108 |
| 109 # Googlesource git returns text file encoded in base64, so decode it. |
| 110 if is_git_hash: |
| 111 deps_content = base64.b64decode(deps_content) |
| 112 |
95 all_deps = {} | 113 all_deps = {} |
96 | 114 |
97 # Parse the content of DEPS file. | 115 # Parse the content of DEPS file. |
98 deps, deps_os = _ParseDEPS(deps_content) | 116 deps, deps_os = _ParseDEPS(deps_content) |
99 all_deps.update(deps) | 117 all_deps.update(deps) |
100 if os_platform is not None: | 118 if os_platform is not None: |
101 all_deps.update(deps_os.get(os_platform, {})) | 119 all_deps.update(deps_os.get(os_platform, {})) |
102 | 120 |
103 # Figure out components based on the dependencies. | 121 # Figure out components based on the dependencies. |
104 components = {} | 122 components = {} |
105 for component_path in all_deps.keys(): | 123 for component_path in all_deps: |
106 name = _GetComponentName(component_path) | 124 name = _GetComponentName(component_path) |
107 repository, revision = all_deps[component_path].split('@') | 125 repository, revision = all_deps[component_path].split('@') |
108 is_git_hash = utils.IsGitHash(revision) | 126 is_git_hash = utils.IsGitHash(revision) |
109 if repository.startswith('/'): | 127 if repository.startswith('/'): |
110 # TODO(stgao): Use git repo after chromium moves to git. | 128 # TODO(stgao): Use git repo after chromium moves to git. |
111 repository = 'https://src.chromium.org/chrome%s' % repository | 129 repository = 'https://src.chromium.org/chrome%s' % repository |
112 if is_git_hash: | 130 if is_git_hash: |
113 repository_type = 'git' | 131 repository_type = 'git' |
114 else: | 132 else: |
115 repository_type = 'svn' | 133 repository_type = 'svn' |
116 if not component_path.endswith('/'): | 134 if not component_path.endswith('/'): |
117 component_path += '/' | 135 component_path += '/' |
118 components[component_path] = { | 136 components[component_path] = { |
119 'path': component_path, | 137 'path': component_path, |
120 'name': name, | 138 'name': name, |
121 'repository': repository, | 139 'repository': repository, |
122 'repository_type': repository_type, | 140 'repository_type': repository_type, |
123 'revision': revision | 141 'revision': revision |
124 } | 142 } |
125 | 143 |
126 # Add chromium as a component. | 144 # Add chromium as a component, depending on the repository type. |
127 # TODO(stgao): Move to git. | 145 if is_git_hash: |
| 146 repository = 'https://chromium.googlesource.com/chromium/src/' |
| 147 repository_type = 'git' |
| 148 else: |
| 149 repository = 'https://src.chromium.org/chrome/trunk' |
| 150 repository_type = 'svn' |
| 151 |
128 components['src/'] = { | 152 components['src/'] = { |
129 'path': 'src/', | 153 'path': 'src/', |
130 'name': 'chromium', | 154 'name': 'chromium', |
131 'repository': 'https://src.chromium.org/chrome/trunk', | 155 'repository': repository, |
132 'repository_type': 'svn', | 156 'repository_type': repository_type, |
133 'revision': chromium_revision | 157 'revision': chromium_revision |
134 } | 158 } |
135 | 159 |
136 return components | 160 return components |
137 | 161 |
138 | 162 |
139 def GetChromiumComponentRange(chromium_revision1, | 163 def GetChromiumComponentRange(old_revision, |
140 chromium_revision2, | 164 new_revision, |
141 os_platform='unix', | 165 os_platform='unix', |
142 deps_file_downloader=_GetContentOfDEPS): | 166 deps_file_downloader=_GetContentOfDEPS): |
143 """Return a list of components with their revision ranges. | 167 """Return a list of components with their revision ranges. |
144 | 168 |
145 Args: | 169 Args: |
146 chromium_revision1: The revision of a Chrome build. | 170 old_revision: The old revision of a Chrome build. |
147 chromium_revision2: The revision of another Chrome build. | 171 new_revision: The new revision of a Chrome build. |
148 os_platform: The target platform of the Chrome build, eg. win, mac, etc. | 172 os_platform: The target platform of the Chrome build, eg. win, mac, etc. |
149 deps_file_downloader: A function that takes the chromium_revision as input, | 173 deps_file_downloader: A function that takes the chromium_revision as input, |
150 and returns the content of the DEPS file. The returned | 174 and returns the content of the DEPS file. The returned |
151 content is assumed to be trusted input and will be | 175 content is assumed to be trusted input and will be |
152 evaluated as python code. | 176 evaluated as python code. |
| 177 |
| 178 Returns: |
| 179 A map from component path to its parsed regression and other information. |
153 """ | 180 """ |
154 # TODO(stgao): support git. | 181 # Assume first revision is the old revision. |
155 chromium_revision1 = int(chromium_revision1) | |
156 chromium_revision2 = int(chromium_revision2) | |
157 old_revision = str(min(chromium_revision1, chromium_revision2)) | |
158 new_revision = str(max(chromium_revision1, chromium_revision2)) | |
159 | |
160 old_components = GetChromiumComponents(old_revision, os_platform, | 182 old_components = GetChromiumComponents(old_revision, os_platform, |
161 deps_file_downloader) | 183 deps_file_downloader) |
162 new_components = GetChromiumComponents(new_revision, os_platform, | 184 new_components = GetChromiumComponents(new_revision, os_platform, |
163 deps_file_downloader) | 185 deps_file_downloader) |
164 | 186 |
165 components = {} | 187 components = {} |
166 for path in new_components.keys(): | 188 for path in new_components: |
167 new_component = new_components[path] | 189 new_component = new_components[path] |
168 old_revision = None | 190 old_revision = None |
169 if path in old_components: | 191 if path in old_components: |
170 old_component = old_components[path] | 192 old_component = old_components[path] |
171 old_revision = old_component['revision'] | 193 old_revision = old_component['revision'] |
172 components[path] = { | 194 components[path] = { |
173 'path': path, | 195 'path': path, |
174 'rolled': new_component['revision'] != old_revision, | 196 'rolled': new_component['revision'] != old_revision, |
175 'name': new_component['name'], | 197 'name': new_component['name'], |
176 'old_revision': old_revision, | 198 'old_revision': old_revision, |
177 'new_revision': new_component['revision'], | 199 'new_revision': new_component['revision'], |
178 'repository': new_component['repository'], | 200 'repository': new_component['repository'], |
179 'repository_type': new_component['repository_type'] | 201 'repository_type': new_component['repository_type'] |
180 } | 202 } |
181 | 203 |
182 return components | 204 return components |
183 | 205 |
184 | 206 |
185 if __name__ == '__main__': | 207 if __name__ == '__main__': |
186 import json | 208 import json |
187 print json.dumps(GetChromiumComponents(284750), sort_keys=True, indent=2) | 209 print json.dumps(GetChromiumComponents( |
| 210 'b4b1aea80b25a3b2f7952c9d95585e880421ef2b'), sort_keys=True, indent=2) |
OLD | NEW |