Morten Krogh-Jespersen | 8a4d1ca | 2021-01-19 08:27:02 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 2 | # Copyright (c) 2019, 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 datetime |
| 8 | import os.path |
| 9 | import re |
Ian Zerny | 68f5c13 | 2023-11-01 12:57:07 +0100 | [diff] [blame] | 10 | import shutil |
Søren Gjesse | 4062e9c | 2023-09-01 12:21:08 +0200 | [diff] [blame] | 11 | import stat |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 12 | import subprocess |
| 13 | import sys |
Christoffer Quist Adamsen | d408d8d | 2021-01-26 19:50:39 +0100 | [diff] [blame] | 14 | import urllib.request |
Søren Gjesse | 2d6e937 | 2020-11-04 08:17:28 +0100 | [diff] [blame] | 15 | import xml.etree.ElementTree |
Søren Gjesse | 975c5df | 2019-12-10 13:48:05 +0100 | [diff] [blame] | 16 | import zipfile |
Ian Zerny | cf1eb3c | 2020-09-24 08:27:23 +0200 | [diff] [blame] | 17 | |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 18 | import utils |
| 19 | |
Søren Gjesse | 448da11 | 2023-08-10 09:30:55 +0200 | [diff] [blame] | 20 | R8_DEV_BRANCH = '8.3' |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 21 | R8_VERSION_FILE = os.path.join('src', 'main', 'java', 'com', 'android', 'tools', |
| 22 | 'r8', 'Version.java') |
Søren Gjesse | 2725159 | 2019-11-06 17:35:23 +0100 | [diff] [blame] | 23 | THIS_FILE_RELATIVE = os.path.join('tools', 'r8_release.py') |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 24 | GMAVEN_PUBLISHER = '/google/bin/releases/android-devtools/gmaven/publisher/gmaven-publisher' |
Søren Gjesse | 975c5df | 2019-12-10 13:48:05 +0100 | [diff] [blame] | 25 | |
| 26 | DESUGAR_JDK_LIBS = 'desugar_jdk_libs' |
| 27 | DESUGAR_JDK_LIBS_CONFIGURATION = DESUGAR_JDK_LIBS + '_configuration' |
| 28 | ANDROID_TOOLS_PACKAGE = 'com.android.tools' |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 29 | |
Søren Gjesse | 07b6aea | 2019-12-12 11:11:58 +0100 | [diff] [blame] | 30 | GITHUB_DESUGAR_JDK_LIBS = 'https://github.com/google/desugar_jdk_libs' |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 31 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 32 | |
Søren Gjesse | 4062e9c | 2023-09-01 12:21:08 +0200 | [diff] [blame] | 33 | def install_gerrit_change_id_hook(checkout_dir): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 34 | with utils.ChangedWorkingDirectory(checkout_dir): |
| 35 | # Fancy way of getting the string ".git". |
| 36 | git_dir = subprocess.check_output(['git', 'rev-parse', '--git-dir' |
| 37 | ]).decode('utf-8').strip() |
| 38 | commit_msg_hooks = '%s/hooks/commit-msg' % git_dir |
| 39 | if not os.path.exists(os.path.dirname(commit_msg_hooks)): |
| 40 | os.mkdir(os.path.dirname(commit_msg_hooks)) |
| 41 | # Install commit hook to generate Gerrit 'Change-Id:'. |
| 42 | urllib.request.urlretrieve( |
| 43 | 'https://gerrit-review.googlesource.com/tools/hooks/commit-msg', |
| 44 | commit_msg_hooks) |
| 45 | st = os.stat(commit_msg_hooks) |
| 46 | os.chmod(commit_msg_hooks, |
| 47 | st.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) |
| 48 | |
Søren Gjesse | 4062e9c | 2023-09-01 12:21:08 +0200 | [diff] [blame] | 49 | |
Morten Krogh-Jespersen | d86a301 | 2020-02-21 15:06:13 +0100 | [diff] [blame] | 50 | def checkout_r8(temp, branch): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 51 | subprocess.check_call(['git', 'clone', utils.REPO_SOURCE, temp]) |
| 52 | with utils.ChangedWorkingDirectory(temp): |
| 53 | subprocess.check_call([ |
| 54 | 'git', 'new-branch', '--upstream', |
| 55 | 'origin/%s' % branch, 'dev-release' |
| 56 | ]) |
| 57 | install_gerrit_change_id_hook(temp) |
| 58 | return temp |
Morten Krogh-Jespersen | d86a301 | 2020-02-21 15:06:13 +0100 | [diff] [blame] | 59 | |
| 60 | |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 61 | def prepare_release(args): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 62 | if args.version: |
| 63 | print("Cannot manually specify version when making a dev release.") |
| 64 | sys.exit(1) |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 65 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 66 | def make_release(args): |
| 67 | commithash = args.dev_release |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 68 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 69 | with utils.TempDir() as temp: |
| 70 | with utils.ChangedWorkingDirectory(checkout_r8(temp, |
| 71 | R8_DEV_BRANCH)): |
| 72 | # Compute the current and new version on the branch. |
| 73 | result = None |
| 74 | for line in open(R8_VERSION_FILE, 'r'): |
| 75 | result = re.match( |
| 76 | r'.*LABEL = "%s\.(\d+)\-dev";' % R8_DEV_BRANCH, line) |
| 77 | if result: |
| 78 | break |
| 79 | if not result or not result.group(1): |
| 80 | print('Failed to find version label matching %s(\d+)-dev'\ |
| 81 | % R8_DEV_BRANCH) |
| 82 | sys.exit(1) |
| 83 | try: |
| 84 | patch_version = int(result.group(1)) |
| 85 | except ValueError: |
| 86 | print('Failed to convert version to integer: %s' % |
| 87 | result.group(1)) |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 88 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 89 | old_version = '%s.%s-dev' % (R8_DEV_BRANCH, patch_version) |
| 90 | version = '%s.%s-dev' % (R8_DEV_BRANCH, patch_version + 1) |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 91 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 92 | # Verify that the merge point from main is not empty. |
| 93 | merge_diff_output = subprocess.check_output( |
| 94 | ['git', 'diff', 'HEAD..%s' % commithash]).decode('utf-8') |
| 95 | other_diff = version_change_diff(merge_diff_output, old_version, |
| 96 | "main") |
| 97 | if not other_diff: |
| 98 | print('Merge point from main (%s)' % commithash, \ |
| 99 | 'is the same as exiting release (%s).' % old_version) |
| 100 | sys.exit(1) |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 101 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 102 | if args.dev_pre_cherry_pick: |
| 103 | for pre_commit in args.dev_pre_cherry_pick: |
| 104 | subprocess.check_call( |
| 105 | ['git', 'cherry-pick', '--no-edit', pre_commit]) |
Rico Wind | 140a564 | 2019-11-26 10:44:21 +0100 | [diff] [blame] | 106 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 107 | # Merge the desired commit from main on to the branch. |
| 108 | subprocess.check_call( |
| 109 | ['git', 'merge', '--no-ff', '--no-edit', commithash]) |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 110 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 111 | # Rewrite the version, commit and validate. |
| 112 | sed(old_version, version, R8_VERSION_FILE) |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 113 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 114 | subprocess.check_call( |
| 115 | ['git', 'commit', '-a', '-m', |
| 116 | 'Version %s' % version]) |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 117 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 118 | version_diff_output = subprocess.check_output( |
| 119 | ['git', 'diff', '%s..HEAD' % commithash]).decode('utf-8') |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 120 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 121 | validate_version_change_diff(version_diff_output, "main", |
| 122 | version) |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 123 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 124 | cmd = ['git', 'cl', 'upload', '--no-squash'] |
| 125 | if args.bypass_hooks: |
| 126 | cmd.append('--bypass-hooks') |
| 127 | maybe_check_call(args, cmd) |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 128 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 129 | if args.dry_run: |
| 130 | input( |
| 131 | 'DryRun: check %s for content of version %s [enter to continue]:' |
| 132 | % (temp, version)) |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 133 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 134 | return "%s dev version %s from hash %s for review" % ( |
| 135 | 'DryRun: omitted upload of' if args.dry_run else 'Uploaded', |
| 136 | version, commithash) |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 137 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 138 | return make_release |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 139 | |
| 140 | |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 141 | def maybe_tag(args, version): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 142 | maybe_check_call(args, |
| 143 | ['git', 'tag', '-a', version, '-m', |
| 144 | '"%s"' % version]) |
| 145 | maybe_check_call(args, ['git', 'push', 'origin', 'refs/tags/%s' % version]) |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 146 | |
Morten Krogh-Jespersen | d86a301 | 2020-02-21 15:06:13 +0100 | [diff] [blame] | 147 | |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 148 | def version_change_diff(diff, old_version, new_version): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 149 | invalid_line = None |
| 150 | for line in str(diff).splitlines(): |
| 151 | if line.startswith('- ') and \ |
| 152 | line != '- public static final String LABEL = "%s";' % old_version: |
| 153 | invalid_line = line |
| 154 | elif line.startswith('+ ') and \ |
| 155 | line != '+ public static final String LABEL = "%s";' % new_version: |
| 156 | invalid_line = line |
| 157 | return invalid_line |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 158 | |
Søren Gjesse | ddeb02e | 2019-11-06 15:48:07 +0100 | [diff] [blame] | 159 | |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 160 | def validate_version_change_diff(version_diff_output, old_version, new_version): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 161 | invalid = version_change_diff(version_diff_output, old_version, new_version) |
| 162 | if invalid: |
| 163 | print("Unexpected diff:") |
| 164 | print("=" * 80) |
| 165 | print(version_diff_output) |
| 166 | print("=" * 80) |
| 167 | accept_string = 'THE DIFF IS OK!' |
| 168 | answer = input("Accept the additonal diff as part of the release? " |
| 169 | "Type '%s' to accept: " % accept_string) |
| 170 | if answer != accept_string: |
| 171 | print("You did not type '%s'" % accept_string) |
| 172 | print('Aborting dev release for %s' % version) |
| 173 | sys.exit(1) |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 174 | |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 175 | |
| 176 | def maybe_check_call(args, cmd): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 177 | if args.dry_run: |
| 178 | print('DryRun:', ' '.join(cmd)) |
| 179 | else: |
| 180 | print(' '.join(cmd)) |
| 181 | return subprocess.check_call(cmd) |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 182 | |
| 183 | |
Ian Zerny | 8c5f7b4 | 2023-05-25 11:24:05 +0200 | [diff] [blame] | 184 | def update_prebuilds(r8_checkout, version, checkout, keepanno=False): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 185 | path = os.path.join(r8_checkout, 'tools', 'update_prebuilds_in_android.py') |
| 186 | commit_arg = '--commit_hash=' if len(version) == 40 else '--version=' |
| 187 | cmd = [path, '--targets=lib', '--maps', commit_arg + version, checkout] |
| 188 | if keepanno: |
| 189 | cmd.append("--keepanno") |
| 190 | subprocess.check_call(cmd) |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 191 | |
| 192 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 193 | def release_studio_or_aosp(r8_checkout, |
| 194 | path, |
| 195 | options, |
| 196 | git_message, |
| 197 | keepanno=False): |
| 198 | with utils.ChangedWorkingDirectory(path): |
| 199 | if not options.use_existing_work_branch: |
| 200 | subprocess.call(['repo', 'abandon', 'update-r8']) |
| 201 | if not options.no_sync: |
| 202 | subprocess.check_call(['repo', 'sync', '-cq', '-j', '16']) |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 203 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 204 | prebuilts_r8 = os.path.join(path, 'prebuilts', 'r8') |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 205 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 206 | if not options.use_existing_work_branch: |
| 207 | with utils.ChangedWorkingDirectory(prebuilts_r8): |
| 208 | subprocess.check_call(['repo', 'start', 'update-r8']) |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 209 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 210 | update_prebuilds(r8_checkout, options.version, path, keepanno) |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 211 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 212 | with utils.ChangedWorkingDirectory(prebuilts_r8): |
| 213 | if not options.use_existing_work_branch: |
| 214 | subprocess.check_call( |
| 215 | ['git', 'commit', '-a', '-m', git_message]) |
| 216 | else: |
| 217 | print('Not committing when --use-existing-work-branch. ' + |
| 218 | 'Commit message should be:\n\n' + git_message + '\n') |
| 219 | # Don't upload if requested not to, or if changes are not committed due |
| 220 | # to --use-existing-work-branch |
| 221 | if not options.no_upload and not options.use_existing_work_branch: |
| 222 | process = subprocess.Popen( |
| 223 | ['repo', 'upload', '.', '--verify', '--current-branch'], |
| 224 | stdin=subprocess.PIPE) |
| 225 | return process.communicate(input=b'y\n')[0] |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 226 | |
| 227 | |
Morten Krogh-Jespersen | b4a7acc | 2019-10-02 10:46:32 +0200 | [diff] [blame] | 228 | def prepare_aosp(args): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 229 | assert args.version |
| 230 | assert os.path.exists(args.aosp), "Could not find AOSP path %s" % args.aosp |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 231 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 232 | def release_aosp(options): |
| 233 | print("Releasing for AOSP") |
| 234 | if options.dry_run: |
| 235 | return 'DryRun: omitting AOSP release for %s' % options.version |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 236 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 237 | git_message = ("""Update D8 and R8 to %s |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 238 | |
Morten Krogh-Jespersen | dbbf9a8 | 2020-08-11 21:38:08 +0200 | [diff] [blame] | 239 | Version: %s |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 240 | This build IS NOT suitable for preview or public release. |
| 241 | |
Morten Krogh-Jespersen | b4a7acc | 2019-10-02 10:46:32 +0200 | [diff] [blame] | 242 | Built here: go/r8-releases/raw/%s |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 243 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 244 | Test: TARGET_PRODUCT=aosp_arm64 m -j core-oj""" % |
| 245 | (args.version, args.version, args.version)) |
| 246 | # Fixes to Android U branch is based of 8.2.2-dev where the keepanno library |
| 247 | # is not built. |
| 248 | keepanno = not args.version.startswith('8.2.2-udc') |
| 249 | return release_studio_or_aosp(utils.REPO_ROOT, |
| 250 | args.aosp, |
| 251 | options, |
| 252 | git_message, |
| 253 | keepanno=keepanno) |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 254 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 255 | return release_aosp |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 256 | |
| 257 | |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 258 | def prepare_maven(args): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 259 | assert args.version |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 260 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 261 | def release_maven(options): |
| 262 | gfile = '/bigstore/r8-releases/raw/%s/r8lib.zip' % args.version |
| 263 | release_id = gmaven_publisher_stage(options, [gfile]) |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 264 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 265 | print("Staged Release ID " + release_id + ".\n") |
| 266 | gmaven_publisher_stage_redir_test_info( |
| 267 | release_id, "com.android.tools:r8:%s" % args.version, "r8lib.jar") |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 268 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 269 | print |
| 270 | answer = input("Continue with publishing [y/N]:") |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 271 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 272 | if answer != 'y': |
| 273 | print('Aborting release to Google maven') |
| 274 | sys.exit(1) |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 275 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 276 | gmaven_publisher_publish(args, release_id) |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 277 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 278 | print("") |
| 279 | print("Published. Use the email workflow for approval.") |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 280 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 281 | return release_maven |
| 282 | |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 283 | |
Ian Zerny | acfaf29 | 2020-09-24 07:14:56 +0200 | [diff] [blame] | 284 | # ------------------------------------------------------ column 70 --v |
Ian Zerny | cf1eb3c | 2020-09-24 08:27:23 +0200 | [diff] [blame] | 285 | def git_message_dev(version, bugs): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 286 | return """Update D8 R8 to %s |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 287 | |
Ian Zerny | acfaf29 | 2020-09-24 07:14:56 +0200 | [diff] [blame] | 288 | This is a development snapshot, it's fine to use for studio canary |
| 289 | build, but not for BETA or release, for those we would need a release |
| 290 | version of R8 binaries. This build IS suitable for preview release |
| 291 | but IS NOT suitable for public release. |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 292 | |
Morten Krogh-Jespersen | b4a7acc | 2019-10-02 10:46:32 +0200 | [diff] [blame] | 293 | Built here: go/r8-releases/raw/%s |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 294 | Test: ./gradlew check |
Ian Zerny | fec0009 | 2022-03-16 08:25:07 +0100 | [diff] [blame] | 295 | Bug: %s""" % (version, version, '\nBug: '.join(map(bug_fmt, bugs))) |
Morten Krogh-Jespersen | b4a7acc | 2019-10-02 10:46:32 +0200 | [diff] [blame] | 296 | |
| 297 | |
Morten Krogh-Jespersen | a1396cd | 2019-10-02 16:14:40 +0200 | [diff] [blame] | 298 | def git_message_release(version, bugs): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 299 | return """D8 R8 version %s |
Morten Krogh-Jespersen | a1396cd | 2019-10-02 16:14:40 +0200 | [diff] [blame] | 300 | |
| 301 | Built here: go/r8-releases/raw/%s/ |
| 302 | Test: ./gradlew check |
Morten Krogh-Jespersen | d86a301 | 2020-02-21 15:06:13 +0100 | [diff] [blame] | 303 | |
Ian Zerny | fec0009 | 2022-03-16 08:25:07 +0100 | [diff] [blame] | 304 | Bug: %s""" % (version, version, '\nBug: '.join(map(bug_fmt, bugs))) |
Morten Krogh-Jespersen | a1396cd | 2019-10-02 16:14:40 +0200 | [diff] [blame] | 305 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 306 | |
Ian Zerny | fec0009 | 2022-03-16 08:25:07 +0100 | [diff] [blame] | 307 | def bug_fmt(bug): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 308 | return "b/%s" % bug |
| 309 | |
Morten Krogh-Jespersen | a1396cd | 2019-10-02 16:14:40 +0200 | [diff] [blame] | 310 | |
Morten Krogh-Jespersen | b4a7acc | 2019-10-02 10:46:32 +0200 | [diff] [blame] | 311 | def prepare_studio(args): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 312 | assert args.version |
| 313 | assert os.path.exists(args.studio), ("Could not find STUDIO path %s" % |
| 314 | args.studio) |
Søren Gjesse | 25e6191 | 2023-11-06 16:02:07 +0100 | [diff] [blame] | 315 | if (not args.studio.endswith('-dev') |
| 316 | and not args.studio.endswith('-dev/') |
| 317 | and not args.studio_legacy_release): |
| 318 | print("Please use the new release process, see go/r8-release-prebuilts. " |
| 319 | + "If for some reason the legacy release process is needed " |
| 320 | + "pass --studio-legacy-release") |
| 321 | sys.exit(1) |
Morten Krogh-Jespersen | b4a7acc | 2019-10-02 10:46:32 +0200 | [diff] [blame] | 322 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 323 | def release_studio(options): |
| 324 | print("Releasing for STUDIO") |
| 325 | if options.dry_run: |
| 326 | return 'DryRun: omitting studio release for %s' % options.version |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 327 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 328 | if 'dev' in options.version: |
| 329 | git_message = git_message_dev(options.version, options.bug) |
| 330 | r8_checkout = utils.REPO_ROOT |
| 331 | return release_studio_or_aosp(r8_checkout, args.studio, options, |
| 332 | git_message) |
| 333 | else: |
| 334 | with utils.TempDir() as temp: |
| 335 | checkout_r8(temp, |
| 336 | options.version[0:options.version.rindex('.')]) |
| 337 | git_message = git_message_release(options.version, options.bug) |
| 338 | return release_studio_or_aosp(temp, args.studio, options, |
| 339 | git_message) |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 340 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 341 | return release_studio |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 342 | |
| 343 | |
| 344 | def g4_cp(old, new, file): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 345 | subprocess.check_call('g4 cp {%s,%s}/%s' % (old, new, file), shell=True) |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 346 | |
| 347 | |
| 348 | def g4_open(file): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 349 | if not os.access(file, os.W_OK): |
| 350 | subprocess.check_call('g4 open %s' % file, shell=True) |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 351 | |
| 352 | |
Rico Wind | 8d008ca | 2020-04-22 12:13:15 +0200 | [diff] [blame] | 353 | def g4_change(version): |
Ian Zerny | 68f5c13 | 2023-11-01 12:57:07 +0100 | [diff] [blame] | 354 | message = f'Update R8 to {version}' |
| 355 | if version == 'main': |
| 356 | message = f'DO NOT SUBMIT: {message}' |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 357 | return subprocess.check_output( |
Ian Zerny | 68f5c13 | 2023-11-01 12:57:07 +0100 | [diff] [blame] | 358 | f'g4 change --desc "{message}\n"', |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 359 | shell=True).decode('utf-8') |
| 360 | |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 361 | |
Morten Krogh-Jespersen | 1f2f514 | 2020-09-21 11:20:23 +0200 | [diff] [blame] | 362 | def get_cl_id(c4_change_output): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 363 | startIndex = c4_change_output.find('Change ') + len('Change ') |
| 364 | endIndex = c4_change_output.find(' ', startIndex) |
| 365 | cl = c4_change_output[startIndex:endIndex] |
| 366 | assert cl.isdigit() |
| 367 | return cl |
| 368 | |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 369 | |
| 370 | def sed(pattern, replace, path): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 371 | with open(path, "r") as sources: |
| 372 | lines = sources.readlines() |
| 373 | with open(path, "w") as sources: |
| 374 | for line in lines: |
| 375 | sources.write(re.sub(pattern, replace, line)) |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 376 | |
Morten Krogh-Jespersen | b4a7acc | 2019-10-02 10:46:32 +0200 | [diff] [blame] | 377 | def download_file(version, file, dst): |
Ian Zerny | 68f5c13 | 2023-11-01 12:57:07 +0100 | [diff] [blame] | 378 | if version == 'main': |
| 379 | src = os.path.join(utils.LIBS, file) |
| 380 | if os.path.exists(src): |
| 381 | shutil.copyfile(src, dst) |
| 382 | else: |
| 383 | print(f"WARNING: no file found for {src}. Skipping.") |
| 384 | return |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 385 | dir = 'raw' if len(version) != 40 else 'raw/main' |
| 386 | urllib.request.urlretrieve( |
| 387 | ('https://storage.googleapis.com/r8-releases/%s/%s/%s' % |
| 388 | (dir, version, file)), dst) |
| 389 | |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 390 | |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 391 | def download_gfile(gfile, dst): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 392 | if not gfile.startswith('/bigstore/r8-releases'): |
| 393 | print('Unexpected gfile prefix for %s' % gfile) |
| 394 | sys.exit(1) |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 395 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 396 | urllib.request.urlretrieve( |
| 397 | 'https://storage.googleapis.com/%s' % gfile[len('/bigstore/'):], dst) |
| 398 | |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 399 | |
| 400 | def blaze_run(target): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 401 | return subprocess.check_output('blaze run %s' % target, |
| 402 | shell=True, |
| 403 | stderr=subprocess.STDOUT).decode('utf-8') |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 404 | |
| 405 | |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 406 | def prepare_google3(args): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 407 | assert args.version |
| 408 | # Check if an existing client exists. |
| 409 | if not args.use_existing_work_branch: |
| 410 | check_no_google3_client(args, args.p4_client) |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 411 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 412 | def release_google3(options): |
| 413 | print("Releasing for Google 3") |
| 414 | if options.dry_run: |
| 415 | return 'DryRun: omitting g3 release for %s' % options.version |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 416 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 417 | google3_base = subprocess.check_output( |
| 418 | ['p4', 'g4d', '-f', args.p4_client]).decode('utf-8').rstrip() |
| 419 | third_party_r8 = os.path.join(google3_base, 'third_party', 'java', 'r8') |
| 420 | today = datetime.date.today() |
| 421 | with utils.ChangedWorkingDirectory(third_party_r8): |
| 422 | # download files |
| 423 | g4_open('full.jar') |
| 424 | g4_open('src.jar') |
| 425 | g4_open('lib.jar') |
| 426 | g4_open('lib.jar.map') |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 427 | g4_open('desugar_jdk_libs_configuration.jar') |
Ian Zerny | 68f5c13 | 2023-11-01 12:57:07 +0100 | [diff] [blame] | 428 | g4_open('threading-module-blocking.jar') |
| 429 | g4_open('threading-module-single-threaded.jar') |
| 430 | download_file(options.version, |
| 431 | 'r8-full-exclude-deps.jar', |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 432 | 'full.jar') |
Ian Zerny | 68f5c13 | 2023-11-01 12:57:07 +0100 | [diff] [blame] | 433 | download_file(options.version, |
Ian Zerny | 68f5c13 | 2023-11-01 12:57:07 +0100 | [diff] [blame] | 434 | 'r8-src.jar', |
| 435 | 'src.jar') |
| 436 | download_file(options.version, |
| 437 | 'r8lib-exclude-deps.jar', |
| 438 | 'lib.jar') |
| 439 | download_file(options.version, |
| 440 | 'r8lib-exclude-deps.jar.map', |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 441 | 'lib.jar.map') |
Ian Zerny | 68f5c13 | 2023-11-01 12:57:07 +0100 | [diff] [blame] | 442 | download_file(options.version, |
| 443 | 'desugar_jdk_libs_configuration.jar', |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 444 | 'desugar_jdk_libs_configuration.jar') |
Ian Zerny | 68f5c13 | 2023-11-01 12:57:07 +0100 | [diff] [blame] | 445 | download_file(options.version, |
Ian Zerny | 68f5c13 | 2023-11-01 12:57:07 +0100 | [diff] [blame] | 446 | 'threading-module-blocking.jar', |
| 447 | 'threading-module-blocking.jar') |
| 448 | download_file(options.version, |
| 449 | 'threading-module-single-threaded.jar', |
| 450 | 'threading-module-single-threaded.jar') |
| 451 | if options.version != 'main': |
| 452 | g4_open('METADATA') |
| 453 | metadata_path = os.path.join(third_party_r8, 'METADATA') |
| 454 | match_count = 0 |
Ian Zerny | ed1f851 | 2023-11-07 11:07:57 +0100 | [diff] [blame] | 455 | match_count_expected = 11 |
Ian Zerny | 68f5c13 | 2023-11-01 12:57:07 +0100 | [diff] [blame] | 456 | version_match_regexp = r'[1-9]\.[0-9]{1,2}\.[0-9]{1,3}-dev' |
| 457 | for line in open(metadata_path, 'r'): |
| 458 | result = re.search(version_match_regexp, line) |
| 459 | if result: |
| 460 | match_count = match_count + 1 |
| 461 | if match_count != match_count_expected: |
| 462 | print(f"""WARNING: |
| 463 | Could not find the previous -dev release string to replace in METADATA. |
| 464 | Expected to find it mentioned {match_count_expected} times, but found |
| 465 | {match_count} occurrences. Please update {metadata_path} manually and |
| 466 | run again with options --google3 --use-existing-work-branch. |
| 467 | """) |
| 468 | sys.exit(1) |
| 469 | sed(version_match_regexp, options.version, metadata_path) |
| 470 | sed(r'\{ year.*\}', |
| 471 | f'{{ year: {today.year} month: {today.month} day: {today.day} }}', |
| 472 | metadata_path) |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 473 | subprocess.check_output('chmod u+w *', shell=True) |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 474 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 475 | with utils.ChangedWorkingDirectory(google3_base): |
| 476 | blaze_result = blaze_run('//third_party/java/r8:d8 -- --version') |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 477 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 478 | assert options.version in blaze_result |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 479 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 480 | if not options.no_upload: |
| 481 | change_result = g4_change(options.version) |
| 482 | change_result += 'Run \'(g4d ' + args.p4_client \ |
| 483 | + ' && tap_presubmit -p all --train -c ' \ |
| 484 | + get_cl_id(change_result) + ')\' for running TAP global' \ |
| 485 | + ' presubmit using the train.\n' \ |
| 486 | + 'Run \'(g4d ' + args.p4_client \ |
| 487 | + ' && tap_presubmit -p all --notrain --detach --email' \ |
| 488 | + ' --skip_flaky_targets --skip_already_failing -c ' \ |
| 489 | + get_cl_id(change_result) + ')\' for running an isolated' \ |
| 490 | + ' TAP global presubmit.' |
| 491 | return change_result |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 492 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 493 | return release_google3 |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 494 | |
| 495 | |
Søren Gjesse | 73355ec | 2020-06-29 09:19:44 +0200 | [diff] [blame] | 496 | def update_desugar_library_in_studio(args): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 497 | assert os.path.exists(args.studio), ("Could not find STUDIO path %s" % |
| 498 | args.studio) |
Søren Gjesse | 73355ec | 2020-06-29 09:19:44 +0200 | [diff] [blame] | 499 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 500 | def make_release(args): |
| 501 | library_version = args.update_desugar_library_in_studio[0] |
| 502 | configuration_version = args.update_desugar_library_in_studio[1] |
| 503 | change_name = 'update-desugar-library-dependencies' |
Søren Gjesse | 73355ec | 2020-06-29 09:19:44 +0200 | [diff] [blame] | 504 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 505 | with utils.ChangedWorkingDirectory(args.studio): |
| 506 | if not args.use_existing_work_branch: |
| 507 | subprocess.call(['repo', 'abandon', change_name]) |
| 508 | if not args.no_sync: |
| 509 | subprocess.check_call(['repo', 'sync', '-cq', '-j', '16']) |
Søren Gjesse | 73355ec | 2020-06-29 09:19:44 +0200 | [diff] [blame] | 510 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 511 | cmd = [ |
| 512 | 'tools/base/bazel/bazel', 'run', |
| 513 | '//tools/base/bazel:add_dependency', '--', |
| 514 | '--repo=https://maven.google.com com.android.tools:desugar_jdk_libs:%s' |
| 515 | % library_version |
| 516 | ] |
| 517 | utils.PrintCmd(cmd) |
| 518 | subprocess.check_call(" ".join(cmd), shell=True) |
| 519 | cmd = ['tools/base/bazel/bazel', 'shutdown'] |
| 520 | utils.PrintCmd(cmd) |
| 521 | subprocess.check_call(cmd) |
Søren Gjesse | 73355ec | 2020-06-29 09:19:44 +0200 | [diff] [blame] | 522 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 523 | prebuilts_tools = os.path.join(args.studio, 'prebuilts', 'tools') |
Søren Gjesse | 73355ec | 2020-06-29 09:19:44 +0200 | [diff] [blame] | 524 | with utils.ChangedWorkingDirectory(prebuilts_tools): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 525 | if not args.use_existing_work_branch: |
| 526 | with utils.ChangedWorkingDirectory(prebuilts_tools): |
| 527 | subprocess.check_call(['repo', 'start', change_name]) |
| 528 | m2_dir = os.path.join('common', 'm2', 'repository', 'com', |
| 529 | 'android', 'tools') |
| 530 | subprocess.check_call([ |
| 531 | 'git', 'add', |
| 532 | os.path.join(m2_dir, DESUGAR_JDK_LIBS, library_version) |
| 533 | ]) |
| 534 | subprocess.check_call([ |
| 535 | 'git', 'add', |
| 536 | os.path.join(m2_dir, DESUGAR_JDK_LIBS_CONFIGURATION, |
| 537 | configuration_version) |
| 538 | ]) |
Søren Gjesse | 73355ec | 2020-06-29 09:19:44 +0200 | [diff] [blame] | 539 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 540 | git_message = ("""Update library desugaring dependencies |
Søren Gjesse | 73355ec | 2020-06-29 09:19:44 +0200 | [diff] [blame] | 541 | |
| 542 | com.android.tools:desugar_jdk_libs:%s |
| 543 | com.android.tools:desugar_jdk_libs_configuration:%s |
| 544 | |
| 545 | Bug: %s |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 546 | Test: L8ToolTest, L8DexDesugarTest""" % |
| 547 | (library_version, configuration_version, |
| 548 | '\nBug: '.join(map(bug_fmt, args.bug)))) |
Søren Gjesse | 73355ec | 2020-06-29 09:19:44 +0200 | [diff] [blame] | 549 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 550 | if not args.use_existing_work_branch: |
| 551 | subprocess.check_call( |
| 552 | ['git', 'commit', '-a', '-m', git_message]) |
| 553 | else: |
| 554 | print('Not committing when --use-existing-work-branch. ' + |
| 555 | 'Commit message should be:\n\n' + git_message + '\n') |
| 556 | # Don't upload if requested not to, or if changes are not committed due |
| 557 | # to --use-existing-work-branch |
| 558 | if not args.no_upload and not args.use_existing_work_branch: |
| 559 | process = subprocess.Popen(['repo', 'upload', '.', '--verify'], |
| 560 | stdin=subprocess.PIPE) |
| 561 | return process.communicate(input='y\n')[0] |
Søren Gjesse | 73355ec | 2020-06-29 09:19:44 +0200 | [diff] [blame] | 562 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 563 | return make_release |
Søren Gjesse | 73355ec | 2020-06-29 09:19:44 +0200 | [diff] [blame] | 564 | |
| 565 | |
Søren Gjesse | 975c5df | 2019-12-10 13:48:05 +0100 | [diff] [blame] | 566 | def prepare_desugar_library(args): |
| 567 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 568 | def make_release(args): |
| 569 | library_version = args.desugar_library[0] |
| 570 | configuration_version = args.desugar_library[1] |
Søren Gjesse | 975c5df | 2019-12-10 13:48:05 +0100 | [diff] [blame] | 571 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 572 | # TODO(b/237636871): Cleanup and generalize. |
| 573 | if (not (library_version.startswith('1.1') or |
| 574 | library_version.startswith('1.2') or |
| 575 | library_version.startswith('2.0'))): |
| 576 | print( |
| 577 | "Release script does not support desugared library version %s" % |
| 578 | library_version) |
| 579 | sys.exit(1) |
Søren Gjesse | e78b165 | 2022-06-30 12:38:36 +0200 | [diff] [blame] | 580 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 581 | postfixes = [''] |
| 582 | if library_version.startswith('1.2'): |
| 583 | postfixes = ['_legacy'] |
| 584 | if library_version.startswith('2.0'): |
| 585 | postfixes = ['_minimal', '', '_nio'] |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 586 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 587 | with utils.TempDir() as temp: |
| 588 | with utils.ChangedWorkingDirectory(temp): |
| 589 | artifacts = [] |
| 590 | for postfix in postfixes: |
| 591 | group_postfix = ('' if postfix == '_legacy' else postfix) |
| 592 | archive_postfix = (postfix |
| 593 | if library_version.startswith('1.1') else |
| 594 | '_jdk11' + postfix) |
| 595 | library_jar = DESUGAR_JDK_LIBS + postfix + '.jar' |
| 596 | library_archive = DESUGAR_JDK_LIBS + archive_postfix + '.zip' |
| 597 | configuration_archive = DESUGAR_JDK_LIBS_CONFIGURATION + archive_postfix + '.zip' |
| 598 | library_gfile = ('/bigstore/r8-releases/raw/%s/%s/%s' % |
| 599 | (DESUGAR_JDK_LIBS + group_postfix, |
| 600 | library_version, library_archive)) |
| 601 | configuration_gfile = ( |
| 602 | '/bigstore/r8-releases/raw/main/%s/%s' % |
| 603 | (configuration_version, configuration_archive)) |
Søren Gjesse | 975c5df | 2019-12-10 13:48:05 +0100 | [diff] [blame] | 604 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 605 | download_gfile(library_gfile, library_archive) |
| 606 | download_gfile(configuration_gfile, configuration_archive) |
| 607 | check_configuration(configuration_archive, group_postfix) |
| 608 | artifacts.append(library_gfile) |
| 609 | artifacts.append(configuration_gfile) |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 610 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 611 | release_id = gmaven_publisher_stage(args, artifacts) |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 612 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 613 | print("Staged Release ID " + release_id + ".\n") |
| 614 | library_artifact_id = \ |
| 615 | '%s:%s:%s' % (ANDROID_TOOLS_PACKAGE, DESUGAR_JDK_LIBS, library_version) |
| 616 | gmaven_publisher_stage_redir_test_info(release_id, |
| 617 | library_artifact_id, |
| 618 | library_jar) |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 619 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 620 | print("") |
| 621 | answer = input("Continue with publishing [y/N]:") |
Søren Gjesse | 975c5df | 2019-12-10 13:48:05 +0100 | [diff] [blame] | 622 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 623 | if answer != 'y': |
| 624 | print('Aborting release to Google maven') |
| 625 | sys.exit(1) |
Søren Gjesse | 975c5df | 2019-12-10 13:48:05 +0100 | [diff] [blame] | 626 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 627 | gmaven_publisher_publish(args, release_id) |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 628 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 629 | print("") |
| 630 | print("Published. Use the email workflow for approval.") |
Søren Gjesse | 975c5df | 2019-12-10 13:48:05 +0100 | [diff] [blame] | 631 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 632 | return make_release |
Søren Gjesse | 975c5df | 2019-12-10 13:48:05 +0100 | [diff] [blame] | 633 | |
| 634 | |
Søren Gjesse | 3e45909 | 2023-01-05 09:40:28 +0100 | [diff] [blame] | 635 | def check_configuration(configuration_archive, postfix): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 636 | zip = zipfile.ZipFile(configuration_archive) |
| 637 | zip.extractall() |
| 638 | dirs = os.listdir( |
| 639 | os.path.join('com', 'android', 'tools', |
| 640 | DESUGAR_JDK_LIBS_CONFIGURATION + postfix)) |
| 641 | if len(dirs) != 1: |
| 642 | print('Unexpected archive content, %s' + dirs) |
| 643 | sys.exit(1) |
Søren Gjesse | 975c5df | 2019-12-10 13:48:05 +0100 | [diff] [blame] | 644 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 645 | version = dirs[0] |
| 646 | pom_file = os.path.join( |
| 647 | 'com', 'android', 'tools', DESUGAR_JDK_LIBS_CONFIGURATION + postfix, |
| 648 | version, |
| 649 | '%s-%s.pom' % (DESUGAR_JDK_LIBS_CONFIGURATION + postfix, version)) |
| 650 | version_from_pom = extract_version_from_pom(pom_file) |
| 651 | if version != version_from_pom: |
| 652 | print('Version mismatch, %s != %s' % (version, version_from_pom)) |
| 653 | sys.exit(1) |
| 654 | |
Søren Gjesse | 07b6aea | 2019-12-12 11:11:58 +0100 | [diff] [blame] | 655 | |
| 656 | def check_no_google3_client(args, client_name): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 657 | if not args.use_existing_work_branch: |
| 658 | clients = subprocess.check_output('g4 myclients', |
| 659 | shell=True).decode('utf-8') |
| 660 | if ':%s:' % client_name in clients: |
| 661 | if args.delete_work_branch: |
| 662 | subprocess.check_call('g4 citc -d -f %s' % client_name, |
| 663 | shell=True) |
| 664 | else: |
| 665 | print(("Remove the existing '%s' client before continuing " + |
| 666 | "(force delete: 'g4 citc -d -f %s'), " + |
| 667 | "or use either --use-existing-work-branch or " + |
| 668 | "--delete-work-branch.") % (client_name, client_name)) |
| 669 | sys.exit(1) |
Søren Gjesse | 07b6aea | 2019-12-12 11:11:58 +0100 | [diff] [blame] | 670 | |
| 671 | |
Søren Gjesse | 975c5df | 2019-12-10 13:48:05 +0100 | [diff] [blame] | 672 | def extract_version_from_pom(pom_file): |
| 673 | ns = "http://maven.apache.org/POM/4.0.0" |
| 674 | xml.etree.ElementTree.register_namespace('', ns) |
| 675 | tree = xml.etree.ElementTree.ElementTree() |
| 676 | tree.parse(pom_file) |
| 677 | return tree.getroot().find("{%s}version" % ns).text |
| 678 | |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 679 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 680 | GMAVEN_PUBLISH_STAGE_RELEASE_ID_PATTERN = re.compile( |
| 681 | 'Release ID = ([0-9a-f\-]+)') |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 682 | |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 683 | |
| 684 | def gmaven_publisher_stage(args, gfiles): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 685 | if args.dry_run: |
| 686 | print('Dry-run, would have staged %s' % gfiles) |
| 687 | return 'dry-run-release-id' |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 688 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 689 | print("Staging: %s" % ', '.join(gfiles)) |
| 690 | print("") |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 691 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 692 | cmd = [GMAVEN_PUBLISHER, 'stage', '--gfile', ','.join(gfiles)] |
| 693 | output = subprocess.check_output(cmd) |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 694 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 695 | # Expect output to contain: |
| 696 | # [INFO] 06/19/2020 09:35:12 CEST: >>>>>>>>>> Staged |
| 697 | # [INFO] 06/19/2020 09:35:12 CEST: Release ID = 9171d015-18f6-4a90-9984-1c362589dc1b |
| 698 | # [INFO] 06/19/2020 09:35:12 CEST: Stage Path = /bigstore/studio_staging/maven2/sgjesse/9171d015-18f6-4a90-9984-1c362589dc1b |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 699 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 700 | matches = GMAVEN_PUBLISH_STAGE_RELEASE_ID_PATTERN.findall( |
| 701 | output.decode("utf-8")) |
| 702 | if matches == None or len(matches) > 1: |
| 703 | print("Could not determine the release ID from the gmaven_publisher " + |
| 704 | "output. Expected a line with 'Release ID = <release id>'.") |
| 705 | print("Output was:") |
| 706 | print(output) |
| 707 | sys.exit(1) |
| 708 | |
Morten Krogh-Jespersen | 8a4d1ca | 2021-01-19 08:27:02 +0100 | [diff] [blame] | 709 | print(output) |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 710 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 711 | release_id = matches[0] |
| 712 | return release_id |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 713 | |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 714 | |
| 715 | def gmaven_publisher_stage_redir_test_info(release_id, artifact, dst): |
| 716 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 717 | redir_command = ("/google/data/ro/teams/android-devtools-infra/tools/redir " |
| 718 | + "--alsologtostderr " + |
| 719 | "--gcs_bucket_path=/bigstore/gmaven-staging/${USER}/%s " + |
| 720 | "--port=1480") % release_id |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 721 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 722 | get_command = ( |
| 723 | "mvn org.apache.maven.plugins:maven-dependency-plugin:2.4:get " + |
| 724 | "-Dmaven.repo.local=/tmp/maven_repo_local " + |
| 725 | "-DremoteRepositories=http://localhost:1480 " + "-Dartifact=%s " + |
| 726 | "-Ddest=%s") % (artifact, dst) |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 727 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 728 | print("""To test the staged content with 'redir' run: |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 729 | |
| 730 | %s |
| 731 | |
Søren Gjesse | 3d3a920 | 2023-11-02 11:04:28 +0100 | [diff] [blame] | 732 | Then add the following repository to settings.gradle.kts (Kotlin Script) to |
| 733 | search the 'redir' repository: |
| 734 | |
| 735 | dependencyResolutionManagement { |
| 736 | repositories { |
| 737 | maven { |
| 738 | url = uri("http://localhost:1480") |
| 739 | isAllowInsecureProtocol = true |
| 740 | } |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | or the following to settings.gradle (Groovy); |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 745 | |
Søren Gjesse | e78b165 | 2022-06-30 12:38:36 +0200 | [diff] [blame] | 746 | dependencyResolutionManagement { |
| 747 | repositories { |
| 748 | maven { |
| 749 | url 'http://localhost:1480' |
| 750 | allowInsecureProtocol true |
| 751 | } |
Søren Gjesse | 44eee51 | 2021-09-24 11:44:11 +0200 | [diff] [blame] | 752 | } |
Søren Gjesse | e78b165 | 2022-06-30 12:38:36 +0200 | [diff] [blame] | 753 | } |
| 754 | |
Søren Gjesse | 3d3a920 | 2023-11-02 11:04:28 +0100 | [diff] [blame] | 755 | and add the following repository to gradle.build.kts (Kotlin Script) for the |
| 756 | staged version: |
| 757 | |
| 758 | coreLibraryDesugaring("%s") { |
| 759 | isChanging = true |
| 760 | } |
| 761 | |
| 762 | or the following to settings.gradle (Groovy); |
Søren Gjesse | e78b165 | 2022-06-30 12:38:36 +0200 | [diff] [blame] | 763 | |
| 764 | dependencies { |
| 765 | coreLibraryDesugaring('%s') { |
| 766 | changing = true |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 767 | } |
| 768 | } |
| 769 | |
| 770 | Use this commands to get artifact from 'redir': |
| 771 | |
| 772 | rm -rf /tmp/maven_repo_local |
| 773 | %s |
Søren Gjesse | 3d3a920 | 2023-11-02 11:04:28 +0100 | [diff] [blame] | 774 | """ % (redir_command, artifact, artifact, get_command)) |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 775 | |
| 776 | |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 777 | def gmaven_publisher_publish(args, release_id): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 778 | if args.dry_run: |
| 779 | print('Dry-run, would have published %s' % release_id) |
| 780 | return |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 781 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 782 | cmd = [GMAVEN_PUBLISHER, 'publish', release_id] |
| 783 | output = subprocess.check_output(cmd) |
| 784 | |
Søren Gjesse | 975c5df | 2019-12-10 13:48:05 +0100 | [diff] [blame] | 785 | |
Søren Gjesse | ddeb02e | 2019-11-06 15:48:07 +0100 | [diff] [blame] | 786 | def branch_change_diff(diff, old_version, new_version): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 787 | invalid_line = None |
| 788 | for line in str(diff).splitlines(): |
| 789 | if line.startswith('-R8') and \ |
| 790 | line != "-R8_DEV_BRANCH = '%s'" % old_version: |
| 791 | print(line) |
| 792 | invalid_line = line |
| 793 | elif line.startswith('+R8') and \ |
| 794 | line != "+R8_DEV_BRANCH = '%s'" % new_version: |
| 795 | print(line) |
| 796 | invalid_line = line |
| 797 | return invalid_line |
Søren Gjesse | ddeb02e | 2019-11-06 15:48:07 +0100 | [diff] [blame] | 798 | |
| 799 | |
| 800 | def validate_branch_change_diff(version_diff_output, old_version, new_version): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 801 | invalid = branch_change_diff(version_diff_output, old_version, new_version) |
| 802 | if invalid: |
| 803 | print("") |
| 804 | print( |
| 805 | "The diff for the branch change in tools/release.py is not as expected:" |
| 806 | ) |
| 807 | print("") |
| 808 | print("=" * 80) |
| 809 | print(version_diff_output) |
| 810 | print("=" * 80) |
| 811 | print("") |
| 812 | print("Validate the uploaded CL before landing.") |
| 813 | print("") |
Søren Gjesse | ddeb02e | 2019-11-06 15:48:07 +0100 | [diff] [blame] | 814 | |
| 815 | |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 816 | def prepare_branch(args): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 817 | branch_version = args.new_dev_branch[0] |
| 818 | commithash = args.new_dev_branch[1] |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 819 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 820 | current_semver = utils.check_basic_semver_version( |
| 821 | R8_DEV_BRANCH, ", current release branch version should be x.y", 2) |
| 822 | semver = utils.check_basic_semver_version( |
| 823 | branch_version, ", release branch version should be x.y", 2) |
| 824 | if not semver.larger_than(current_semver): |
| 825 | print('New branch version "' + branch_version + |
| 826 | '" must be strictly larger than the current "' + R8_DEV_BRANCH + |
| 827 | '"') |
| 828 | sys.exit(1) |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 829 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 830 | def make_branch(options): |
| 831 | with utils.TempDir() as temp: |
| 832 | subprocess.check_call(['git', 'clone', utils.REPO_SOURCE, temp]) |
| 833 | with utils.ChangedWorkingDirectory(temp): |
| 834 | subprocess.check_call( |
| 835 | ['git', 'branch', branch_version, commithash]) |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 836 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 837 | subprocess.check_call(['git', 'checkout', branch_version]) |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 838 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 839 | # Rewrite the version, commit and validate. |
| 840 | old_version = 'main' |
| 841 | full_version = branch_version + '.0-dev' |
| 842 | version_prefix = 'public static final String LABEL = "' |
| 843 | sed(version_prefix + old_version, version_prefix + full_version, |
| 844 | R8_VERSION_FILE) |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 845 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 846 | subprocess.check_call( |
| 847 | ['git', 'commit', '-a', '-m', |
| 848 | 'Version %s' % full_version]) |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 849 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 850 | version_diff_output = subprocess.check_output( |
| 851 | ['git', 'diff', '%s..HEAD' % commithash]) |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 852 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 853 | validate_version_change_diff(version_diff_output, old_version, |
| 854 | full_version) |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 855 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 856 | # Double check that we want to create a new release branch. |
| 857 | if not options.dry_run: |
| 858 | answer = input('Create new branch for %s [y/N]:' % |
| 859 | branch_version) |
| 860 | if answer != 'y': |
| 861 | print('Aborting new branch for %s' % branch_version) |
| 862 | sys.exit(1) |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 863 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 864 | maybe_check_call( |
| 865 | options, |
| 866 | ['git', 'push', 'origin', |
| 867 | 'HEAD:%s' % branch_version]) |
| 868 | maybe_tag(options, full_version) |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 869 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 870 | print( |
| 871 | 'Updating tools/r8_release.py to make new dev releases on %s' |
| 872 | % branch_version) |
Søren Gjesse | ddeb02e | 2019-11-06 15:48:07 +0100 | [diff] [blame] | 873 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 874 | subprocess.check_call( |
| 875 | ['git', 'new-branch', 'update-release-script']) |
Søren Gjesse | ddeb02e | 2019-11-06 15:48:07 +0100 | [diff] [blame] | 876 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 877 | # Check this file for the setting of the current dev branch. |
| 878 | result = None |
| 879 | for line in open(THIS_FILE_RELATIVE, 'r'): |
| 880 | result = re.match(r"^R8_DEV_BRANCH = '(\d+).(\d+)'", line) |
| 881 | if result: |
| 882 | break |
| 883 | if not result or not result.group(1): |
| 884 | print('Failed to find version label in %s' % |
| 885 | THIS_FILE_RELATIVE) |
| 886 | sys.exit(1) |
Søren Gjesse | ddeb02e | 2019-11-06 15:48:07 +0100 | [diff] [blame] | 887 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 888 | # Update this file with the new dev branch. |
| 889 | sed( |
| 890 | "R8_DEV_BRANCH = '%s.%s" % |
| 891 | (result.group(1), result.group(2)), |
| 892 | "R8_DEV_BRANCH = '%s.%s" % |
| 893 | (str(semver.major), str(semver.minor)), THIS_FILE_RELATIVE) |
Søren Gjesse | ddeb02e | 2019-11-06 15:48:07 +0100 | [diff] [blame] | 894 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 895 | message = \ |
| 896 | 'Prepare %s for branch %s' % (THIS_FILE_RELATIVE, branch_version) |
| 897 | subprocess.check_call(['git', 'commit', '-a', '-m', message]) |
Søren Gjesse | ddeb02e | 2019-11-06 15:48:07 +0100 | [diff] [blame] | 898 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 899 | branch_diff_output = subprocess.check_output( |
| 900 | ['git', 'diff', 'HEAD~']) |
Søren Gjesse | ddeb02e | 2019-11-06 15:48:07 +0100 | [diff] [blame] | 901 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 902 | validate_branch_change_diff(branch_diff_output, R8_DEV_BRANCH, |
| 903 | branch_version) |
Søren Gjesse | ddeb02e | 2019-11-06 15:48:07 +0100 | [diff] [blame] | 904 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 905 | maybe_check_call(options, |
| 906 | ['git', 'cl', 'upload', '-f', '-m', message]) |
Søren Gjesse | ddeb02e | 2019-11-06 15:48:07 +0100 | [diff] [blame] | 907 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 908 | print('') |
| 909 | print('Make sure to send out the branch change CL for review.') |
| 910 | print('') |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 911 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 912 | return make_branch |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 913 | |
| 914 | |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 915 | def parse_options(): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 916 | result = argparse.ArgumentParser(description='Release r8') |
| 917 | group = result.add_mutually_exclusive_group() |
| 918 | group.add_argument('--dev-release', |
| 919 | metavar=('<main hash>'), |
| 920 | help='The hash to use for the new dev version of R8') |
| 921 | group.add_argument( |
| 922 | '--version', |
| 923 | metavar=('<version>'), |
| 924 | help= |
| 925 | 'The new version of R8 (e.g., 1.4.51) to release to selected channels') |
| 926 | group.add_argument( |
| 927 | '--desugar-library', |
| 928 | nargs=2, |
| 929 | metavar=('<version>', '<configuration hash>'), |
| 930 | help='The new version of com.android.tools:desugar_jdk_libs') |
| 931 | group.add_argument( |
| 932 | '--update-desugar-library-in-studio', |
| 933 | nargs=2, |
| 934 | metavar=('<version>', '<configuration version>'), |
| 935 | help='Update studio mirror of com.android.tools:desugar_jdk_libs') |
| 936 | group.add_argument( |
| 937 | '--new-dev-branch', |
| 938 | nargs=2, |
| 939 | metavar=('<version>', '<main hash>'), |
| 940 | help='Create a new branch starting a version line (e.g. 2.0)') |
| 941 | result.add_argument('--dev-pre-cherry-pick', |
| 942 | metavar=('<main hash(s)>'), |
| 943 | default=[], |
| 944 | action='append', |
| 945 | help='List of commits to cherry pick before doing full ' |
| 946 | 'merge, mostly used for reverting cherry picks') |
| 947 | result.add_argument('--no-sync', |
| 948 | '--no_sync', |
| 949 | default=False, |
| 950 | action='store_true', |
| 951 | help='Do not sync repos before uploading') |
| 952 | result.add_argument('--bug', |
| 953 | metavar=('<bug(s)>'), |
| 954 | default=[], |
| 955 | action='append', |
| 956 | help='List of bugs for release version') |
| 957 | result.add_argument('--no-bugs', |
| 958 | default=False, |
| 959 | action='store_true', |
| 960 | help='Allow Studio release without specifying any bugs') |
| 961 | result.add_argument( |
| 962 | '--studio', |
| 963 | metavar=('<path>'), |
| 964 | help='Release for studio by setting the path to a studio ' |
| 965 | 'checkout') |
Søren Gjesse | 25e6191 | 2023-11-06 16:02:07 +0100 | [diff] [blame] | 966 | result.add_argument('--studio-legacy-release', |
| 967 | default=False, |
| 968 | action='store_true', |
| 969 | help='Allow Studio release using the legacy process') |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 970 | result.add_argument('--aosp', |
| 971 | metavar=('<path>'), |
| 972 | help='Release for aosp by setting the path to the ' |
| 973 | 'checkout') |
| 974 | result.add_argument('--maven', |
| 975 | default=False, |
| 976 | action='store_true', |
| 977 | help='Release to Google Maven') |
| 978 | result.add_argument('--google3', |
| 979 | default=False, |
| 980 | action='store_true', |
| 981 | help='Release for google 3') |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 982 | result.add_argument('--p4-client', |
| 983 | default='update-r8', |
| 984 | metavar=('<client name>'), |
| 985 | help='P4 client name for google 3') |
| 986 | result.add_argument( |
| 987 | '--use-existing-work-branch', |
| 988 | '--use_existing_work_branch', |
| 989 | default=False, |
| 990 | action='store_true', |
| 991 | help='Use existing work branch/CL in aosp/studio/google3') |
| 992 | result.add_argument('--delete-work-branch', |
| 993 | '--delete_work_branch', |
| 994 | default=False, |
| 995 | action='store_true', |
| 996 | help='Delete CL in google3') |
| 997 | result.add_argument('--bypass-hooks', |
| 998 | '--bypass_hooks', |
| 999 | default=False, |
| 1000 | action='store_true', |
| 1001 | help="Bypass hooks when uploading") |
| 1002 | result.add_argument('--no-upload', |
| 1003 | '--no_upload', |
| 1004 | default=False, |
| 1005 | action='store_true', |
| 1006 | help="Don't upload for code review") |
| 1007 | result.add_argument( |
| 1008 | '--dry-run', |
| 1009 | default=False, |
| 1010 | action='store_true', |
| 1011 | help='Only perform non-commiting tasks and print others.') |
| 1012 | result.add_argument('--dry-run-output', |
| 1013 | '--dry_run_output', |
| 1014 | default=os.getcwd(), |
| 1015 | metavar=('<path>'), |
| 1016 | help='Location for dry run output.') |
| 1017 | args = result.parse_args() |
| 1018 | if (len(args.bug) > 0 and args.no_bugs): |
| 1019 | print("Use of '--bug' and '--no-bugs' are mutually exclusive") |
| 1020 | sys.exit(1) |
Søren Gjesse | 5aa4a68 | 2022-08-26 09:17:27 +0200 | [diff] [blame] | 1021 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1022 | if (args.studio and args.version and not 'dev' in args.version and |
| 1023 | args.bug == [] and not args.no_bugs): |
| 1024 | print("When releasing a release version to Android Studio add the " + |
| 1025 | "list of bugs by using '--bug'") |
| 1026 | sys.exit(1) |
Morten Krogh-Jespersen | a1396cd | 2019-10-02 16:14:40 +0200 | [diff] [blame] | 1027 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1028 | if args.version and not 'dev' in args.version and args.google3: |
| 1029 | print("WARNING: You should not roll a release version into google 3") |
Morten Krogh-Jespersen | 52d3ab0 | 2019-10-29 08:57:06 +0100 | [diff] [blame] | 1030 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1031 | return args |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 1032 | |
| 1033 | |
| 1034 | def main(): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1035 | args = parse_options() |
| 1036 | targets_to_run = [] |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 1037 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1038 | if args.new_dev_branch: |
| 1039 | if args.google3 or args.studio or args.aosp: |
| 1040 | print('Cannot create a branch and roll at the same time.') |
| 1041 | sys.exit(1) |
| 1042 | targets_to_run.append(prepare_branch(args)) |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 1043 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1044 | if args.dev_release: |
| 1045 | if args.google3 or args.studio or args.aosp: |
| 1046 | print('Cannot create a dev release and roll at the same time.') |
| 1047 | sys.exit(1) |
| 1048 | targets_to_run.append(prepare_release(args)) |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 1049 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1050 | if (args.google3 or args.maven or (args.studio and not args.no_sync) or |
| 1051 | (args.desugar_library and not args.dry_run)): |
| 1052 | utils.check_gcert() |
Søren Gjesse | b8dec61 | 2019-10-10 09:15:43 +0200 | [diff] [blame] | 1053 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1054 | if args.google3: |
| 1055 | targets_to_run.append(prepare_google3(args)) |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1056 | if args.studio and not args.update_desugar_library_in_studio: |
| 1057 | targets_to_run.append(prepare_studio(args)) |
| 1058 | if args.aosp: |
| 1059 | targets_to_run.append(prepare_aosp(args)) |
| 1060 | if args.maven: |
| 1061 | targets_to_run.append(prepare_maven(args)) |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 1062 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1063 | if args.desugar_library: |
| 1064 | targets_to_run.append(prepare_desugar_library(args)) |
Søren Gjesse | 975c5df | 2019-12-10 13:48:05 +0100 | [diff] [blame] | 1065 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1066 | if args.update_desugar_library_in_studio: |
| 1067 | if not args.studio: |
| 1068 | print("--studio required") |
| 1069 | sys.exit(1) |
| 1070 | if args.bug == []: |
| 1071 | print( |
| 1072 | "Update studio mirror of com.android.tools:desugar_jdk_libs " + |
| 1073 | "requires at least one bug by using '--bug'") |
| 1074 | sys.exit(1) |
| 1075 | targets_to_run.append(update_desugar_library_in_studio(args)) |
Søren Gjesse | 73355ec | 2020-06-29 09:19:44 +0200 | [diff] [blame] | 1076 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1077 | final_results = [] |
| 1078 | for target_closure in targets_to_run: |
| 1079 | final_results.append(target_closure(args)) |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 1080 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1081 | print('\n\n**************************************************************') |
| 1082 | print('PRINTING SUMMARY') |
| 1083 | print('**************************************************************\n\n') |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 1084 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1085 | for result in final_results: |
| 1086 | if result is not None: |
| 1087 | print(result) |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 1088 | |
| 1089 | |
| 1090 | if __name__ == '__main__': |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1091 | sys.exit(main()) |