| 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, gerrit_reset): |
| 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 gerrit_reset: |
| 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 gerrit_reset): |
| 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, gerrit_reset) |
| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1433 parse.add_option('--patch_url', help='Optional URL to SVN patch.') | 1435 parse.add_option('--patch_url', help='Optional URL to SVN patch.') |
| 1434 parse.add_option('--root', dest='patch_root', | 1436 parse.add_option('--root', dest='patch_root', |
| 1435 help='DEPRECATED: Use --patch_root.') | 1437 help='DEPRECATED: Use --patch_root.') |
| 1436 parse.add_option('--patch_root', help='Directory to patch on top of.') | 1438 parse.add_option('--patch_root', help='Directory to patch on top of.') |
| 1437 parse.add_option('--rietveld_server', | 1439 parse.add_option('--rietveld_server', |
| 1438 default='codereview.chromium.org', | 1440 default='codereview.chromium.org', |
| 1439 help='Rietveld server.') | 1441 help='Rietveld server.') |
| 1440 parse.add_option('--gerrit_repo', | 1442 parse.add_option('--gerrit_repo', |
| 1441 help='Gerrit repository to pull the ref from.') | 1443 help='Gerrit repository to pull the ref from.') |
| 1442 parse.add_option('--gerrit_ref', help='Gerrit ref to apply.') | 1444 parse.add_option('--gerrit_ref', help='Gerrit ref to apply.') |
| 1445 parse.add_option('--gerrit_no_reset', action='store_true', |
| 1446 help='Bypass calling reset after applying a gerrit ref.') |
| 1443 parse.add_option('--specs', help='Gcilent spec.') | 1447 parse.add_option('--specs', help='Gcilent spec.') |
| 1444 parse.add_option('--master', help='Master name.') | 1448 parse.add_option('--master', help='Master name.') |
| 1445 parse.add_option('-f', '--force', action='store_true', | 1449 parse.add_option('-f', '--force', action='store_true', |
| 1446 help='Bypass check to see if we want to be run. ' | 1450 help='Bypass check to see if we want to be run. ' |
| 1447 'Should ONLY be used locally or by smart recipes.') | 1451 'Should ONLY be used locally or by smart recipes.') |
| 1448 parse.add_option('--revision_mapping', | 1452 parse.add_option('--revision_mapping', |
| 1449 help='{"path/to/repo/": "property_name"}') | 1453 help='{"path/to/repo/": "property_name"}') |
| 1450 parse.add_option('--revision_mapping_file', | 1454 parse.add_option('--revision_mapping_file', |
| 1451 help=('Same as revision_mapping, except its a path to a json' | 1455 help=('Same as revision_mapping, except its a path to a json' |
| 1452 ' file containing that format.')) | 1456 ' file containing that format.')) |
| (...skipping 149 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 gerrit_reset=not options.gerrit_no_reset) |
| 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 |