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