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 print('Downloading the patch.') | 169 issues_patchsets_to_apply = [(options.issue, options.patchset)] |
170 try: | 170 depends_on_info = obj.get_depends_on_patchset(options.issue, options.patchset) |
171 patchset = obj.get_patch(options.issue, options.patchset) | 171 while depends_on_info: |
172 except urllib2.HTTPError as e: | 172 depends_on_issue = int(depends_on_info['issue']) |
173 print( | 173 depends_on_patchset = int(depends_on_info['patchset']) |
174 'Failed to fetch the patch for issue %d, patchset %d.\n' | 174 try: |
175 'Try visiting %s/%d') % ( | 175 depends_on_info = obj.get_depends_on_patchset(depends_on_issue, |
176 options.issue, options.patchset, | 176 depends_on_patchset) |
177 options.server, options.issue) | 177 issues_patchsets_to_apply.insert(0, (depends_on_issue, |
178 return 1 | 178 depends_on_patchset)) |
179 if options.whitelist: | 179 except urllib2.HTTPError: |
180 patchset.patches = [patch for patch in patchset.patches | 180 print ('The patchset that was marked as a dependency no longer ' |
181 if patch.filename in options.whitelist] | 181 'exists: %s/%d/#ps%d' % ( |
182 if options.blacklist: | 182 options.server, depends_on_issue, depends_on_patchset)) |
183 patchset.patches = [patch for patch in patchset.patches | 183 print 'Therefore it is likely that this patch will not apply cleanly.' |
184 if patch.filename not in options.blacklist] | 184 print |
185 for patch in patchset.patches: | 185 depends_on_info = None |
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') | |
197 | 186 |
198 # TODO(maruel): HACK, remove me. | 187 num_issues_patchsets_to_apply = len(issues_patchsets_to_apply) |
199 # When run a build slave, make sure buildbot knows that the checkout was | 188 if num_issues_patchsets_to_apply > 1: |
200 # modified. | 189 print |
201 if options.root_dir == 'src' and getpass.getuser() == 'chrome-bot': | 190 print 'apply_issue.py found %d dependent CLs.' % ( |
202 # See sourcedirIsPatched() in: | 191 num_issues_patchsets_to_apply - 1) |
203 # http://src.chromium.org/viewvc/chrome/trunk/tools/build/scripts/slave/ | 192 print 'They will be applied in the following order:' |
204 # chromium_commands.py?view=markup | 193 num = 1 |
205 open('.buildbot-patched', 'w').close() | 194 for issue_to_apply, patchset_to_apply in issues_patchsets_to_apply: |
| 195 print ' #%d %s/%d/#ps%d' % ( |
| 196 num, options.server, issue_to_apply, patchset_to_apply) |
| 197 num += 1 |
| 198 print |
206 | 199 |
207 print('\nApplying the patch.') | 200 for issue_to_apply, patchset_to_apply in issues_patchsets_to_apply: |
208 try: | 201 issue_url = '%s/%d/#ps%d' % (options.server, issue_to_apply, |
209 scm_obj.apply_patch(patchset, verbose=True) | 202 patchset_to_apply) |
210 except checkout.PatchApplicationFailed as e: | 203 print('Downloading patch from %s' % issue_url) |
211 print(str(e)) | 204 try: |
212 print('CWD=%s' % os.getcwd()) | 205 patchset = obj.get_patch(issue_to_apply, patchset_to_apply) |
213 print('Checkout path=%s' % scm_obj.project_path) | 206 except urllib2.HTTPError as e: |
214 return 1 | 207 print( |
| 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 |
215 | 249 |
216 if ('DEPS' in map(os.path.basename, patchset.filenames) | 250 if ('DEPS' in map(os.path.basename, patchset.filenames) |
217 and not options.ignore_deps): | 251 and not options.ignore_deps): |
218 gclient_root = gclient_utils.FindGclientRoot(full_dir) | 252 gclient_root = gclient_utils.FindGclientRoot(full_dir) |
219 if gclient_root and scm_type: | 253 if gclient_root and scm_type: |
220 print( | 254 print( |
221 'A DEPS file was updated inside a gclient checkout, running gclient ' | 255 'A DEPS file was updated inside a gclient checkout, running gclient ' |
222 'sync.') | 256 'sync.') |
223 gclient_path = os.path.join(BASE_DIR, 'gclient') | 257 gclient_path = os.path.join(BASE_DIR, 'gclient') |
224 if sys.platform == 'win32': | 258 if sys.platform == 'win32': |
(...skipping 20 matching lines...) Expand all Loading... |
245 return 0 | 279 return 0 |
246 | 280 |
247 | 281 |
248 if __name__ == "__main__": | 282 if __name__ == "__main__": |
249 fix_encoding.fix_encoding() | 283 fix_encoding.fix_encoding() |
250 try: | 284 try: |
251 sys.exit(main()) | 285 sys.exit(main()) |
252 except KeyboardInterrupt: | 286 except KeyboardInterrupt: |
253 sys.stderr.write('interrupted\n') | 287 sys.stderr.write('interrupted\n') |
254 sys.exit(1) | 288 sys.exit(1) |
OLD | NEW |