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

Side by Side Diff: recipe_modules/bot_update/resources/bot_update.py

Issue 2310113003: Remove patch_url from bot_update. (Closed)
Patch Set: Created 4 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 | « recipe_modules/bot_update/example.expected/tryjob_v8.json ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 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 # TODO(hinoka): Use logging. 6 # TODO(hinoka): Use logging.
7 7
8 import cStringIO 8 import cStringIO
9 import codecs 9 import codecs
10 import collections 10 import collections
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 (line, diff)) 999 (line, diff))
1000 1000
1001 current_diff = '' 1001 current_diff = ''
1002 current_diff += '%s\n' % line 1002 current_diff += '%s\n' % line
1003 if current_header: 1003 if current_header:
1004 # We hit EOF, gotta save the last diff. 1004 # We hit EOF, gotta save the last diff.
1005 result.append((current_header, current_diff)) 1005 result.append((current_header, current_diff))
1006 return result 1006 return result
1007 1007
1008 1008
1009 def get_svn_patch(patch_url):
1010 """Fetch patch from patch_url, return list of (filename, diff)"""
1011 svn_exe = 'svn.bat' if sys.platform.startswith('win') else 'svn'
1012 patch_data = call(svn_exe, 'cat', patch_url)
1013 return parse_diff(patch_data)
1014
1015
1016 def apply_svn_patch(patch_root, patches, whitelist=None, blacklist=None):
1017 """Expects a list of (filename, diff), applies it on top of patch_root."""
1018 if whitelist:
1019 patches = [(name, diff) for name, diff in patches if name in whitelist]
1020 elif blacklist:
1021 patches = [(name, diff) for name, diff in patches if name not in blacklist]
1022 diffs = [diff for _, diff in patches]
1023 patch = ''.join(diffs)
1024
1025 if patch:
1026 print '===Patching files==='
1027 for filename, _ in patches:
1028 print 'Patching %s' % filename
1029 try:
1030 call(PATCH_TOOL, '-p0', '--remove-empty-files', '--force', '--forward',
1031 stdin_data=patch, cwd=patch_root, tries=1)
1032 for filename, _ in patches:
1033 full_filename = path.abspath(path.join(patch_root, filename))
1034 git('add', full_filename, cwd=path.dirname(full_filename))
1035 except SubprocessFailed as e:
1036 raise PatchFailed(e.message, e.code, e.output)
1037
1038 def apply_rietveld_issue(issue, patchset, root, server, _rev_map, _revision, 1009 def apply_rietveld_issue(issue, patchset, root, server, _rev_map, _revision,
1039 email_file, key_file, whitelist=None, blacklist=None): 1010 email_file, key_file, whitelist=None, blacklist=None):
1040 apply_issue_bin = ('apply_issue.bat' if sys.platform.startswith('win') 1011 apply_issue_bin = ('apply_issue.bat' if sys.platform.startswith('win')
1041 else 'apply_issue') 1012 else 'apply_issue')
1042 cmd = [apply_issue_bin, 1013 cmd = [apply_issue_bin,
1043 # The patch will be applied on top of this directory. 1014 # The patch will be applied on top of this directory.
1044 '--root_dir', root, 1015 '--root_dir', root,
1045 # Tell apply_issue how to fetch the patch. 1016 # Tell apply_issue how to fetch the patch.
1046 '--issue', issue, 1017 '--issue', issue,
1047 '--server', server, 1018 '--server', server,
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 revision = get_target_revision(deps_name, deps_data.get('url', None), 1229 revision = get_target_revision(deps_name, deps_data.get('url', None),
1259 revisions) 1230 revisions)
1260 if not revision: 1231 if not revision:
1261 continue 1232 continue
1262 # TODO(hinoka): Catch SVNRevisionNotFound error maybe? 1233 # TODO(hinoka): Catch SVNRevisionNotFound error maybe?
1263 git('fetch', 'origin', cwd=deps_name) 1234 git('fetch', 'origin', cwd=deps_name)
1264 force_revision(deps_name, revision) 1235 force_revision(deps_name, revision)
1265 1236
1266 1237
1267 def ensure_checkout(solutions, revisions, first_sln, target_os, target_os_only, 1238 def ensure_checkout(solutions, revisions, first_sln, target_os, target_os_only,
1268 patch_root, issue, patchset, patch_url, rietveld_server, 1239 patch_root, issue, patchset, rietveld_server,
1269 gerrit_repo, gerrit_ref, gerrit_rebase_patch_ref, 1240 gerrit_repo, gerrit_ref, gerrit_rebase_patch_ref,
1270 revision_mapping, apply_issue_email_file, 1241 revision_mapping, apply_issue_email_file,
1271 apply_issue_key_file, buildspec, gyp_env, shallow, runhooks, 1242 apply_issue_key_file, buildspec, gyp_env, shallow, runhooks,
1272 refs, git_cache_dir, gerrit_reset): 1243 refs, git_cache_dir, gerrit_reset):
1273 # Get a checkout of each solution, without DEPS or hooks. 1244 # Get a checkout of each solution, without DEPS or hooks.
1274 # Calling git directly because there is no way to run Gclient without 1245 # Calling git directly because there is no way to run Gclient without
1275 # invoking DEPS. 1246 # invoking DEPS.
1276 print 'Fetching Git checkout' 1247 print 'Fetching Git checkout'
1277 1248
1278 git_ref = git_checkout(solutions, revisions, shallow, refs, git_cache_dir) 1249 git_ref = git_checkout(solutions, revisions, shallow, refs, git_cache_dir)
1279 1250
1280 patches = None
1281 if patch_url:
1282 patches = get_svn_patch(patch_url)
1283
1284 print '===Processing patch solutions===' 1251 print '===Processing patch solutions==='
1285 already_patched = [] 1252 already_patched = []
1286 patch_root = patch_root or '' 1253 patch_root = patch_root or ''
1287 applied_gerrit_patch = False 1254 applied_gerrit_patch = False
1288 print 'Patch root is %r' % patch_root 1255 print 'Patch root is %r' % patch_root
1289 for solution in solutions: 1256 for solution in solutions:
1290 print 'Processing solution %r' % solution['name'] 1257 print 'Processing solution %r' % solution['name']
1291 if (patch_root == solution['name'] or 1258 if (patch_root == solution['name'] or
1292 solution['name'].startswith(patch_root + '/')): 1259 solution['name'].startswith(patch_root + '/')):
1293 relative_root = solution['name'][len(patch_root) + 1:] 1260 relative_root = solution['name'][len(patch_root) + 1:]
1294 target = '/'.join([relative_root, 'DEPS']).lstrip('/') 1261 target = '/'.join([relative_root, 'DEPS']).lstrip('/')
1295 print ' relative root is %r, target is %r' % (relative_root, target) 1262 print ' relative root is %r, target is %r' % (relative_root, target)
1296 if patches: 1263 if issue:
1297 apply_svn_patch(patch_root, patches, whitelist=[target])
1298 already_patched.append(target)
1299 elif issue:
1300 apply_rietveld_issue(issue, patchset, patch_root, rietveld_server, 1264 apply_rietveld_issue(issue, patchset, patch_root, rietveld_server,
1301 revision_mapping, git_ref, apply_issue_email_file, 1265 revision_mapping, git_ref, apply_issue_email_file,
1302 apply_issue_key_file, whitelist=[target]) 1266 apply_issue_key_file, whitelist=[target])
1303 already_patched.append(target) 1267 already_patched.append(target)
1304 elif gerrit_ref: 1268 elif gerrit_ref:
1305 apply_gerrit_ref(gerrit_repo, gerrit_ref, patch_root, gerrit_reset, 1269 apply_gerrit_ref(gerrit_repo, gerrit_ref, patch_root, gerrit_reset,
1306 gerrit_rebase_patch_ref) 1270 gerrit_rebase_patch_ref)
1307 applied_gerrit_patch = True 1271 applied_gerrit_patch = True
1308 1272
1309 # Ensure our build/ directory is set up with the correct .gclient file. 1273 # Ensure our build/ directory is set up with the correct .gclient file.
(...skipping 15 matching lines...) Expand all
1325 # Run gclient runhooks if we're on an official builder. 1289 # Run gclient runhooks if we're on an official builder.
1326 # TODO(hinoka): Remove this when the official builders run their own 1290 # TODO(hinoka): Remove this when the official builders run their own
1327 # runhooks step. 1291 # runhooks step.
1328 gclient_runhooks(gyp_env) 1292 gclient_runhooks(gyp_env)
1329 1293
1330 # Finally, ensure that all DEPS are pinned to the correct revision. 1294 # Finally, ensure that all DEPS are pinned to the correct revision.
1331 dir_names = [sln['name'] for sln in solutions] 1295 dir_names = [sln['name'] for sln in solutions]
1332 ensure_deps_revisions(gclient_output.get('solutions', {}), 1296 ensure_deps_revisions(gclient_output.get('solutions', {}),
1333 dir_names, revisions) 1297 dir_names, revisions)
1334 # Apply the rest of the patch here (sans DEPS) 1298 # Apply the rest of the patch here (sans DEPS)
1335 if patches: 1299 if issue:
1336 apply_svn_patch(patch_root, patches, blacklist=already_patched)
1337 elif issue:
1338 apply_rietveld_issue(issue, patchset, patch_root, rietveld_server, 1300 apply_rietveld_issue(issue, patchset, patch_root, rietveld_server,
1339 revision_mapping, git_ref, apply_issue_email_file, 1301 revision_mapping, git_ref, apply_issue_email_file,
1340 apply_issue_key_file, blacklist=already_patched) 1302 apply_issue_key_file, blacklist=already_patched)
1341 elif gerrit_ref and not applied_gerrit_patch: 1303 elif gerrit_ref and not applied_gerrit_patch:
1342 # If gerrit_ref was for solution's main repository, it has already been 1304 # If gerrit_ref was for solution's main repository, it has already been
1343 # applied above. This chunk is executed only for patches to DEPS-ed in 1305 # applied above. This chunk is executed only for patches to DEPS-ed in
1344 # git repositories. 1306 # git repositories.
1345 apply_gerrit_ref(gerrit_repo, gerrit_ref, patch_root, gerrit_reset, 1307 apply_gerrit_ref(gerrit_repo, gerrit_ref, patch_root, gerrit_reset,
1346 gerrit_rebase_patch_ref) 1308 gerrit_rebase_patch_ref)
1347 1309
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 parse = optparse.OptionParser() 1367 parse = optparse.OptionParser()
1406 1368
1407 parse.add_option('--issue', help='Issue number to patch from.') 1369 parse.add_option('--issue', help='Issue number to patch from.')
1408 parse.add_option('--patchset', 1370 parse.add_option('--patchset',
1409 help='Patchset from issue to patch from, if applicable.') 1371 help='Patchset from issue to patch from, if applicable.')
1410 parse.add_option('--apply_issue_email_file', 1372 parse.add_option('--apply_issue_email_file',
1411 help='--email-file option passthrough for apply_patch.py.') 1373 help='--email-file option passthrough for apply_patch.py.')
1412 parse.add_option('--apply_issue_key_file', 1374 parse.add_option('--apply_issue_key_file',
1413 help='--private-key-file option passthrough for ' 1375 help='--private-key-file option passthrough for '
1414 'apply_patch.py.') 1376 'apply_patch.py.')
1415 parse.add_option('--patch_url', help='Optional URL to SVN patch.')
1416 parse.add_option('--root', dest='patch_root', 1377 parse.add_option('--root', dest='patch_root',
1417 help='DEPRECATED: Use --patch_root.') 1378 help='DEPRECATED: Use --patch_root.')
1418 parse.add_option('--patch_root', help='Directory to patch on top of.') 1379 parse.add_option('--patch_root', help='Directory to patch on top of.')
1419 parse.add_option('--rietveld_server', 1380 parse.add_option('--rietveld_server',
1420 default='codereview.chromium.org', 1381 default='codereview.chromium.org',
1421 help='Rietveld server.') 1382 help='Rietveld server.')
1422 parse.add_option('--gerrit_repo', 1383 parse.add_option('--gerrit_repo',
1423 help='Gerrit repository to pull the ref from.') 1384 help='Gerrit repository to pull the ref from.')
1424 parse.add_option('--gerrit_ref', help='Gerrit ref to apply.') 1385 parse.add_option('--gerrit_ref', help='Gerrit ref to apply.')
1425 parse.add_option('--gerrit_no_rebase_patch_ref', action='store_true', 1386 parse.add_option('--gerrit_no_rebase_patch_ref', action='store_true',
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1574 first_sln=first_sln, 1535 first_sln=first_sln,
1575 1536
1576 # Also, target os variables for gclient. 1537 # Also, target os variables for gclient.
1577 target_os=specs.get('target_os', []), 1538 target_os=specs.get('target_os', []),
1578 target_os_only=specs.get('target_os_only', False), 1539 target_os_only=specs.get('target_os_only', False),
1579 1540
1580 # Then, pass in information about how to patch. 1541 # Then, pass in information about how to patch.
1581 patch_root=options.patch_root, 1542 patch_root=options.patch_root,
1582 issue=options.issue, 1543 issue=options.issue,
1583 patchset=options.patchset, 1544 patchset=options.patchset,
1584 patch_url=options.patch_url,
1585 rietveld_server=options.rietveld_server, 1545 rietveld_server=options.rietveld_server,
1586 gerrit_repo=options.gerrit_repo, 1546 gerrit_repo=options.gerrit_repo,
1587 gerrit_ref=options.gerrit_ref, 1547 gerrit_ref=options.gerrit_ref,
1588 gerrit_rebase_patch_ref=not options.gerrit_no_rebase_patch_ref, 1548 gerrit_rebase_patch_ref=not options.gerrit_no_rebase_patch_ref,
1589 revision_mapping=options.revision_mapping, 1549 revision_mapping=options.revision_mapping,
1590 apply_issue_email_file=options.apply_issue_email_file, 1550 apply_issue_email_file=options.apply_issue_email_file,
1591 apply_issue_key_file=options.apply_issue_key_file, 1551 apply_issue_key_file=options.apply_issue_key_file,
1592 1552
1593 # For official builders. 1553 # For official builders.
1594 buildspec=buildspec, 1554 buildspec=buildspec,
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1742 except Exception: 1702 except Exception:
1743 # Unexpected failure. 1703 # Unexpected failure.
1744 emit_flag(options.flag_file) 1704 emit_flag(options.flag_file)
1745 raise 1705 raise
1746 else: 1706 else:
1747 emit_flag(options.flag_file) 1707 emit_flag(options.flag_file)
1748 1708
1749 1709
1750 if __name__ == '__main__': 1710 if __name__ == '__main__':
1751 sys.exit(main()) 1711 sys.exit(main())
OLDNEW
« no previous file with comments | « recipe_modules/bot_update/example.expected/tryjob_v8.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698