Søren Gjesse | 1525df3 | 2022-06-30 14:04:44 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # Copyright (c) 2022, the R8 project authors. Please see the AUTHORS file |
| 3 | # for details. All rights reserved. Use of this source code is governed by a |
| 4 | # BSD-style license that can be found in the LICENSE file. |
| 5 | |
| 6 | import argparse |
| 7 | import os |
| 8 | import subprocess |
| 9 | import sys |
| 10 | import utils |
| 11 | |
| 12 | def parse_options(): |
| 13 | parser = argparse.ArgumentParser(description='Release r8') |
| 14 | parser.add_argument('--branch', |
| 15 | metavar=('<branch>'), |
| 16 | help='Branch to cherry-pick to') |
| 17 | parser.add_argument('--clean-checkout', '--clean_checkout', |
| 18 | default=False, |
| 19 | action='store_true', |
| 20 | help='Perform cherry picks in a clean checkout') |
| 21 | parser.add_argument('--no-upload', '--no_upload', |
| 22 | default=False, |
| 23 | action='store_true', |
| 24 | help='Do not upload to Gerrit') |
| 25 | parser.add_argument('hashes', metavar='<hash>', nargs='+', |
| 26 | help='Hashed to merge') |
| 27 | |
| 28 | return parser.parse_args() |
| 29 | |
| 30 | |
| 31 | def run(args): |
| 32 | # Checkout the branch. |
| 33 | subprocess.check_output(['git', 'checkout', args.branch]) |
| 34 | |
| 35 | if (not args.clean_checkout): |
| 36 | for i in range(len(args.hashes) + 1): |
| 37 | branch = 'cherry-%d' % (i + 1) |
| 38 | print('Deleting branch %s' % branch) |
| 39 | subprocess.run(['git', 'branch', branch, '-D']) |
| 40 | |
| 41 | count = 1 |
| 42 | for hash in args.hashes: |
| 43 | branch = 'cherry-%d' % count |
| 44 | print('Cherry-picking %s in %s' % (hash, branch)) |
| 45 | if (count == 1): |
| 46 | subprocess.run(['git', 'new-branch', branch, '--upstream', 'origin/%s' % args.branch]) |
| 47 | else: |
| 48 | subprocess.run(['git', 'new-branch', branch, '--upstream-current']) |
| 49 | |
| 50 | subprocess.run(['git', 'cherry-pick', hash]) |
| 51 | |
| 52 | question = ('Ready to continue (cwd %s, will not upload to Gerrit)' % os.getcwd() |
| 53 | if args.no_upload else |
| 54 | 'Ready to upload %s (cwd %s)' % (branch, os.getcwd())) |
| 55 | answer = input(question + ' [y/N]?') |
| 56 | if answer != 'y': |
| 57 | print('Aborting new branch for %s' % branch_version) |
| 58 | sys.exit(1) |
| 59 | |
| 60 | if (not args.no_upload): |
| 61 | subprocess.run(['git', 'cl', 'upload']) |
| 62 | count = count + 1 |
| 63 | |
| 64 | branch = 'cherry-%d' % count |
| 65 | subprocess.run(['git', 'new-branch', branch, '--upstream-current']) |
| 66 | editor = os.environ.get('VISUAL') |
| 67 | if not editor: |
| 68 | editor = os.environ.get('EDITOR') |
| 69 | if not editor: |
| 70 | editor = 'vi' |
| 71 | else: |
| 72 | print("Opening src/main/java/com/android/tools/r8/Version.java" + |
| 73 | " for version update with %" % editor) |
| 74 | subprocess.run([editor, 'src/main/java/com/android/tools/r8/Version.java']) |
| 75 | subprocess.run(['git', 'commit', '-a']) |
| 76 | if (not args.no_upload): |
| 77 | subprocess.run(['git', 'cl', 'upload']) |
| 78 | if (args.clean_checkout): |
| 79 | answer = input('Done, press enter to delete checkout in %s' % os.getcwd()) |
| 80 | |
| 81 | def main(): |
| 82 | args = parse_options() |
| 83 | |
| 84 | if (args.clean_checkout): |
| 85 | with utils.TempDir() as temp: |
| 86 | print("Performing cherry-picking in %s" % temp) |
| 87 | subprocess.check_call(['git', 'clone', utils.REPO_SOURCE, temp]) |
| 88 | with utils.ChangedWorkingDirectory(temp): |
| 89 | run(args) |
| 90 | else: |
| 91 | # Run in current directory. |
| 92 | print("Performing cherry-picking in %s" % os.getcwd()) |
| 93 | subprocess.check_output(['git', 'fetch', 'origin']) |
| 94 | run(args) |
| 95 | |
| 96 | if __name__ == '__main__': |
| 97 | sys.exit(main()) |