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 copy | 10 import copy |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 """Fetch url and return content, with retries for flake.""" | 548 """Fetch url and return content, with retries for flake.""" |
549 for attempt in xrange(ATTEMPTS): | 549 for attempt in xrange(ATTEMPTS): |
550 try: | 550 try: |
551 return urllib2.urlopen(url).read() | 551 return urllib2.urlopen(url).read() |
552 except Exception: | 552 except Exception: |
553 if attempt == ATTEMPTS - 1: | 553 if attempt == ATTEMPTS - 1: |
554 raise | 554 raise |
555 | 555 |
556 | 556 |
557 def apply_rietveld_issue(issue, patchset, root, server, _rev_map, _revision, | 557 def apply_rietveld_issue(issue, patchset, root, server, _rev_map, _revision, |
558 email_file, key_file, whitelist=None, blacklist=None): | 558 email_file, key_file, oauth2_file, |
| 559 whitelist=None, blacklist=None): |
559 apply_issue_bin = ('apply_issue.bat' if sys.platform.startswith('win') | 560 apply_issue_bin = ('apply_issue.bat' if sys.platform.startswith('win') |
560 else 'apply_issue') | 561 else 'apply_issue') |
561 cmd = [apply_issue_bin, | 562 cmd = [apply_issue_bin, |
562 # The patch will be applied on top of this directory. | 563 # The patch will be applied on top of this directory. |
563 '--root_dir', root, | 564 '--root_dir', root, |
564 # Tell apply_issue how to fetch the patch. | 565 # Tell apply_issue how to fetch the patch. |
565 '--issue', issue, | 566 '--issue', issue, |
566 '--server', server, | 567 '--server', server, |
567 # Always run apply_issue.py, otherwise it would see update.flag | 568 # Always run apply_issue.py, otherwise it would see update.flag |
568 # and then bail out. | 569 # and then bail out. |
569 '--force', | 570 '--force', |
570 # Don't run gclient sync when it sees a DEPS change. | 571 # Don't run gclient sync when it sees a DEPS change. |
571 '--ignore_deps', | 572 '--ignore_deps', |
572 ] | 573 ] |
573 # Use an oauth key file if specified. | 574 # Use an oauth key or json file if specified. |
574 if email_file and key_file: | 575 if oauth2_file: |
| 576 cmd.extend(['--auth-refresh-token-json', oauth2_file]) |
| 577 elif email_file and key_file: |
575 cmd.extend(['--email-file', email_file, '--private-key-file', key_file]) | 578 cmd.extend(['--email-file', email_file, '--private-key-file', key_file]) |
576 else: | 579 else: |
577 cmd.append('--no-auth') | 580 cmd.append('--no-auth') |
578 | 581 |
579 if patchset: | 582 if patchset: |
580 cmd.extend(['--patchset', patchset]) | 583 cmd.extend(['--patchset', patchset]) |
581 if whitelist: | 584 if whitelist: |
582 for item in whitelist: | 585 for item in whitelist: |
583 cmd.extend(['--whitelist', item]) | 586 cmd.extend(['--whitelist', item]) |
584 elif blacklist: | 587 elif blacklist: |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 revisions) | 710 revisions) |
708 if not revision: | 711 if not revision: |
709 continue | 712 continue |
710 git('fetch', 'origin', cwd=deps_name) | 713 git('fetch', 'origin', cwd=deps_name) |
711 force_revision(deps_name, revision) | 714 force_revision(deps_name, revision) |
712 | 715 |
713 | 716 |
714 def ensure_checkout(solutions, revisions, first_sln, target_os, target_os_only, | 717 def ensure_checkout(solutions, revisions, first_sln, target_os, target_os_only, |
715 patch_root, issue, patchset, rietveld_server, gerrit_repo, | 718 patch_root, issue, patchset, rietveld_server, gerrit_repo, |
716 gerrit_ref, gerrit_rebase_patch_ref, revision_mapping, | 719 gerrit_ref, gerrit_rebase_patch_ref, revision_mapping, |
717 apply_issue_email_file, apply_issue_key_file, shallow, refs, | 720 apply_issue_email_file, apply_issue_key_file, |
718 git_cache_dir, gerrit_reset): | 721 apply_issue_oauth2_file, shallow, refs, git_cache_dir, |
| 722 gerrit_reset): |
719 # Get a checkout of each solution, without DEPS or hooks. | 723 # Get a checkout of each solution, without DEPS or hooks. |
720 # Calling git directly because there is no way to run Gclient without | 724 # Calling git directly because there is no way to run Gclient without |
721 # invoking DEPS. | 725 # invoking DEPS. |
722 print 'Fetching Git checkout' | 726 print 'Fetching Git checkout' |
723 | 727 |
724 git_ref = git_checkout(solutions, revisions, shallow, refs, git_cache_dir) | 728 git_ref = git_checkout(solutions, revisions, shallow, refs, git_cache_dir) |
725 | 729 |
726 print '===Processing patch solutions===' | 730 print '===Processing patch solutions===' |
727 already_patched = [] | 731 already_patched = [] |
728 patch_root = patch_root or '' | 732 patch_root = patch_root or '' |
729 applied_gerrit_patch = False | 733 applied_gerrit_patch = False |
730 print 'Patch root is %r' % patch_root | 734 print 'Patch root is %r' % patch_root |
731 for solution in solutions: | 735 for solution in solutions: |
732 print 'Processing solution %r' % solution['name'] | 736 print 'Processing solution %r' % solution['name'] |
733 if (patch_root == solution['name'] or | 737 if (patch_root == solution['name'] or |
734 solution['name'].startswith(patch_root + '/')): | 738 solution['name'].startswith(patch_root + '/')): |
735 relative_root = solution['name'][len(patch_root) + 1:] | 739 relative_root = solution['name'][len(patch_root) + 1:] |
736 target = '/'.join([relative_root, 'DEPS']).lstrip('/') | 740 target = '/'.join([relative_root, 'DEPS']).lstrip('/') |
737 print ' relative root is %r, target is %r' % (relative_root, target) | 741 print ' relative root is %r, target is %r' % (relative_root, target) |
738 if issue: | 742 if issue: |
739 apply_rietveld_issue(issue, patchset, patch_root, rietveld_server, | 743 apply_rietveld_issue(issue, patchset, patch_root, rietveld_server, |
740 revision_mapping, git_ref, apply_issue_email_file, | 744 revision_mapping, git_ref, apply_issue_email_file, |
741 apply_issue_key_file, whitelist=[target]) | 745 apply_issue_key_file, apply_issue_oauth2_file, |
| 746 whitelist=[target]) |
742 already_patched.append(target) | 747 already_patched.append(target) |
743 elif gerrit_ref: | 748 elif gerrit_ref: |
744 apply_gerrit_ref(gerrit_repo, gerrit_ref, patch_root, gerrit_reset, | 749 apply_gerrit_ref(gerrit_repo, gerrit_ref, patch_root, gerrit_reset, |
745 gerrit_rebase_patch_ref) | 750 gerrit_rebase_patch_ref) |
746 applied_gerrit_patch = True | 751 applied_gerrit_patch = True |
747 | 752 |
748 # Ensure our build/ directory is set up with the correct .gclient file. | 753 # Ensure our build/ directory is set up with the correct .gclient file. |
749 gclient_configure(solutions, target_os, target_os_only, git_cache_dir) | 754 gclient_configure(solutions, target_os, target_os_only, git_cache_dir) |
750 | 755 |
751 # Let gclient do the DEPS syncing. | 756 # Let gclient do the DEPS syncing. |
752 # The branch-head refspec is a special case because its possible Chrome | 757 # The branch-head refspec is a special case because its possible Chrome |
753 # src, which contains the branch-head refspecs, is DEPSed in. | 758 # src, which contains the branch-head refspecs, is DEPSed in. |
754 gclient_output = gclient_sync(BRANCH_HEADS_REFSPEC in refs, shallow) | 759 gclient_output = gclient_sync(BRANCH_HEADS_REFSPEC in refs, shallow) |
755 | 760 |
756 # Now that gclient_sync has finished, we should revert any .DEPS.git so that | 761 # Now that gclient_sync has finished, we should revert any .DEPS.git so that |
757 # presubmit doesn't complain about it being modified. | 762 # presubmit doesn't complain about it being modified. |
758 if git('ls-files', '.DEPS.git', cwd=first_sln).strip(): | 763 if git('ls-files', '.DEPS.git', cwd=first_sln).strip(): |
759 git('checkout', 'HEAD', '--', '.DEPS.git', cwd=first_sln) | 764 git('checkout', 'HEAD', '--', '.DEPS.git', cwd=first_sln) |
760 | 765 |
761 # Finally, ensure that all DEPS are pinned to the correct revision. | 766 # Finally, ensure that all DEPS are pinned to the correct revision. |
762 dir_names = [sln['name'] for sln in solutions] | 767 dir_names = [sln['name'] for sln in solutions] |
763 ensure_deps_revisions(gclient_output.get('solutions', {}), | 768 ensure_deps_revisions(gclient_output.get('solutions', {}), |
764 dir_names, revisions) | 769 dir_names, revisions) |
765 # Apply the rest of the patch here (sans DEPS) | 770 # Apply the rest of the patch here (sans DEPS) |
766 if issue: | 771 if issue: |
767 apply_rietveld_issue(issue, patchset, patch_root, rietveld_server, | 772 apply_rietveld_issue(issue, patchset, patch_root, rietveld_server, |
768 revision_mapping, git_ref, apply_issue_email_file, | 773 revision_mapping, apply_issue_oauth2_file, git_ref, |
769 apply_issue_key_file, blacklist=already_patched) | 774 apply_issue_email_file, apply_issue_key_file, |
| 775 blacklist=already_patched) |
770 elif gerrit_ref and not applied_gerrit_patch: | 776 elif gerrit_ref and not applied_gerrit_patch: |
771 # If gerrit_ref was for solution's main repository, it has already been | 777 # If gerrit_ref was for solution's main repository, it has already been |
772 # applied above. This chunk is executed only for patches to DEPS-ed in | 778 # applied above. This chunk is executed only for patches to DEPS-ed in |
773 # git repositories. | 779 # git repositories. |
774 apply_gerrit_ref(gerrit_repo, gerrit_ref, patch_root, gerrit_reset, | 780 apply_gerrit_ref(gerrit_repo, gerrit_ref, patch_root, gerrit_reset, |
775 gerrit_rebase_patch_ref) | 781 gerrit_rebase_patch_ref) |
776 | 782 |
777 # Reset the deps_file point in the solutions so that hooks get run properly. | 783 # Reset the deps_file point in the solutions so that hooks get run properly. |
778 for sln in solutions: | 784 for sln in solutions: |
779 sln['deps_file'] = sln.get('deps_file', 'DEPS').replace('.DEPS.git', 'DEPS') | 785 sln['deps_file'] = sln.get('deps_file', 'DEPS').replace('.DEPS.git', 'DEPS') |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 parse = optparse.OptionParser() | 834 parse = optparse.OptionParser() |
829 | 835 |
830 parse.add_option('--issue', help='Issue number to patch from.') | 836 parse.add_option('--issue', help='Issue number to patch from.') |
831 parse.add_option('--patchset', | 837 parse.add_option('--patchset', |
832 help='Patchset from issue to patch from, if applicable.') | 838 help='Patchset from issue to patch from, if applicable.') |
833 parse.add_option('--apply_issue_email_file', | 839 parse.add_option('--apply_issue_email_file', |
834 help='--email-file option passthrough for apply_patch.py.') | 840 help='--email-file option passthrough for apply_patch.py.') |
835 parse.add_option('--apply_issue_key_file', | 841 parse.add_option('--apply_issue_key_file', |
836 help='--private-key-file option passthrough for ' | 842 help='--private-key-file option passthrough for ' |
837 'apply_patch.py.') | 843 'apply_patch.py.') |
| 844 parse.add_option('--apply_issue_oauth2_file', |
| 845 help='--auth-refresh-token-json option passthrough for ' |
| 846 'apply_patch.py.') |
838 parse.add_option('--root', dest='patch_root', | 847 parse.add_option('--root', dest='patch_root', |
839 help='DEPRECATED: Use --patch_root.') | 848 help='DEPRECATED: Use --patch_root.') |
840 parse.add_option('--patch_root', help='Directory to patch on top of.') | 849 parse.add_option('--patch_root', help='Directory to patch on top of.') |
841 parse.add_option('--rietveld_server', | 850 parse.add_option('--rietveld_server', |
842 default='codereview.chromium.org', | 851 default='codereview.chromium.org', |
843 help='Rietveld server.') | 852 help='Rietveld server.') |
844 parse.add_option('--gerrit_repo', | 853 parse.add_option('--gerrit_repo', |
845 help='Gerrit repository to pull the ref from.') | 854 help='Gerrit repository to pull the ref from.') |
846 parse.add_option('--gerrit_ref', help='Gerrit ref to apply.') | 855 parse.add_option('--gerrit_ref', help='Gerrit ref to apply.') |
847 parse.add_option('--gerrit_no_rebase_patch_ref', action='store_true', | 856 parse.add_option('--gerrit_no_rebase_patch_ref', action='store_true', |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
965 patch_root=options.patch_root, | 974 patch_root=options.patch_root, |
966 issue=options.issue, | 975 issue=options.issue, |
967 patchset=options.patchset, | 976 patchset=options.patchset, |
968 rietveld_server=options.rietveld_server, | 977 rietveld_server=options.rietveld_server, |
969 gerrit_repo=options.gerrit_repo, | 978 gerrit_repo=options.gerrit_repo, |
970 gerrit_ref=options.gerrit_ref, | 979 gerrit_ref=options.gerrit_ref, |
971 gerrit_rebase_patch_ref=not options.gerrit_no_rebase_patch_ref, | 980 gerrit_rebase_patch_ref=not options.gerrit_no_rebase_patch_ref, |
972 revision_mapping=options.revision_mapping, | 981 revision_mapping=options.revision_mapping, |
973 apply_issue_email_file=options.apply_issue_email_file, | 982 apply_issue_email_file=options.apply_issue_email_file, |
974 apply_issue_key_file=options.apply_issue_key_file, | 983 apply_issue_key_file=options.apply_issue_key_file, |
| 984 apply_issue_oauth2_file=options.apply_issue_oauth2_file, |
975 | 985 |
976 # Finally, extra configurations such as shallowness of the clone. | 986 # Finally, extra configurations such as shallowness of the clone. |
977 shallow=shallow, | 987 shallow=shallow, |
978 refs=options.refs, | 988 refs=options.refs, |
979 git_cache_dir=options.git_cache_dir, | 989 git_cache_dir=options.git_cache_dir, |
980 gerrit_reset=not options.gerrit_no_reset) | 990 gerrit_reset=not options.gerrit_no_reset) |
981 gclient_output = ensure_checkout(**checkout_parameters) | 991 gclient_output = ensure_checkout(**checkout_parameters) |
982 except GclientSyncFailed: | 992 except GclientSyncFailed: |
983 print 'We failed gclient sync, lets delete the checkout and retry.' | 993 print 'We failed gclient sync, lets delete the checkout and retry.' |
984 ensure_no_checkout(dir_names) | 994 ensure_no_checkout(dir_names) |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 # download patch failure is still an infra problem. | 1090 # download patch failure is still an infra problem. |
1081 if e.code == 3: | 1091 if e.code == 3: |
1082 # Patch download problem. | 1092 # Patch download problem. |
1083 return 87 | 1093 return 87 |
1084 # Genuine patch problem. | 1094 # Genuine patch problem. |
1085 return 88 | 1095 return 88 |
1086 | 1096 |
1087 | 1097 |
1088 if __name__ == '__main__': | 1098 if __name__ == '__main__': |
1089 sys.exit(main()) | 1099 sys.exit(main()) |
OLD | NEW |