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') |
| 427 | g4_open('retrace_full.jar') |
| 428 | g4_open('retrace_lib.jar') |
| 429 | g4_open('retrace_lib.jar.map') |
| 430 | g4_open('desugar_jdk_libs_configuration.jar') |
Ian Zerny | 68f5c13 | 2023-11-01 12:57:07 +0100 | [diff] [blame] | 431 | g4_open('threading-module-blocking.jar') |
| 432 | g4_open('threading-module-single-threaded.jar') |
| 433 | download_file(options.version, |
| 434 | 'r8-full-exclude-deps.jar', |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 435 | 'full.jar') |
Ian Zerny | 68f5c13 | 2023-11-01 12:57:07 +0100 | [diff] [blame] | 436 | download_file(options.version, |
| 437 | 'r8-full-exclude-deps.jar', |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 438 | 'retrace_full.jar') |
Ian Zerny | 68f5c13 | 2023-11-01 12:57:07 +0100 | [diff] [blame] | 439 | download_file(options.version, |
| 440 | 'r8-src.jar', |
| 441 | 'src.jar') |
| 442 | download_file(options.version, |
| 443 | 'r8lib-exclude-deps.jar', |
| 444 | 'lib.jar') |
| 445 | download_file(options.version, |
| 446 | 'r8lib-exclude-deps.jar.map', |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 447 | 'lib.jar.map') |
Ian Zerny | 68f5c13 | 2023-11-01 12:57:07 +0100 | [diff] [blame] | 448 | download_file(options.version, |
| 449 | 'desugar_jdk_libs_configuration.jar', |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 450 | 'desugar_jdk_libs_configuration.jar') |
Ian Zerny | 68f5c13 | 2023-11-01 12:57:07 +0100 | [diff] [blame] | 451 | download_file(options.version, |
| 452 | 'r8retrace-exclude-deps.jar', |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 453 | 'retrace_lib.jar') |
Ian Zerny | 68f5c13 | 2023-11-01 12:57:07 +0100 | [diff] [blame] | 454 | download_file(options.version, |
| 455 | 'r8retrace-exclude-deps.jar.map', |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 456 | 'retrace_lib.jar.map') |
Ian Zerny | 68f5c13 | 2023-11-01 12:57:07 +0100 | [diff] [blame] | 457 | download_file(options.version, |
| 458 | 'threading-module-blocking.jar', |
| 459 | 'threading-module-blocking.jar') |
| 460 | download_file(options.version, |
| 461 | 'threading-module-single-threaded.jar', |
| 462 | 'threading-module-single-threaded.jar') |
| 463 | if options.version != 'main': |
| 464 | g4_open('METADATA') |
| 465 | metadata_path = os.path.join(third_party_r8, 'METADATA') |
| 466 | match_count = 0 |
| 467 | match_count_expected = 12 |
| 468 | version_match_regexp = r'[1-9]\.[0-9]{1,2}\.[0-9]{1,3}-dev' |
| 469 | for line in open(metadata_path, 'r'): |
| 470 | result = re.search(version_match_regexp, line) |
| 471 | if result: |
| 472 | match_count = match_count + 1 |
| 473 | if match_count != match_count_expected: |
| 474 | print(f"""WARNING: |
| 475 | Could not find the previous -dev release string to replace in METADATA. |
| 476 | Expected to find it mentioned {match_count_expected} times, but found |
| 477 | {match_count} occurrences. Please update {metadata_path} manually and |
| 478 | run again with options --google3 --use-existing-work-branch. |
| 479 | """) |
| 480 | sys.exit(1) |
| 481 | sed(version_match_regexp, options.version, metadata_path) |
| 482 | sed(r'\{ year.*\}', |
| 483 | f'{{ year: {today.year} month: {today.month} day: {today.day} }}', |
| 484 | metadata_path) |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 485 | subprocess.check_output('chmod u+w *', shell=True) |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 486 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 487 | with utils.ChangedWorkingDirectory(google3_base): |
| 488 | blaze_result = blaze_run('//third_party/java/r8:d8 -- --version') |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 489 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 490 | assert options.version in blaze_result |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 491 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 492 | if not options.no_upload: |
| 493 | change_result = g4_change(options.version) |
| 494 | change_result += 'Run \'(g4d ' + args.p4_client \ |
| 495 | + ' && tap_presubmit -p all --train -c ' \ |
| 496 | + get_cl_id(change_result) + ')\' for running TAP global' \ |
| 497 | + ' presubmit using the train.\n' \ |
| 498 | + 'Run \'(g4d ' + args.p4_client \ |
| 499 | + ' && tap_presubmit -p all --notrain --detach --email' \ |
| 500 | + ' --skip_flaky_targets --skip_already_failing -c ' \ |
| 501 | + get_cl_id(change_result) + ')\' for running an isolated' \ |
| 502 | + ' TAP global presubmit.' |
| 503 | return change_result |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 504 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 505 | return release_google3 |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 506 | |
| 507 | |
Morten Krogh-Jespersen | 0452794 | 2022-08-02 13:50:11 +0200 | [diff] [blame] | 508 | def prepare_google3_retrace(args): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 509 | assert args.version |
| 510 | # Check if an existing client exists. |
| 511 | if not args.use_existing_work_branch: |
| 512 | check_no_google3_client(args, args.p4_client) |
Morten Krogh-Jespersen | 0452794 | 2022-08-02 13:50:11 +0200 | [diff] [blame] | 513 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 514 | def release_google3_retrace(options): |
| 515 | print("Releasing Retrace for Google 3") |
| 516 | if options.dry_run: |
| 517 | return 'DryRun: omitting g3 release for %s' % options.version |
Morten Krogh-Jespersen | 0452794 | 2022-08-02 13:50:11 +0200 | [diff] [blame] | 518 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 519 | google3_base = subprocess.check_output( |
| 520 | ['p4', 'g4d', '-f', args.p4_client]).decode('utf-8').rstrip() |
| 521 | third_party_r8 = os.path.join(google3_base, 'third_party', 'java', 'r8') |
| 522 | with utils.ChangedWorkingDirectory(third_party_r8): |
| 523 | # download files |
| 524 | g4_open('retrace_full.jar') |
| 525 | g4_open('retrace_lib.jar') |
| 526 | g4_open('retrace_lib.jar.map') |
| 527 | download_file(options.version, 'r8-full-exclude-deps.jar', |
| 528 | 'retrace_full.jar') |
| 529 | download_file(options.version, 'r8retrace-exclude-deps.jar', |
| 530 | 'retrace_lib.jar') |
| 531 | download_file(options.version, 'r8lib-exclude-deps.jar.map', |
| 532 | 'retrace_lib.jar.map') |
| 533 | g4_open('METADATA') |
| 534 | metadata_path = os.path.join(third_party_r8, 'METADATA') |
| 535 | match_count = 0 |
| 536 | version_match_regexp = r'[1-9]\.[0-9]{1,2}\.[0-9]{1,3}-dev/r8retrace-exclude-deps.jar' |
| 537 | for line in open(metadata_path, 'r'): |
| 538 | result = re.search(version_match_regexp, line) |
| 539 | if result: |
| 540 | match_count = match_count + 1 |
| 541 | if match_count != 1: |
| 542 | print(( |
| 543 | "Could not find the previous retrace release string to replace in " |
| 544 | + |
| 545 | "METADATA. Expected to find is mentioned 1 times. Please update %s " |
| 546 | + "manually and run again with options --google3retrace " + |
| 547 | "--use-existing-work-branch.") % metadata_path) |
| 548 | sys.exit(1) |
| 549 | sed(version_match_regexp, |
| 550 | options.version + "/r8retrace-exclude-deps.jar", metadata_path) |
| 551 | subprocess.check_output('chmod u+w *', shell=True) |
Morten Krogh-Jespersen | 0452794 | 2022-08-02 13:50:11 +0200 | [diff] [blame] | 552 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 553 | with utils.ChangedWorkingDirectory(google3_base): |
| 554 | blaze_result = blaze_run( |
| 555 | '//third_party/java/r8:retrace -- --version') |
Morten Krogh-Jespersen | 0452794 | 2022-08-02 13:50:11 +0200 | [diff] [blame] | 556 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 557 | print(blaze_result) |
| 558 | assert options.version in blaze_result |
Morten Krogh-Jespersen | 0452794 | 2022-08-02 13:50:11 +0200 | [diff] [blame] | 559 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 560 | if not options.no_upload: |
| 561 | change_result = g4_change(options.version) |
| 562 | change_result += 'Run \'(g4d ' + args.p4_client \ |
| 563 | + ' && tap_presubmit -p all --train -c ' \ |
| 564 | + get_cl_id(change_result) + ')\' for running TAP global' \ |
| 565 | + ' presubmit using the train.\n' \ |
| 566 | + 'Run \'(g4d ' + args.p4_client \ |
| 567 | + ' && tap_presubmit -p all --notrain --detach --email' \ |
| 568 | + ' --skip_flaky_targets --skip_already_failing -c ' \ |
| 569 | + get_cl_id(change_result) + ')\' for running an isolated' \ |
| 570 | + ' TAP global presubmit.' |
| 571 | return change_result |
Morten Krogh-Jespersen | 0452794 | 2022-08-02 13:50:11 +0200 | [diff] [blame] | 572 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 573 | return release_google3_retrace |
| 574 | |
Morten Krogh-Jespersen | 0452794 | 2022-08-02 13:50:11 +0200 | [diff] [blame] | 575 | |
Søren Gjesse | 73355ec | 2020-06-29 09:19:44 +0200 | [diff] [blame] | 576 | def update_desugar_library_in_studio(args): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 577 | assert os.path.exists(args.studio), ("Could not find STUDIO path %s" % |
| 578 | args.studio) |
Søren Gjesse | 73355ec | 2020-06-29 09:19:44 +0200 | [diff] [blame] | 579 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 580 | def make_release(args): |
| 581 | library_version = args.update_desugar_library_in_studio[0] |
| 582 | configuration_version = args.update_desugar_library_in_studio[1] |
| 583 | change_name = 'update-desugar-library-dependencies' |
Søren Gjesse | 73355ec | 2020-06-29 09:19:44 +0200 | [diff] [blame] | 584 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 585 | with utils.ChangedWorkingDirectory(args.studio): |
| 586 | if not args.use_existing_work_branch: |
| 587 | subprocess.call(['repo', 'abandon', change_name]) |
| 588 | if not args.no_sync: |
| 589 | subprocess.check_call(['repo', 'sync', '-cq', '-j', '16']) |
Søren Gjesse | 73355ec | 2020-06-29 09:19:44 +0200 | [diff] [blame] | 590 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 591 | cmd = [ |
| 592 | 'tools/base/bazel/bazel', 'run', |
| 593 | '//tools/base/bazel:add_dependency', '--', |
| 594 | '--repo=https://maven.google.com com.android.tools:desugar_jdk_libs:%s' |
| 595 | % library_version |
| 596 | ] |
| 597 | utils.PrintCmd(cmd) |
| 598 | subprocess.check_call(" ".join(cmd), shell=True) |
| 599 | cmd = ['tools/base/bazel/bazel', 'shutdown'] |
| 600 | utils.PrintCmd(cmd) |
| 601 | subprocess.check_call(cmd) |
Søren Gjesse | 73355ec | 2020-06-29 09:19:44 +0200 | [diff] [blame] | 602 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 603 | prebuilts_tools = os.path.join(args.studio, 'prebuilts', 'tools') |
Søren Gjesse | 73355ec | 2020-06-29 09:19:44 +0200 | [diff] [blame] | 604 | with utils.ChangedWorkingDirectory(prebuilts_tools): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 605 | if not args.use_existing_work_branch: |
| 606 | with utils.ChangedWorkingDirectory(prebuilts_tools): |
| 607 | subprocess.check_call(['repo', 'start', change_name]) |
| 608 | m2_dir = os.path.join('common', 'm2', 'repository', 'com', |
| 609 | 'android', 'tools') |
| 610 | subprocess.check_call([ |
| 611 | 'git', 'add', |
| 612 | os.path.join(m2_dir, DESUGAR_JDK_LIBS, library_version) |
| 613 | ]) |
| 614 | subprocess.check_call([ |
| 615 | 'git', 'add', |
| 616 | os.path.join(m2_dir, DESUGAR_JDK_LIBS_CONFIGURATION, |
| 617 | configuration_version) |
| 618 | ]) |
Søren Gjesse | 73355ec | 2020-06-29 09:19:44 +0200 | [diff] [blame] | 619 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 620 | git_message = ("""Update library desugaring dependencies |
Søren Gjesse | 73355ec | 2020-06-29 09:19:44 +0200 | [diff] [blame] | 621 | |
| 622 | com.android.tools:desugar_jdk_libs:%s |
| 623 | com.android.tools:desugar_jdk_libs_configuration:%s |
| 624 | |
| 625 | Bug: %s |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 626 | Test: L8ToolTest, L8DexDesugarTest""" % |
| 627 | (library_version, configuration_version, |
| 628 | '\nBug: '.join(map(bug_fmt, args.bug)))) |
Søren Gjesse | 73355ec | 2020-06-29 09:19:44 +0200 | [diff] [blame] | 629 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 630 | if not args.use_existing_work_branch: |
| 631 | subprocess.check_call( |
| 632 | ['git', 'commit', '-a', '-m', git_message]) |
| 633 | else: |
| 634 | print('Not committing when --use-existing-work-branch. ' + |
| 635 | 'Commit message should be:\n\n' + git_message + '\n') |
| 636 | # Don't upload if requested not to, or if changes are not committed due |
| 637 | # to --use-existing-work-branch |
| 638 | if not args.no_upload and not args.use_existing_work_branch: |
| 639 | process = subprocess.Popen(['repo', 'upload', '.', '--verify'], |
| 640 | stdin=subprocess.PIPE) |
| 641 | return process.communicate(input='y\n')[0] |
Søren Gjesse | 73355ec | 2020-06-29 09:19:44 +0200 | [diff] [blame] | 642 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 643 | return make_release |
Søren Gjesse | 73355ec | 2020-06-29 09:19:44 +0200 | [diff] [blame] | 644 | |
| 645 | |
Søren Gjesse | 975c5df | 2019-12-10 13:48:05 +0100 | [diff] [blame] | 646 | def prepare_desugar_library(args): |
| 647 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 648 | def make_release(args): |
| 649 | library_version = args.desugar_library[0] |
| 650 | configuration_version = args.desugar_library[1] |
Søren Gjesse | 975c5df | 2019-12-10 13:48:05 +0100 | [diff] [blame] | 651 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 652 | # TODO(b/237636871): Cleanup and generalize. |
| 653 | if (not (library_version.startswith('1.1') or |
| 654 | library_version.startswith('1.2') or |
| 655 | library_version.startswith('2.0'))): |
| 656 | print( |
| 657 | "Release script does not support desugared library version %s" % |
| 658 | library_version) |
| 659 | sys.exit(1) |
Søren Gjesse | e78b165 | 2022-06-30 12:38:36 +0200 | [diff] [blame] | 660 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 661 | postfixes = [''] |
| 662 | if library_version.startswith('1.2'): |
| 663 | postfixes = ['_legacy'] |
| 664 | if library_version.startswith('2.0'): |
| 665 | postfixes = ['_minimal', '', '_nio'] |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 666 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 667 | with utils.TempDir() as temp: |
| 668 | with utils.ChangedWorkingDirectory(temp): |
| 669 | artifacts = [] |
| 670 | for postfix in postfixes: |
| 671 | group_postfix = ('' if postfix == '_legacy' else postfix) |
| 672 | archive_postfix = (postfix |
| 673 | if library_version.startswith('1.1') else |
| 674 | '_jdk11' + postfix) |
| 675 | library_jar = DESUGAR_JDK_LIBS + postfix + '.jar' |
| 676 | library_archive = DESUGAR_JDK_LIBS + archive_postfix + '.zip' |
| 677 | configuration_archive = DESUGAR_JDK_LIBS_CONFIGURATION + archive_postfix + '.zip' |
| 678 | library_gfile = ('/bigstore/r8-releases/raw/%s/%s/%s' % |
| 679 | (DESUGAR_JDK_LIBS + group_postfix, |
| 680 | library_version, library_archive)) |
| 681 | configuration_gfile = ( |
| 682 | '/bigstore/r8-releases/raw/main/%s/%s' % |
| 683 | (configuration_version, configuration_archive)) |
Søren Gjesse | 975c5df | 2019-12-10 13:48:05 +0100 | [diff] [blame] | 684 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 685 | download_gfile(library_gfile, library_archive) |
| 686 | download_gfile(configuration_gfile, configuration_archive) |
| 687 | check_configuration(configuration_archive, group_postfix) |
| 688 | artifacts.append(library_gfile) |
| 689 | artifacts.append(configuration_gfile) |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 690 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 691 | release_id = gmaven_publisher_stage(args, artifacts) |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 692 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 693 | print("Staged Release ID " + release_id + ".\n") |
| 694 | library_artifact_id = \ |
| 695 | '%s:%s:%s' % (ANDROID_TOOLS_PACKAGE, DESUGAR_JDK_LIBS, library_version) |
| 696 | gmaven_publisher_stage_redir_test_info(release_id, |
| 697 | library_artifact_id, |
| 698 | library_jar) |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 699 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 700 | print("") |
| 701 | answer = input("Continue with publishing [y/N]:") |
Søren Gjesse | 975c5df | 2019-12-10 13:48:05 +0100 | [diff] [blame] | 702 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 703 | if answer != 'y': |
| 704 | print('Aborting release to Google maven') |
| 705 | sys.exit(1) |
Søren Gjesse | 975c5df | 2019-12-10 13:48:05 +0100 | [diff] [blame] | 706 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 707 | gmaven_publisher_publish(args, release_id) |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 708 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 709 | print("") |
| 710 | print("Published. Use the email workflow for approval.") |
Søren Gjesse | 975c5df | 2019-12-10 13:48:05 +0100 | [diff] [blame] | 711 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 712 | return make_release |
Søren Gjesse | 975c5df | 2019-12-10 13:48:05 +0100 | [diff] [blame] | 713 | |
| 714 | |
Søren Gjesse | 3e45909 | 2023-01-05 09:40:28 +0100 | [diff] [blame] | 715 | def check_configuration(configuration_archive, postfix): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 716 | zip = zipfile.ZipFile(configuration_archive) |
| 717 | zip.extractall() |
| 718 | dirs = os.listdir( |
| 719 | os.path.join('com', 'android', 'tools', |
| 720 | DESUGAR_JDK_LIBS_CONFIGURATION + postfix)) |
| 721 | if len(dirs) != 1: |
| 722 | print('Unexpected archive content, %s' + dirs) |
| 723 | sys.exit(1) |
Søren Gjesse | 975c5df | 2019-12-10 13:48:05 +0100 | [diff] [blame] | 724 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 725 | version = dirs[0] |
| 726 | pom_file = os.path.join( |
| 727 | 'com', 'android', 'tools', DESUGAR_JDK_LIBS_CONFIGURATION + postfix, |
| 728 | version, |
| 729 | '%s-%s.pom' % (DESUGAR_JDK_LIBS_CONFIGURATION + postfix, version)) |
| 730 | version_from_pom = extract_version_from_pom(pom_file) |
| 731 | if version != version_from_pom: |
| 732 | print('Version mismatch, %s != %s' % (version, version_from_pom)) |
| 733 | sys.exit(1) |
| 734 | |
Søren Gjesse | 07b6aea | 2019-12-12 11:11:58 +0100 | [diff] [blame] | 735 | |
| 736 | def check_no_google3_client(args, client_name): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 737 | if not args.use_existing_work_branch: |
| 738 | clients = subprocess.check_output('g4 myclients', |
| 739 | shell=True).decode('utf-8') |
| 740 | if ':%s:' % client_name in clients: |
| 741 | if args.delete_work_branch: |
| 742 | subprocess.check_call('g4 citc -d -f %s' % client_name, |
| 743 | shell=True) |
| 744 | else: |
| 745 | print(("Remove the existing '%s' client before continuing " + |
| 746 | "(force delete: 'g4 citc -d -f %s'), " + |
| 747 | "or use either --use-existing-work-branch or " + |
| 748 | "--delete-work-branch.") % (client_name, client_name)) |
| 749 | sys.exit(1) |
Søren Gjesse | 07b6aea | 2019-12-12 11:11:58 +0100 | [diff] [blame] | 750 | |
| 751 | |
Søren Gjesse | 975c5df | 2019-12-10 13:48:05 +0100 | [diff] [blame] | 752 | def extract_version_from_pom(pom_file): |
| 753 | ns = "http://maven.apache.org/POM/4.0.0" |
| 754 | xml.etree.ElementTree.register_namespace('', ns) |
| 755 | tree = xml.etree.ElementTree.ElementTree() |
| 756 | tree.parse(pom_file) |
| 757 | return tree.getroot().find("{%s}version" % ns).text |
| 758 | |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 759 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 760 | GMAVEN_PUBLISH_STAGE_RELEASE_ID_PATTERN = re.compile( |
| 761 | 'Release ID = ([0-9a-f\-]+)') |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 762 | |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 763 | |
| 764 | def gmaven_publisher_stage(args, gfiles): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 765 | if args.dry_run: |
| 766 | print('Dry-run, would have staged %s' % gfiles) |
| 767 | return 'dry-run-release-id' |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 768 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 769 | print("Staging: %s" % ', '.join(gfiles)) |
| 770 | print("") |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 771 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 772 | cmd = [GMAVEN_PUBLISHER, 'stage', '--gfile', ','.join(gfiles)] |
| 773 | output = subprocess.check_output(cmd) |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 774 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 775 | # Expect output to contain: |
| 776 | # [INFO] 06/19/2020 09:35:12 CEST: >>>>>>>>>> Staged |
| 777 | # [INFO] 06/19/2020 09:35:12 CEST: Release ID = 9171d015-18f6-4a90-9984-1c362589dc1b |
| 778 | # [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] | 779 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 780 | matches = GMAVEN_PUBLISH_STAGE_RELEASE_ID_PATTERN.findall( |
| 781 | output.decode("utf-8")) |
| 782 | if matches == None or len(matches) > 1: |
| 783 | print("Could not determine the release ID from the gmaven_publisher " + |
| 784 | "output. Expected a line with 'Release ID = <release id>'.") |
| 785 | print("Output was:") |
| 786 | print(output) |
| 787 | sys.exit(1) |
| 788 | |
Morten Krogh-Jespersen | 8a4d1ca | 2021-01-19 08:27:02 +0100 | [diff] [blame] | 789 | print(output) |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 790 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 791 | release_id = matches[0] |
| 792 | return release_id |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 793 | |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 794 | |
| 795 | def gmaven_publisher_stage_redir_test_info(release_id, artifact, dst): |
| 796 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 797 | redir_command = ("/google/data/ro/teams/android-devtools-infra/tools/redir " |
| 798 | + "--alsologtostderr " + |
| 799 | "--gcs_bucket_path=/bigstore/gmaven-staging/${USER}/%s " + |
| 800 | "--port=1480") % release_id |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 801 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 802 | get_command = ( |
| 803 | "mvn org.apache.maven.plugins:maven-dependency-plugin:2.4:get " + |
| 804 | "-Dmaven.repo.local=/tmp/maven_repo_local " + |
| 805 | "-DremoteRepositories=http://localhost:1480 " + "-Dartifact=%s " + |
| 806 | "-Ddest=%s") % (artifact, dst) |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 807 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 808 | print("""To test the staged content with 'redir' run: |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 809 | |
| 810 | %s |
| 811 | |
Søren Gjesse | 3d3a920 | 2023-11-02 11:04:28 +0100 | [diff] [blame] | 812 | Then add the following repository to settings.gradle.kts (Kotlin Script) to |
| 813 | search the 'redir' repository: |
| 814 | |
| 815 | dependencyResolutionManagement { |
| 816 | repositories { |
| 817 | maven { |
| 818 | url = uri("http://localhost:1480") |
| 819 | isAllowInsecureProtocol = true |
| 820 | } |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | or the following to settings.gradle (Groovy); |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 825 | |
Søren Gjesse | e78b165 | 2022-06-30 12:38:36 +0200 | [diff] [blame] | 826 | dependencyResolutionManagement { |
| 827 | repositories { |
| 828 | maven { |
| 829 | url 'http://localhost:1480' |
| 830 | allowInsecureProtocol true |
| 831 | } |
Søren Gjesse | 44eee51 | 2021-09-24 11:44:11 +0200 | [diff] [blame] | 832 | } |
Søren Gjesse | e78b165 | 2022-06-30 12:38:36 +0200 | [diff] [blame] | 833 | } |
| 834 | |
Søren Gjesse | 3d3a920 | 2023-11-02 11:04:28 +0100 | [diff] [blame] | 835 | and add the following repository to gradle.build.kts (Kotlin Script) for the |
| 836 | staged version: |
| 837 | |
| 838 | coreLibraryDesugaring("%s") { |
| 839 | isChanging = true |
| 840 | } |
| 841 | |
| 842 | or the following to settings.gradle (Groovy); |
Søren Gjesse | e78b165 | 2022-06-30 12:38:36 +0200 | [diff] [blame] | 843 | |
| 844 | dependencies { |
| 845 | coreLibraryDesugaring('%s') { |
| 846 | changing = true |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 847 | } |
| 848 | } |
| 849 | |
| 850 | Use this commands to get artifact from 'redir': |
| 851 | |
| 852 | rm -rf /tmp/maven_repo_local |
| 853 | %s |
Søren Gjesse | 3d3a920 | 2023-11-02 11:04:28 +0100 | [diff] [blame] | 854 | """ % (redir_command, artifact, artifact, get_command)) |
Søren Gjesse | b093b67 | 2020-06-23 16:23:10 +0200 | [diff] [blame] | 855 | |
| 856 | |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 857 | def gmaven_publisher_publish(args, release_id): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 858 | if args.dry_run: |
| 859 | print('Dry-run, would have published %s' % release_id) |
| 860 | return |
Søren Gjesse | 376b74c | 2020-06-22 08:42:44 +0200 | [diff] [blame] | 861 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 862 | cmd = [GMAVEN_PUBLISHER, 'publish', release_id] |
| 863 | output = subprocess.check_output(cmd) |
| 864 | |
Søren Gjesse | 975c5df | 2019-12-10 13:48:05 +0100 | [diff] [blame] | 865 | |
Søren Gjesse | ddeb02e | 2019-11-06 15:48:07 +0100 | [diff] [blame] | 866 | def branch_change_diff(diff, old_version, new_version): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 867 | invalid_line = None |
| 868 | for line in str(diff).splitlines(): |
| 869 | if line.startswith('-R8') and \ |
| 870 | line != "-R8_DEV_BRANCH = '%s'" % old_version: |
| 871 | print(line) |
| 872 | invalid_line = line |
| 873 | elif line.startswith('+R8') and \ |
| 874 | line != "+R8_DEV_BRANCH = '%s'" % new_version: |
| 875 | print(line) |
| 876 | invalid_line = line |
| 877 | return invalid_line |
Søren Gjesse | ddeb02e | 2019-11-06 15:48:07 +0100 | [diff] [blame] | 878 | |
| 879 | |
| 880 | 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] | 881 | invalid = branch_change_diff(version_diff_output, old_version, new_version) |
| 882 | if invalid: |
| 883 | print("") |
| 884 | print( |
| 885 | "The diff for the branch change in tools/release.py is not as expected:" |
| 886 | ) |
| 887 | print("") |
| 888 | print("=" * 80) |
| 889 | print(version_diff_output) |
| 890 | print("=" * 80) |
| 891 | print("") |
| 892 | print("Validate the uploaded CL before landing.") |
| 893 | print("") |
Søren Gjesse | ddeb02e | 2019-11-06 15:48:07 +0100 | [diff] [blame] | 894 | |
| 895 | |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 896 | def prepare_branch(args): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 897 | branch_version = args.new_dev_branch[0] |
| 898 | commithash = args.new_dev_branch[1] |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 899 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 900 | current_semver = utils.check_basic_semver_version( |
| 901 | R8_DEV_BRANCH, ", current release branch version should be x.y", 2) |
| 902 | semver = utils.check_basic_semver_version( |
| 903 | branch_version, ", release branch version should be x.y", 2) |
| 904 | if not semver.larger_than(current_semver): |
| 905 | print('New branch version "' + branch_version + |
| 906 | '" must be strictly larger than the current "' + R8_DEV_BRANCH + |
| 907 | '"') |
| 908 | sys.exit(1) |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 909 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 910 | def make_branch(options): |
| 911 | with utils.TempDir() as temp: |
| 912 | subprocess.check_call(['git', 'clone', utils.REPO_SOURCE, temp]) |
| 913 | with utils.ChangedWorkingDirectory(temp): |
| 914 | subprocess.check_call( |
| 915 | ['git', 'branch', branch_version, commithash]) |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 916 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 917 | subprocess.check_call(['git', 'checkout', branch_version]) |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 918 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 919 | # Rewrite the version, commit and validate. |
| 920 | old_version = 'main' |
| 921 | full_version = branch_version + '.0-dev' |
| 922 | version_prefix = 'public static final String LABEL = "' |
| 923 | sed(version_prefix + old_version, version_prefix + full_version, |
| 924 | R8_VERSION_FILE) |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 925 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 926 | subprocess.check_call( |
| 927 | ['git', 'commit', '-a', '-m', |
| 928 | 'Version %s' % full_version]) |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 929 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 930 | version_diff_output = subprocess.check_output( |
| 931 | ['git', 'diff', '%s..HEAD' % commithash]) |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 932 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 933 | validate_version_change_diff(version_diff_output, old_version, |
| 934 | full_version) |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 935 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 936 | # Double check that we want to create a new release branch. |
| 937 | if not options.dry_run: |
| 938 | answer = input('Create new branch for %s [y/N]:' % |
| 939 | branch_version) |
| 940 | if answer != 'y': |
| 941 | print('Aborting new branch for %s' % branch_version) |
| 942 | sys.exit(1) |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 943 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 944 | maybe_check_call( |
| 945 | options, |
| 946 | ['git', 'push', 'origin', |
| 947 | 'HEAD:%s' % branch_version]) |
| 948 | maybe_tag(options, full_version) |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 949 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 950 | print( |
| 951 | 'Updating tools/r8_release.py to make new dev releases on %s' |
| 952 | % branch_version) |
Søren Gjesse | ddeb02e | 2019-11-06 15:48:07 +0100 | [diff] [blame] | 953 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 954 | subprocess.check_call( |
| 955 | ['git', 'new-branch', 'update-release-script']) |
Søren Gjesse | ddeb02e | 2019-11-06 15:48:07 +0100 | [diff] [blame] | 956 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 957 | # Check this file for the setting of the current dev branch. |
| 958 | result = None |
| 959 | for line in open(THIS_FILE_RELATIVE, 'r'): |
| 960 | result = re.match(r"^R8_DEV_BRANCH = '(\d+).(\d+)'", line) |
| 961 | if result: |
| 962 | break |
| 963 | if not result or not result.group(1): |
| 964 | print('Failed to find version label in %s' % |
| 965 | THIS_FILE_RELATIVE) |
| 966 | sys.exit(1) |
Søren Gjesse | ddeb02e | 2019-11-06 15:48:07 +0100 | [diff] [blame] | 967 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 968 | # Update this file with the new dev branch. |
| 969 | sed( |
| 970 | "R8_DEV_BRANCH = '%s.%s" % |
| 971 | (result.group(1), result.group(2)), |
| 972 | "R8_DEV_BRANCH = '%s.%s" % |
| 973 | (str(semver.major), str(semver.minor)), THIS_FILE_RELATIVE) |
Søren Gjesse | ddeb02e | 2019-11-06 15:48:07 +0100 | [diff] [blame] | 974 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 975 | message = \ |
| 976 | 'Prepare %s for branch %s' % (THIS_FILE_RELATIVE, branch_version) |
| 977 | subprocess.check_call(['git', 'commit', '-a', '-m', message]) |
Søren Gjesse | ddeb02e | 2019-11-06 15:48:07 +0100 | [diff] [blame] | 978 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 979 | branch_diff_output = subprocess.check_output( |
| 980 | ['git', 'diff', 'HEAD~']) |
Søren Gjesse | ddeb02e | 2019-11-06 15:48:07 +0100 | [diff] [blame] | 981 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 982 | validate_branch_change_diff(branch_diff_output, R8_DEV_BRANCH, |
| 983 | branch_version) |
Søren Gjesse | ddeb02e | 2019-11-06 15:48:07 +0100 | [diff] [blame] | 984 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 985 | maybe_check_call(options, |
| 986 | ['git', 'cl', 'upload', '-f', '-m', message]) |
Søren Gjesse | ddeb02e | 2019-11-06 15:48:07 +0100 | [diff] [blame] | 987 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 988 | print('') |
| 989 | print('Make sure to send out the branch change CL for review.') |
| 990 | print('') |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 991 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 992 | return make_branch |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 993 | |
| 994 | |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 995 | def parse_options(): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 996 | result = argparse.ArgumentParser(description='Release r8') |
| 997 | group = result.add_mutually_exclusive_group() |
| 998 | group.add_argument('--dev-release', |
| 999 | metavar=('<main hash>'), |
| 1000 | help='The hash to use for the new dev version of R8') |
| 1001 | group.add_argument( |
| 1002 | '--version', |
| 1003 | metavar=('<version>'), |
| 1004 | help= |
| 1005 | 'The new version of R8 (e.g., 1.4.51) to release to selected channels') |
| 1006 | group.add_argument( |
| 1007 | '--desugar-library', |
| 1008 | nargs=2, |
| 1009 | metavar=('<version>', '<configuration hash>'), |
| 1010 | help='The new version of com.android.tools:desugar_jdk_libs') |
| 1011 | group.add_argument( |
| 1012 | '--update-desugar-library-in-studio', |
| 1013 | nargs=2, |
| 1014 | metavar=('<version>', '<configuration version>'), |
| 1015 | help='Update studio mirror of com.android.tools:desugar_jdk_libs') |
| 1016 | group.add_argument( |
| 1017 | '--new-dev-branch', |
| 1018 | nargs=2, |
| 1019 | metavar=('<version>', '<main hash>'), |
| 1020 | help='Create a new branch starting a version line (e.g. 2.0)') |
| 1021 | result.add_argument('--dev-pre-cherry-pick', |
| 1022 | metavar=('<main hash(s)>'), |
| 1023 | default=[], |
| 1024 | action='append', |
| 1025 | help='List of commits to cherry pick before doing full ' |
| 1026 | 'merge, mostly used for reverting cherry picks') |
| 1027 | result.add_argument('--no-sync', |
| 1028 | '--no_sync', |
| 1029 | default=False, |
| 1030 | action='store_true', |
| 1031 | help='Do not sync repos before uploading') |
| 1032 | result.add_argument('--bug', |
| 1033 | metavar=('<bug(s)>'), |
| 1034 | default=[], |
| 1035 | action='append', |
| 1036 | help='List of bugs for release version') |
| 1037 | result.add_argument('--no-bugs', |
| 1038 | default=False, |
| 1039 | action='store_true', |
| 1040 | help='Allow Studio release without specifying any bugs') |
| 1041 | result.add_argument( |
| 1042 | '--studio', |
| 1043 | metavar=('<path>'), |
| 1044 | help='Release for studio by setting the path to a studio ' |
| 1045 | 'checkout') |
Søren Gjesse | 25e6191 | 2023-11-06 16:02:07 +0100 | [diff] [blame^] | 1046 | result.add_argument('--studio-legacy-release', |
| 1047 | default=False, |
| 1048 | action='store_true', |
| 1049 | help='Allow Studio release using the legacy process') |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1050 | result.add_argument('--aosp', |
| 1051 | metavar=('<path>'), |
| 1052 | help='Release for aosp by setting the path to the ' |
| 1053 | 'checkout') |
| 1054 | result.add_argument('--maven', |
| 1055 | default=False, |
| 1056 | action='store_true', |
| 1057 | help='Release to Google Maven') |
| 1058 | result.add_argument('--google3', |
| 1059 | default=False, |
| 1060 | action='store_true', |
| 1061 | help='Release for google 3') |
| 1062 | result.add_argument('--google3retrace', |
| 1063 | default=False, |
| 1064 | action='store_true', |
| 1065 | help='Release retrace for google 3') |
| 1066 | result.add_argument('--p4-client', |
| 1067 | default='update-r8', |
| 1068 | metavar=('<client name>'), |
| 1069 | help='P4 client name for google 3') |
| 1070 | result.add_argument( |
| 1071 | '--use-existing-work-branch', |
| 1072 | '--use_existing_work_branch', |
| 1073 | default=False, |
| 1074 | action='store_true', |
| 1075 | help='Use existing work branch/CL in aosp/studio/google3') |
| 1076 | result.add_argument('--delete-work-branch', |
| 1077 | '--delete_work_branch', |
| 1078 | default=False, |
| 1079 | action='store_true', |
| 1080 | help='Delete CL in google3') |
| 1081 | result.add_argument('--bypass-hooks', |
| 1082 | '--bypass_hooks', |
| 1083 | default=False, |
| 1084 | action='store_true', |
| 1085 | help="Bypass hooks when uploading") |
| 1086 | result.add_argument('--no-upload', |
| 1087 | '--no_upload', |
| 1088 | default=False, |
| 1089 | action='store_true', |
| 1090 | help="Don't upload for code review") |
| 1091 | result.add_argument( |
| 1092 | '--dry-run', |
| 1093 | default=False, |
| 1094 | action='store_true', |
| 1095 | help='Only perform non-commiting tasks and print others.') |
| 1096 | result.add_argument('--dry-run-output', |
| 1097 | '--dry_run_output', |
| 1098 | default=os.getcwd(), |
| 1099 | metavar=('<path>'), |
| 1100 | help='Location for dry run output.') |
| 1101 | args = result.parse_args() |
| 1102 | if (len(args.bug) > 0 and args.no_bugs): |
| 1103 | print("Use of '--bug' and '--no-bugs' are mutually exclusive") |
| 1104 | sys.exit(1) |
Søren Gjesse | 5aa4a68 | 2022-08-26 09:17:27 +0200 | [diff] [blame] | 1105 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1106 | if (args.studio and args.version and not 'dev' in args.version and |
| 1107 | args.bug == [] and not args.no_bugs): |
| 1108 | print("When releasing a release version to Android Studio add the " + |
| 1109 | "list of bugs by using '--bug'") |
| 1110 | sys.exit(1) |
Morten Krogh-Jespersen | a1396cd | 2019-10-02 16:14:40 +0200 | [diff] [blame] | 1111 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1112 | if args.version and not 'dev' in args.version and args.google3: |
| 1113 | 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] | 1114 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1115 | return args |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 1116 | |
| 1117 | |
| 1118 | def main(): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1119 | args = parse_options() |
| 1120 | targets_to_run = [] |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 1121 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1122 | if args.new_dev_branch: |
| 1123 | if args.google3 or args.studio or args.aosp: |
| 1124 | print('Cannot create a branch and roll at the same time.') |
| 1125 | sys.exit(1) |
| 1126 | targets_to_run.append(prepare_branch(args)) |
Søren Gjesse | 4e5c6fe | 2019-11-05 17:17:43 +0100 | [diff] [blame] | 1127 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1128 | if args.dev_release: |
| 1129 | if args.google3 or args.studio or args.aosp: |
| 1130 | print('Cannot create a dev release and roll at the same time.') |
| 1131 | sys.exit(1) |
| 1132 | targets_to_run.append(prepare_release(args)) |
Ian Zerny | 59dfa4c | 2019-10-25 10:34:36 +0200 | [diff] [blame] | 1133 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1134 | if (args.google3 or args.maven or (args.studio and not args.no_sync) or |
| 1135 | (args.desugar_library and not args.dry_run)): |
| 1136 | utils.check_gcert() |
Søren Gjesse | b8dec61 | 2019-10-10 09:15:43 +0200 | [diff] [blame] | 1137 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1138 | if args.google3: |
| 1139 | targets_to_run.append(prepare_google3(args)) |
| 1140 | if args.google3retrace: |
| 1141 | targets_to_run.append(prepare_google3_retrace(args)) |
| 1142 | if args.studio and not args.update_desugar_library_in_studio: |
| 1143 | targets_to_run.append(prepare_studio(args)) |
| 1144 | if args.aosp: |
| 1145 | targets_to_run.append(prepare_aosp(args)) |
| 1146 | if args.maven: |
| 1147 | targets_to_run.append(prepare_maven(args)) |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 1148 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1149 | if args.desugar_library: |
| 1150 | targets_to_run.append(prepare_desugar_library(args)) |
Søren Gjesse | 975c5df | 2019-12-10 13:48:05 +0100 | [diff] [blame] | 1151 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1152 | if args.update_desugar_library_in_studio: |
| 1153 | if not args.studio: |
| 1154 | print("--studio required") |
| 1155 | sys.exit(1) |
| 1156 | if args.bug == []: |
| 1157 | print( |
| 1158 | "Update studio mirror of com.android.tools:desugar_jdk_libs " + |
| 1159 | "requires at least one bug by using '--bug'") |
| 1160 | sys.exit(1) |
| 1161 | targets_to_run.append(update_desugar_library_in_studio(args)) |
Søren Gjesse | 73355ec | 2020-06-29 09:19:44 +0200 | [diff] [blame] | 1162 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1163 | final_results = [] |
| 1164 | for target_closure in targets_to_run: |
| 1165 | final_results.append(target_closure(args)) |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 1166 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1167 | print('\n\n**************************************************************') |
| 1168 | print('PRINTING SUMMARY') |
| 1169 | print('**************************************************************\n\n') |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 1170 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1171 | for result in final_results: |
| 1172 | if result is not None: |
| 1173 | print(result) |
Morten Krogh-Jespersen | 1947a86 | 2019-09-26 14:06:48 +0200 | [diff] [blame] | 1174 | |
| 1175 | |
| 1176 | if __name__ == '__main__': |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 1177 | sys.exit(main()) |