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

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: Address comments. 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
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 _, content = utils.GetHttpClient().Get(url, timeout=60)
114 url = git_base_url + (git_deps_path % chromium_revision) 123 cr_rev_data = json.loads(content)
115 else: 124 if 'git_sha' not in cr_rev_data:
116 url = svn_base_url + (svn_deps_path % chromium_revision) 125 raise Exception('Failed to convert svn revision to git hash')
126 chromium_revision = cr_rev_data['git_sha']
117 127
118 # Download the content of DEPS file in chromium. 128 # Download the content of DEPS file in chromium.
119 deps_content = deps_file_downloader(url) 129 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 130
125 all_deps = {} 131 all_deps = {}
126 132
127 # Parse the content of DEPS file. 133 # Parse the content of DEPS file.
128 deps, deps_os = _ParseDEPS(deps_content) 134 deps, deps_os = _ParseDEPS(deps_content)
129 all_deps.update(deps) 135 all_deps.update(deps)
130 if os_platform is not None: 136 if os_platform is not None:
131 all_deps.update(deps_os.get(os_platform, {})) 137 all_deps.update(deps_os.get(os_platform, {}))
132 138
133 # Figure out components based on the dependencies. 139 # Figure out components based on the dependencies.
134 components = {} 140 components = {}
135 host_dirs = CONFIG['host_directories'] 141 host_dirs = CONFIG['host_directories']
136 for component_path in all_deps: 142 for component_path, component_repo_url in all_deps.iteritems():
143 if component_repo_url is None:
144 # For some platform like iso, some component is ignored.
145 continue
146
137 name = _GetComponentName(component_path, host_dirs) 147 name = _GetComponentName(component_path, host_dirs)
138 repository, revision = all_deps[component_path].split('@') 148 repository, revision = component_repo_url.split('@')
139 is_git_hash = utils.IsGitHash(revision) 149 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: 150 if is_git_hash:
147 repository_type = 'git' 151 repository_type = 'git'
148 else: 152 else:
149 repository_type = 'svn' 153 repository_type = 'svn'
150 if not component_path.endswith('/'): 154 if not component_path.endswith('/'):
151 component_path += '/' 155 component_path += '/'
152 components[component_path] = { 156 components[component_path] = {
153 'path': component_path, 157 'path': component_path,
154 'name': name, 158 'name': name,
155 'repository': repository, 159 'repository': repository,
156 'repository_type': repository_type, 160 'repository_type': repository_type,
157 'revision': revision 161 'revision': revision
158 } 162 }
159 163
160 # Add chromium as a component, depending on the repository type. 164 # 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/'] = { 165 components['src/'] = {
169 'path': 'src/', 166 'path': 'src/',
170 'name': 'chromium', 167 'name': 'chromium',
171 'repository': repository, 168 'repository': chromium_git_base_url,
172 'repository_type': repository_type, 169 'repository_type': 'git',
173 'revision': chromium_revision 170 'revision': chromium_revision
174 } 171 }
175 172
176 return components 173 return components
177 174
178 175
179 def GetChromiumComponentRange(old_revision, 176 def GetChromiumComponentRange(old_revision,
180 new_revision, 177 new_revision,
181 os_platform='unix', 178 os_platform='unix',
182 deps_file_downloader=_GetContentOfDEPS): 179 deps_file_downloader=_GetContentOfDEPS):
(...skipping 30 matching lines...) Expand all
213 'path': path, 210 'path': path,
214 'rolled': new_component['revision'] != old_revision, 211 'rolled': new_component['revision'] != old_revision,
215 'name': new_component['name'], 212 'name': new_component['name'],
216 'old_revision': old_revision, 213 'old_revision': old_revision,
217 'new_revision': new_component['revision'], 214 'new_revision': new_component['revision'],
218 'repository': new_component['repository'], 215 'repository': new_component['repository'],
219 'repository_type': new_component['repository_type'] 216 'repository_type': new_component['repository_type']
220 } 217 }
221 218
222 return components 219 return components
OLDNEW
« no previous file with comments | « no previous file | tools/findit/chromium_deps_unittest.py » ('j') | tools/findit/common/http_client_local.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698