OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Applies an issue from Rietveld. | 6 """Applies an issue from Rietveld. |
7 """ | 7 """ |
8 | 8 |
9 import getpass | 9 import getpass |
10 import json | 10 import json |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 try: | 159 try: |
160 properties = obj.get_issue_properties(options.issue, False) | 160 properties = obj.get_issue_properties(options.issue, False) |
161 except rietveld.upload.ClientLoginError as e: | 161 except rietveld.upload.ClientLoginError as e: |
162 print('Accessing the issue requires proper credentials.') | 162 print('Accessing the issue requires proper credentials.') |
163 return 1 | 163 return 1 |
164 | 164 |
165 if not options.patchset: | 165 if not options.patchset: |
166 options.patchset = properties['patchsets'][-1] | 166 options.patchset = properties['patchsets'][-1] |
167 print('No patchset specified. Using patchset %d' % options.patchset) | 167 print('No patchset specified. Using patchset %d' % options.patchset) |
168 | 168 |
169 issues_patchsets_to_apply = [(options.issue, options.patchset)] | 169 print('Downloading the patch.') |
170 depends_on_info = obj.get_depends_on_patchset(options.issue, options.patchset) | 170 try: |
171 while depends_on_info: | 171 patchset = obj.get_patch(options.issue, options.patchset) |
172 depends_on_issue = int(depends_on_info['issue']) | 172 except urllib2.HTTPError as e: |
173 depends_on_patchset = int(depends_on_info['patchset']) | 173 print( |
174 try: | 174 'Failed to fetch the patch for issue %d, patchset %d.\n' |
175 depends_on_info = obj.get_depends_on_patchset(depends_on_issue, | 175 'Try visiting %s/%d') % ( |
176 depends_on_patchset) | 176 options.issue, options.patchset, |
177 issues_patchsets_to_apply.insert(0, (depends_on_issue, | 177 options.server, options.issue) |
178 depends_on_patchset)) | 178 return 1 |
179 except urllib2.HTTPError: | 179 if options.whitelist: |
180 print ('The patchset that was marked as a dependency no longer ' | 180 patchset.patches = [patch for patch in patchset.patches |
181 'exists: %s/%d/#ps%d' % ( | 181 if patch.filename in options.whitelist] |
182 options.server, depends_on_issue, depends_on_patchset)) | 182 if options.blacklist: |
183 print 'Therefore it is likely that this patch will not apply cleanly.' | 183 patchset.patches = [patch for patch in patchset.patches |
184 print | 184 if patch.filename not in options.blacklist] |
185 depends_on_info = None | 185 for patch in patchset.patches: |
| 186 print(patch) |
| 187 full_dir = os.path.abspath(options.root_dir) |
| 188 scm_type = scm.determine_scm(full_dir) |
| 189 if scm_type == 'svn': |
| 190 scm_obj = checkout.SvnCheckout(full_dir, None, None, None, None) |
| 191 elif scm_type == 'git': |
| 192 scm_obj = checkout.GitCheckout(full_dir, None, None, None, None) |
| 193 elif scm_type == None: |
| 194 scm_obj = checkout.RawCheckout(full_dir, None, None) |
| 195 else: |
| 196 parser.error('Couldn\'t determine the scm') |
186 | 197 |
187 num_issues_patchsets_to_apply = len(issues_patchsets_to_apply) | 198 # TODO(maruel): HACK, remove me. |
188 if num_issues_patchsets_to_apply > 1: | 199 # When run a build slave, make sure buildbot knows that the checkout was |
189 print | 200 # modified. |
190 print 'apply_issue.py found %d dependent CLs.' % ( | 201 if options.root_dir == 'src' and getpass.getuser() == 'chrome-bot': |
191 num_issues_patchsets_to_apply - 1) | 202 # See sourcedirIsPatched() in: |
192 print 'They will be applied in the following order:' | 203 # http://src.chromium.org/viewvc/chrome/trunk/tools/build/scripts/slave/ |
193 num = 1 | 204 # chromium_commands.py?view=markup |
194 for issue_to_apply, patchset_to_apply in issues_patchsets_to_apply: | 205 open('.buildbot-patched', 'w').close() |
195 print ' #%d %s/%d/#ps%d' % ( | |
196 num, options.server, issue_to_apply, patchset_to_apply) | |
197 num += 1 | |
198 print | |
199 | 206 |
200 for issue_to_apply, patchset_to_apply in issues_patchsets_to_apply: | 207 print('\nApplying the patch.') |
201 issue_url = '%s/%d/#ps%d' % (options.server, issue_to_apply, | 208 try: |
202 patchset_to_apply) | 209 scm_obj.apply_patch(patchset, verbose=True) |
203 print('Downloading patch from %s' % issue_url) | 210 except checkout.PatchApplicationFailed as e: |
204 try: | 211 print(str(e)) |
205 patchset = obj.get_patch(issue_to_apply, patchset_to_apply) | 212 print('CWD=%s' % os.getcwd()) |
206 except urllib2.HTTPError as e: | 213 print('Checkout path=%s' % scm_obj.project_path) |
207 print( | 214 return 1 |
208 'Failed to fetch the patch for issue %d, patchset %d.\n' | |
209 'Try visiting %s/%d') % ( | |
210 issue_to_apply, patchset_to_apply, | |
211 options.server, issue_to_apply) | |
212 return 1 | |
213 if options.whitelist: | |
214 patchset.patches = [patch for patch in patchset.patches | |
215 if patch.filename in options.whitelist] | |
216 if options.blacklist: | |
217 patchset.patches = [patch for patch in patchset.patches | |
218 if patch.filename not in options.blacklist] | |
219 for patch in patchset.patches: | |
220 print(patch) | |
221 full_dir = os.path.abspath(options.root_dir) | |
222 scm_type = scm.determine_scm(full_dir) | |
223 if scm_type == 'svn': | |
224 scm_obj = checkout.SvnCheckout(full_dir, None, None, None, None) | |
225 elif scm_type == 'git': | |
226 scm_obj = checkout.GitCheckout(full_dir, None, None, None, None) | |
227 elif scm_type == None: | |
228 scm_obj = checkout.RawCheckout(full_dir, None, None) | |
229 else: | |
230 parser.error('Couldn\'t determine the scm') | |
231 | |
232 # TODO(maruel): HACK, remove me. | |
233 # When run a build slave, make sure buildbot knows that the checkout was | |
234 # modified. | |
235 if options.root_dir == 'src' and getpass.getuser() == 'chrome-bot': | |
236 # See sourcedirIsPatched() in: | |
237 # http://src.chromium.org/viewvc/chrome/trunk/tools/build/scripts/slave/ | |
238 # chromium_commands.py?view=markup | |
239 open('.buildbot-patched', 'w').close() | |
240 | |
241 print('\nApplying the patch from %s' % issue_url) | |
242 try: | |
243 scm_obj.apply_patch(patchset, verbose=True) | |
244 except checkout.PatchApplicationFailed as e: | |
245 print(str(e)) | |
246 print('CWD=%s' % os.getcwd()) | |
247 print('Checkout path=%s' % scm_obj.project_path) | |
248 return 1 | |
249 | 215 |
250 if ('DEPS' in map(os.path.basename, patchset.filenames) | 216 if ('DEPS' in map(os.path.basename, patchset.filenames) |
251 and not options.ignore_deps): | 217 and not options.ignore_deps): |
252 gclient_root = gclient_utils.FindGclientRoot(full_dir) | 218 gclient_root = gclient_utils.FindGclientRoot(full_dir) |
253 if gclient_root and scm_type: | 219 if gclient_root and scm_type: |
254 print( | 220 print( |
255 'A DEPS file was updated inside a gclient checkout, running gclient ' | 221 'A DEPS file was updated inside a gclient checkout, running gclient ' |
256 'sync.') | 222 'sync.') |
257 gclient_path = os.path.join(BASE_DIR, 'gclient') | 223 gclient_path = os.path.join(BASE_DIR, 'gclient') |
258 if sys.platform == 'win32': | 224 if sys.platform == 'win32': |
(...skipping 20 matching lines...) Expand all Loading... |
279 return 0 | 245 return 0 |
280 | 246 |
281 | 247 |
282 if __name__ == "__main__": | 248 if __name__ == "__main__": |
283 fix_encoding.fix_encoding() | 249 fix_encoding.fix_encoding() |
284 try: | 250 try: |
285 sys.exit(main()) | 251 sys.exit(main()) |
286 except KeyboardInterrupt: | 252 except KeyboardInterrupt: |
287 sys.stderr.write('interrupted\n') | 253 sys.stderr.write('interrupted\n') |
288 sys.exit(1) | 254 sys.exit(1) |
OLD | NEW |