| 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 base64 |
| 6 import json | 6 import json |
| 7 import os | 7 import os |
| 8 import re | 8 import re |
| 9 import time | 9 import time |
| 10 import urllib2 | 10 import urllib2 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 name = path.split('/')[0].lower() | 61 name = path.split('/')[0].lower() |
| 62 if name in components_renamed: | 62 if name in components_renamed: |
| 63 return components_renamed[name].lower() | 63 return components_renamed[name].lower() |
| 64 else: | 64 else: |
| 65 return name.lower() | 65 return name.lower() |
| 66 | 66 |
| 67 # Unknown path, return the whole path as component name. | 67 # Unknown path, return the whole path as component name. |
| 68 return '_'.join(path.split('/')) | 68 return '_'.join(path.split('/')) |
| 69 | 69 |
| 70 | 70 |
| 71 def _GetContentOfDEPS(revision, retries=5, sleep_time=0.1): | 71 def _GetContentOfDEPS(revision): |
| 72 chromium_git_file_url_template = CONFIG['chromium_git_file_url'] | 72 chromium_git_file_url_template = CONFIG['chromium_git_file_url'] |
| 73 | 73 |
| 74 deps_file_name = '.DEPS.git' | 74 # Try .DEPS.git first, because before migration from SVN to GIT, the .DEPS.git |
| 75 count = 0 | 75 # has the dependency in GIT repo while DEPS has dependency in SVN repo. |
| 76 while True: | 76 url = chromium_git_file_url_template % (revision, '.DEPS.git') |
| 77 count += 1 | 77 http_status_code, content = utils.GetHttpClient().Get( |
| 78 url, retries=5, retry_if_not=404) |
| 78 | 79 |
| 79 url = chromium_git_file_url_template % (revision, deps_file_name) | 80 # If .DEPS.git is not found, use DEPS, assuming it is a commit after migration |
| 80 http_status_code, content = utils.GetHttpClient().Get(url, timeout=60) | 81 # from SVN to GIT. |
| 82 if http_status_code == 404: |
| 83 url = chromium_git_file_url_template % (revision, 'DEPS') |
| 84 http_status_code, content = utils.GetHttpClient().Get(url, retries=5) |
| 81 | 85 |
| 82 if http_status_code == 404 and deps_file_name != 'DEPS': | 86 if http_status_code == 200: |
| 83 deps_file_name = 'DEPS' | 87 return base64.b64decode(content) |
| 84 count = 0 | 88 else: |
| 85 continue | 89 return '' |
| 86 elif http_status_code == 200: | |
| 87 # Googlesource git returns text file encoded in base64, so decode it. | |
| 88 return base64.b64decode(content) | |
| 89 | |
| 90 if count < retries: | |
| 91 time.sleep(sleep_time) | |
| 92 else: | |
| 93 break | |
| 94 | |
| 95 return '' | |
| 96 | 90 |
| 97 | 91 |
| 98 def GetChromiumComponents(chromium_revision, | 92 def GetChromiumComponents(chromium_revision, |
| 99 os_platform='unix', | 93 os_platform='unix', |
| 100 deps_file_downloader=_GetContentOfDEPS): | 94 deps_file_downloader=_GetContentOfDEPS): |
| 101 """Return a list of components used by Chrome of the given revision. | 95 """Return a list of components used by Chrome of the given revision. |
| 102 | 96 |
| 103 Args: | 97 Args: |
| 104 chromium_revision: Revision of the Chrome build: svn revision, or git hash. | 98 chromium_revision: Revision of the Chrome build: svn revision, or git hash. |
| 105 os_platform: The target platform of the Chrome build, eg. win, mac, etc. | 99 os_platform: The target platform of the Chrome build, eg. win, mac, etc. |
| 106 deps_file_downloader: A function that takes the chromium_revision as input, | 100 deps_file_downloader: A function that takes the chromium_revision as input, |
| 107 and returns the content of the DEPS file. The returned | 101 and returns the content of the DEPS file. The returned |
| 108 content is assumed to be trusted input and will be | 102 content is assumed to be trusted input and will be |
| 109 evaluated as python code. | 103 evaluated as python code. |
| 110 | 104 |
| 111 Returns: | 105 Returns: |
| 112 A map from component path to parsed component name, repository URL, | 106 A map from component path to parsed component name, repository URL, |
| 113 repository type and revision. | 107 repository type and revision. |
| 108 Return None if an error occurs. |
| 114 """ | 109 """ |
| 115 if os_platform.lower() == 'linux': | 110 if os_platform.lower() == 'linux': |
| 116 os_platform = 'unix' | 111 os_platform = 'unix' |
| 117 | 112 |
| 118 chromium_git_base_url = CONFIG['chromium_git_base_url'] | 113 chromium_git_base_url = CONFIG['chromium_git_base_url'] |
| 119 | 114 |
| 120 if not utils.IsGitHash(chromium_revision): | 115 if not utils.IsGitHash(chromium_revision): |
| 121 # Convert svn revision or commit position to Git hash. | 116 # Convert svn revision or commit position to Git hash. |
| 122 cr_rev_url_template = CONFIG['cr_rev_url'] | 117 cr_rev_url_template = CONFIG['cr_rev_url'] |
| 123 url = cr_rev_url_template % chromium_revision | 118 url = cr_rev_url_template % chromium_revision |
| 124 # TODO(stgao): Add retry in HttpClient. | 119 status_code, content = utils.GetHttpClient().Get( |
| 125 _, content = utils.GetHttpClient().Get(url, timeout=60) | 120 url, timeout=60, retries=5, retry_if_not=404) |
| 121 if status_code != 200 or not content: |
| 122 if status_code == 404: |
| 123 print 'Chromium commit position %s is not found.' % chromium_revision |
| 124 return None |
| 125 |
| 126 cr_rev_data = json.loads(content) | 126 cr_rev_data = json.loads(content) |
| 127 if 'git_sha' not in cr_rev_data: | 127 if 'git_sha' not in cr_rev_data: |
| 128 raise Exception('Failed to convert svn revision to git hash') | 128 return None |
| 129 chromium_revision = cr_rev_data['git_sha'] | 129 |
| 130 if 'repo' not in cr_rev_data or cr_rev_data['repo'] != 'chromium/src': |
| 131 print ('%s seems like a commit position of "%s", but not "chromium/src".' |
| 132 % (chromium_revision, cr_rev_data['repo'])) |
| 133 return None |
| 134 |
| 135 chromium_revision = cr_rev_data.get('git_sha') |
| 136 if not chromium_revision: |
| 137 return None |
| 130 | 138 |
| 131 # Download the content of DEPS file in chromium. | 139 # Download the content of DEPS file in chromium. |
| 132 deps_content = deps_file_downloader(chromium_revision) | 140 deps_content = deps_file_downloader(chromium_revision) |
| 141 if not deps_content: |
| 142 return None |
| 133 | 143 |
| 134 all_deps = {} | 144 all_deps = {} |
| 135 | 145 |
| 136 # Parse the content of DEPS file. | 146 # Parse the content of DEPS file. |
| 137 deps, deps_os = _ParseDEPS(deps_content) | 147 deps, deps_os = _ParseDEPS(deps_content) |
| 138 all_deps.update(deps) | 148 all_deps.update(deps) |
| 139 if os_platform is not None: | 149 if os_platform is not None: |
| 140 all_deps.update(deps_os.get(os_platform, {})) | 150 all_deps.update(deps_os.get(os_platform, {})) |
| 141 | 151 |
| 142 # Figure out components based on the dependencies. | 152 # Figure out components based on the dependencies. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 old_revision: The old revision of a Chrome build. | 199 old_revision: The old revision of a Chrome build. |
| 190 new_revision: The new revision of a Chrome build. | 200 new_revision: The new revision of a Chrome build. |
| 191 os_platform: The target platform of the Chrome build, eg. win, mac, etc. | 201 os_platform: The target platform of the Chrome build, eg. win, mac, etc. |
| 192 deps_file_downloader: A function that takes the chromium_revision as input, | 202 deps_file_downloader: A function that takes the chromium_revision as input, |
| 193 and returns the content of the DEPS file. The returned | 203 and returns the content of the DEPS file. The returned |
| 194 content is assumed to be trusted input and will be | 204 content is assumed to be trusted input and will be |
| 195 evaluated as python code. | 205 evaluated as python code. |
| 196 | 206 |
| 197 Returns: | 207 Returns: |
| 198 A map from component path to its parsed regression and other information. | 208 A map from component path to its parsed regression and other information. |
| 209 Return None if an error occurs. |
| 199 """ | 210 """ |
| 200 # Assume first revision is the old revision. | |
| 201 old_components = GetChromiumComponents(old_revision, os_platform, | 211 old_components = GetChromiumComponents(old_revision, os_platform, |
| 202 deps_file_downloader) | 212 deps_file_downloader) |
| 213 if not old_components: |
| 214 return None |
| 215 |
| 203 new_components = GetChromiumComponents(new_revision, os_platform, | 216 new_components = GetChromiumComponents(new_revision, os_platform, |
| 204 deps_file_downloader) | 217 deps_file_downloader) |
| 218 if not new_components: |
| 219 return None |
| 205 | 220 |
| 206 components = {} | 221 components = {} |
| 207 for path in new_components: | 222 for path in new_components: |
| 208 new_component = new_components[path] | 223 new_component = new_components[path] |
| 209 old_revision = None | 224 old_revision = None |
| 210 | 225 |
| 211 if path in old_components: | 226 if path in old_components: |
| 212 old_component = old_components[path] | 227 old_component = old_components[path] |
| 213 old_revision = old_component['revision'] | 228 old_revision = old_component['revision'] |
| 214 | 229 |
| 215 components[path] = { | 230 components[path] = { |
| 216 'path': path, | 231 'path': path, |
| 217 'rolled': new_component['revision'] != old_revision, | 232 'rolled': new_component['revision'] != old_revision, |
| 218 'name': new_component['name'], | 233 'name': new_component['name'], |
| 219 'old_revision': old_revision, | 234 'old_revision': old_revision, |
| 220 'new_revision': new_component['revision'], | 235 'new_revision': new_component['revision'], |
| 221 'repository': new_component['repository'], | 236 'repository': new_component['repository'], |
| 222 'repository_type': new_component['repository_type'] | 237 'repository_type': new_component['repository_type'] |
| 223 } | 238 } |
| 224 | 239 |
| 225 return components | 240 return components |
| OLD | NEW |