OLD | NEW |
---|---|
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 1112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1123 elif blacklist: | 1123 elif blacklist: |
1124 for item in blacklist: | 1124 for item in blacklist: |
1125 cmd.extend(['--blacklist', item]) | 1125 cmd.extend(['--blacklist', item]) |
1126 | 1126 |
1127 # Only try once, since subsequent failures hide the real failure. | 1127 # Only try once, since subsequent failures hide the real failure. |
1128 try: | 1128 try: |
1129 call(*cmd, tries=1) | 1129 call(*cmd, tries=1) |
1130 except SubprocessFailed as e: | 1130 except SubprocessFailed as e: |
1131 raise PatchFailed(e.message, e.code, e.output) | 1131 raise PatchFailed(e.message, e.code, e.output) |
1132 | 1132 |
1133 def apply_gerrit_ref(gerrit_repo, gerrit_ref, root): | 1133 def apply_gerrit_ref(gerrit_repo, gerrit_ref, root, reset_soft): |
1134 gerrit_repo = gerrit_repo or 'origin' | 1134 gerrit_repo = gerrit_repo or 'origin' |
1135 assert gerrit_ref | 1135 assert gerrit_ref |
1136 try: | 1136 try: |
1137 base_rev = git('rev-parse', 'HEAD', cwd=root).strip() | 1137 base_rev = git('rev-parse', 'HEAD', cwd=root).strip() |
1138 git('retry', 'fetch', gerrit_repo, gerrit_ref, cwd=root, tries=1) | 1138 git('retry', 'fetch', gerrit_repo, gerrit_ref, cwd=root, tries=1) |
1139 git('checkout', 'FETCH_HEAD', cwd=root) | 1139 git('checkout', 'FETCH_HEAD', cwd=root) |
1140 git('reset', '--soft', base_rev, cwd=root) | 1140 if not reset_soft: |
hinoka
2016/03/25 12:48:17
if reset_soft:
Yoshisato Yanagisawa
2016/03/28 02:00:52
good catch ;p
| |
1141 git('reset', '--soft', base_rev, cwd=root) | |
1141 except SubprocessFailed as e: | 1142 except SubprocessFailed as e: |
1142 raise PatchFailed(e.message, e.code, e.output) | 1143 raise PatchFailed(e.message, e.code, e.output) |
1143 | 1144 |
1144 def check_flag(flag_file): | 1145 def check_flag(flag_file): |
1145 """Returns True if the flag file is present.""" | 1146 """Returns True if the flag file is present.""" |
1146 return os.path.isfile(flag_file) | 1147 return os.path.isfile(flag_file) |
1147 | 1148 |
1148 | 1149 |
1149 def delete_flag(flag_file): | 1150 def delete_flag(flag_file): |
1150 """Remove bot update flag.""" | 1151 """Remove bot update flag.""" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1288 continue | 1289 continue |
1289 # TODO(hinoka): Catch SVNRevisionNotFound error maybe? | 1290 # TODO(hinoka): Catch SVNRevisionNotFound error maybe? |
1290 git('fetch', 'origin', cwd=deps_name) | 1291 git('fetch', 'origin', cwd=deps_name) |
1291 force_revision(deps_name, revision) | 1292 force_revision(deps_name, revision) |
1292 | 1293 |
1293 | 1294 |
1294 def ensure_checkout(solutions, revisions, first_sln, target_os, target_os_only, | 1295 def ensure_checkout(solutions, revisions, first_sln, target_os, target_os_only, |
1295 patch_root, issue, patchset, patch_url, rietveld_server, | 1296 patch_root, issue, patchset, patch_url, rietveld_server, |
1296 gerrit_repo, gerrit_ref, revision_mapping, | 1297 gerrit_repo, gerrit_ref, revision_mapping, |
1297 apply_issue_email_file, apply_issue_key_file, buildspec, | 1298 apply_issue_email_file, apply_issue_key_file, buildspec, |
1298 gyp_env, shallow, runhooks, refs, git_cache_dir): | 1299 gyp_env, shallow, runhooks, refs, git_cache_dir, |
1300 reset_soft): | |
1299 # Get a checkout of each solution, without DEPS or hooks. | 1301 # Get a checkout of each solution, without DEPS or hooks. |
1300 # Calling git directly because there is no way to run Gclient without | 1302 # Calling git directly because there is no way to run Gclient without |
1301 # invoking DEPS. | 1303 # invoking DEPS. |
1302 print 'Fetching Git checkout' | 1304 print 'Fetching Git checkout' |
1303 | 1305 |
1304 git_ref = git_checkout(solutions, revisions, shallow, refs, git_cache_dir) | 1306 git_ref = git_checkout(solutions, revisions, shallow, refs, git_cache_dir) |
1305 | 1307 |
1306 patches = None | 1308 patches = None |
1307 if patch_url: | 1309 if patch_url: |
1308 patches = get_svn_patch(patch_url) | 1310 patches = get_svn_patch(patch_url) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1354 ensure_deps_revisions(gclient_output.get('solutions', {}), | 1356 ensure_deps_revisions(gclient_output.get('solutions', {}), |
1355 dir_names, revisions) | 1357 dir_names, revisions) |
1356 # Apply the rest of the patch here (sans DEPS) | 1358 # Apply the rest of the patch here (sans DEPS) |
1357 if patches: | 1359 if patches: |
1358 apply_svn_patch(patch_root, patches, blacklist=already_patched) | 1360 apply_svn_patch(patch_root, patches, blacklist=already_patched) |
1359 elif issue: | 1361 elif issue: |
1360 apply_rietveld_issue(issue, patchset, patch_root, rietveld_server, | 1362 apply_rietveld_issue(issue, patchset, patch_root, rietveld_server, |
1361 revision_mapping, git_ref, apply_issue_email_file, | 1363 revision_mapping, git_ref, apply_issue_email_file, |
1362 apply_issue_key_file, blacklist=already_patched) | 1364 apply_issue_key_file, blacklist=already_patched) |
1363 elif gerrit_ref: | 1365 elif gerrit_ref: |
1364 apply_gerrit_ref(gerrit_repo, gerrit_ref, patch_root) | 1366 apply_gerrit_ref(gerrit_repo, gerrit_ref, patch_root, reset_soft) |
1365 | 1367 |
1366 # Reset the deps_file point in the solutions so that hooks get run properly. | 1368 # Reset the deps_file point in the solutions so that hooks get run properly. |
1367 for sln in solutions: | 1369 for sln in solutions: |
1368 sln['deps_file'] = sln.get('deps_file', 'DEPS').replace('.DEPS.git', 'DEPS') | 1370 sln['deps_file'] = sln.get('deps_file', 'DEPS').replace('.DEPS.git', 'DEPS') |
1369 gclient_configure(solutions, target_os, target_os_only, git_cache_dir) | 1371 gclient_configure(solutions, target_os, target_os_only, git_cache_dir) |
1370 | 1372 |
1371 return gclient_output | 1373 return gclient_output |
1372 | 1374 |
1373 | 1375 |
1374 def parse_revisions(revisions, root): | 1376 def parse_revisions(revisions, root): |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1484 parse.add_option('--no_runhooks', action='store_true', | 1486 parse.add_option('--no_runhooks', action='store_true', |
1485 help='Do not run hooks on official builder.') | 1487 help='Do not run hooks on official builder.') |
1486 parse.add_option('--refs', action='append', | 1488 parse.add_option('--refs', action='append', |
1487 help='Also fetch this refspec for the main solution(s). ' | 1489 help='Also fetch this refspec for the main solution(s). ' |
1488 'Eg. +refs/branch-heads/*') | 1490 'Eg. +refs/branch-heads/*') |
1489 parse.add_option('--with_branch_heads', action='store_true', | 1491 parse.add_option('--with_branch_heads', action='store_true', |
1490 help='Always pass --with_branch_heads to gclient. This ' | 1492 help='Always pass --with_branch_heads to gclient. This ' |
1491 'does the same thing as --refs +refs/branch-heads/*') | 1493 'does the same thing as --refs +refs/branch-heads/*') |
1492 parse.add_option('--git-cache-dir', default=path.join(SLAVE_DIR, 'cache_dir'), | 1494 parse.add_option('--git-cache-dir', default=path.join(SLAVE_DIR, 'cache_dir'), |
1493 help='Path to git cache directory.') | 1495 help='Path to git cache directory.') |
1496 parse.add_option('--no_reset_soft', action='store_true', | |
1497 help='Bypass calling reset --soft after git fetch.') | |
hinoka
2016/03/25 12:48:17
I think the name "--gerrit_no_reset" is better, si
Yoshisato Yanagisawa
2016/03/28 02:00:52
Done.
| |
1494 | 1498 |
1495 | 1499 |
1496 options, args = parse.parse_args() | 1500 options, args = parse.parse_args() |
1497 | 1501 |
1498 if not options.refs: | 1502 if not options.refs: |
1499 options.refs = [] | 1503 options.refs = [] |
1500 | 1504 |
1501 if options.with_branch_heads: | 1505 if options.with_branch_heads: |
1502 options.refs.append(BRANCH_HEADS_REFSPEC) | 1506 options.refs.append(BRANCH_HEADS_REFSPEC) |
1503 del options.with_branch_heads | 1507 del options.with_branch_heads |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1602 apply_issue_key_file=options.apply_issue_key_file, | 1606 apply_issue_key_file=options.apply_issue_key_file, |
1603 | 1607 |
1604 # For official builders. | 1608 # For official builders. |
1605 buildspec=buildspec, | 1609 buildspec=buildspec, |
1606 gyp_env=options.gyp_env, | 1610 gyp_env=options.gyp_env, |
1607 runhooks=not options.no_runhooks, | 1611 runhooks=not options.no_runhooks, |
1608 | 1612 |
1609 # Finally, extra configurations such as shallowness of the clone. | 1613 # Finally, extra configurations such as shallowness of the clone. |
1610 shallow=options.shallow, | 1614 shallow=options.shallow, |
1611 refs=options.refs, | 1615 refs=options.refs, |
1612 git_cache_dir=options.git_cache_dir) | 1616 git_cache_dir=options.git_cache_dir, |
1617 reset_soft=not options.no_reset_soft) | |
1613 gclient_output = ensure_checkout(**checkout_parameters) | 1618 gclient_output = ensure_checkout(**checkout_parameters) |
1614 except GclientSyncFailed: | 1619 except GclientSyncFailed: |
1615 print 'We failed gclient sync, lets delete the checkout and retry.' | 1620 print 'We failed gclient sync, lets delete the checkout and retry.' |
1616 ensure_no_checkout(dir_names, '*') | 1621 ensure_no_checkout(dir_names, '*') |
1617 gclient_output = ensure_checkout(**checkout_parameters) | 1622 gclient_output = ensure_checkout(**checkout_parameters) |
1618 except PatchFailed as e: | 1623 except PatchFailed as e: |
1619 if options.output_json: | 1624 if options.output_json: |
1620 # Tell recipes information such as root, got_revision, etc. | 1625 # Tell recipes information such as root, got_revision, etc. |
1621 emit_json(options.output_json, | 1626 emit_json(options.output_json, |
1622 did_run=True, | 1627 did_run=True, |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1748 except Exception: | 1753 except Exception: |
1749 # Unexpected failure. | 1754 # Unexpected failure. |
1750 emit_flag(options.flag_file) | 1755 emit_flag(options.flag_file) |
1751 raise | 1756 raise |
1752 else: | 1757 else: |
1753 emit_flag(options.flag_file) | 1758 emit_flag(options.flag_file) |
1754 | 1759 |
1755 | 1760 |
1756 if __name__ == '__main__': | 1761 if __name__ == '__main__': |
1757 sys.exit(main()) | 1762 sys.exit(main()) |
OLD | NEW |