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