Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: tools/findit/chromium_deps.py

Issue 504443004: [Findit] Improve output format and cherry-pick bugs fix. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix nit. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/findit/chromium_deps_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 time 8 import time
9 import urllib2 9 import urllib2
10 10
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 name = path.split('/')[0].lower() 59 name = path.split('/')[0].lower()
60 if name in components_renamed: 60 if name in components_renamed:
61 return components_renamed[name].lower() 61 return components_renamed[name].lower()
62 else: 62 else:
63 return name.lower() 63 return name.lower()
64 64
65 # Unknown path, return the whole path as component name. 65 # Unknown path, return the whole path as component name.
66 return '_'.join(path.split('/')) 66 return '_'.join(path.split('/'))
67 67
68 68
69 def _GetContentOfDEPS(url, retries=5, sleep_time=0.1): 69 def _GetContentOfDEPS(revision, retries=5, sleep_time=0.1):
70 chromium_git_file_url_template = CONFIG['chromium_git_file_url']
71
72 deps_file_name = '.DEPS.git'
70 count = 0 73 count = 0
71 while True: 74 while True:
72 count += 1 75 count += 1
73 try:
74 _, content = utils.GetHttpClient().Get(url, timeout=60)
75 return content
76 76
77 # TODO(jeun): Handle HTTP Errors, such as 404. 77 url = chromium_git_file_url_template % (revision, deps_file_name)
78 except urllib2.HTTPError: 78 http_status_code, content = utils.GetHttpClient().Get(url, timeout=60)
79 if count < retries: 79
80 time.sleep(sleep_time) 80 if http_status_code == 404 and deps_file_name != 'DEPS':
81 else: 81 deps_file_name = 'DEPS'
82 break 82 count = 0
83 continue
84 elif http_status_code == 200:
85 # Googlesource git returns text file encoded in base64, so decode it.
86 return base64.b64decode(content)
87
88 if count < retries:
89 time.sleep(sleep_time)
90 else:
91 break
83 92
84 return '' 93 return ''
85 94
86 95
87 def GetChromiumComponents(chromium_revision, 96 def GetChromiumComponents(chromium_revision,
88 os_platform='unix', 97 os_platform='unix',
89 deps_file_downloader=_GetContentOfDEPS): 98 deps_file_downloader=_GetContentOfDEPS):
90 """Return a list of components used by Chrome of the given revision. 99 """Return a list of components used by Chrome of the given revision.
91 100
92 Args: 101 Args:
93 chromium_revision: The revision of the Chrome build. 102 chromium_revision: Revision of the Chrome build: svn revision, or git hash.
94 os_platform: The target platform of the Chrome build, eg. win, mac, etc. 103 os_platform: The target platform of the Chrome build, eg. win, mac, etc.
95 deps_file_downloader: A function that takes the chromium_revision as input, 104 deps_file_downloader: A function that takes the chromium_revision as input,
96 and returns the content of the DEPS file. The returned 105 and returns the content of the DEPS file. The returned
97 content is assumed to be trusted input and will be 106 content is assumed to be trusted input and will be
98 evaluated as python code. 107 evaluated as python code.
99 108
100 Returns: 109 Returns:
101 A map from component path to parsed component name, repository URL, 110 A map from component path to parsed component name, repository URL,
102 repository type and revision. 111 repository type and revision.
103 """ 112 """
104 if os_platform.lower() == 'linux': 113 if os_platform.lower() == 'linux':
105 os_platform = 'unix' 114 os_platform = 'unix'
106 115
107 git_base_url = CONFIG['git_base_url'] 116 chromium_git_base_url = CONFIG['chromium_git_base_url']
108 git_deps_path = CONFIG['git_deps_path'] 117
109 svn_base_url = CONFIG['svn_base_url'] 118 if not utils.IsGitHash(chromium_revision):
110 svn_deps_path = CONFIG['svn_deps_path'] 119 # Convert svn revision or commit position to Git hash.
111 svn_src_chromium_url = CONFIG['svn_src_chromium_url'] 120 cr_rev_url_template = CONFIG['cr_rev_url']
112 is_git_hash = utils.IsGitHash(chromium_revision) 121 url = cr_rev_url_template % chromium_revision
113 if is_git_hash: 122 # TODO(stgao): Add retry in HttpClient.
114 url = git_base_url + (git_deps_path % chromium_revision) 123 _, content = utils.GetHttpClient().Get(url, timeout=60)
115 else: 124 cr_rev_data = json.loads(content)
116 url = svn_base_url + (svn_deps_path % chromium_revision) 125 if 'git_sha' not in cr_rev_data:
126 raise Exception('Failed to convert svn revision to git hash')
127 chromium_revision = cr_rev_data['git_sha']
117 128
118 # Download the content of DEPS file in chromium. 129 # Download the content of DEPS file in chromium.
119 deps_content = deps_file_downloader(url) 130 deps_content = deps_file_downloader(chromium_revision)
120
121 # Googlesource git returns text file encoded in base64, so decode it.
122 if is_git_hash:
123 deps_content = base64.b64decode(deps_content)
124 131
125 all_deps = {} 132 all_deps = {}
126 133
127 # Parse the content of DEPS file. 134 # Parse the content of DEPS file.
128 deps, deps_os = _ParseDEPS(deps_content) 135 deps, deps_os = _ParseDEPS(deps_content)
129 all_deps.update(deps) 136 all_deps.update(deps)
130 if os_platform is not None: 137 if os_platform is not None:
131 all_deps.update(deps_os.get(os_platform, {})) 138 all_deps.update(deps_os.get(os_platform, {}))
132 139
133 # Figure out components based on the dependencies. 140 # Figure out components based on the dependencies.
134 components = {} 141 components = {}
135 host_dirs = CONFIG['host_directories'] 142 host_dirs = CONFIG['host_directories']
136 for component_path in all_deps: 143 for component_path, component_repo_url in all_deps.iteritems():
144 if component_repo_url is None:
145 # For some platform like iso, some component is ignored.
146 continue
147
137 name = _GetComponentName(component_path, host_dirs) 148 name = _GetComponentName(component_path, host_dirs)
138 repository, revision = all_deps[component_path].split('@') 149 repository, revision = component_repo_url.split('@')
139 is_git_hash = utils.IsGitHash(revision) 150 is_git_hash = utils.IsGitHash(revision)
140 if repository.startswith('/'):
141 # In DEPS file, if a path starts with /, it is a relative path to the
142 # https://src.chromium.org/chrome. Strip /trunk at the end of the base
143 # url and add it to the base url.
144 # TODO(stgao): Use git repo after chromium moves to git.
145 repository = svn_src_chromium_url + repository
146 if is_git_hash: 151 if is_git_hash:
147 repository_type = 'git' 152 repository_type = 'git'
148 else: 153 else:
149 repository_type = 'svn' 154 repository_type = 'svn'
150 if not component_path.endswith('/'): 155 if not component_path.endswith('/'):
151 component_path += '/' 156 component_path += '/'
152 components[component_path] = { 157 components[component_path] = {
153 'path': component_path, 158 'path': component_path,
154 'name': name, 159 'name': name,
155 'repository': repository, 160 'repository': repository,
156 'repository_type': repository_type, 161 'repository_type': repository_type,
157 'revision': revision 162 'revision': revision
158 } 163 }
159 164
160 # Add chromium as a component, depending on the repository type. 165 # Add chromium as a component.
161 if is_git_hash:
162 repository = git_base_url
163 repository_type = 'git'
164 else:
165 repository = svn_base_url
166 repository_type = 'svn'
167
168 components['src/'] = { 166 components['src/'] = {
169 'path': 'src/', 167 'path': 'src/',
170 'name': 'chromium', 168 'name': 'chromium',
171 'repository': repository, 169 'repository': chromium_git_base_url,
172 'repository_type': repository_type, 170 'repository_type': 'git',
173 'revision': chromium_revision 171 'revision': chromium_revision
174 } 172 }
175 173
176 return components 174 return components
177 175
178 176
179 def GetChromiumComponentRange(old_revision, 177 def GetChromiumComponentRange(old_revision,
180 new_revision, 178 new_revision,
181 os_platform='unix', 179 os_platform='unix',
182 deps_file_downloader=_GetContentOfDEPS): 180 deps_file_downloader=_GetContentOfDEPS):
(...skipping 30 matching lines...) Expand all
213 'path': path, 211 'path': path,
214 'rolled': new_component['revision'] != old_revision, 212 'rolled': new_component['revision'] != old_revision,
215 'name': new_component['name'], 213 'name': new_component['name'],
216 'old_revision': old_revision, 214 'old_revision': old_revision,
217 'new_revision': new_component['revision'], 215 'new_revision': new_component['revision'],
218 'repository': new_component['repository'], 216 'repository': new_component['repository'],
219 'repository_type': new_component['repository_type'] 217 'repository_type': new_component['repository_type']
220 } 218 }
221 219
222 return components 220 return components
OLDNEW
« no previous file with comments | « no previous file | tools/findit/chromium_deps_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698