blob: a5d7a4c13dd67949c6a4a03f6c8d5f6fdaa7ba9c [file] [log] [blame]
Morten Krogh-Jespersen8a4d1ca2021-01-19 08:27:02 +01001#!/usr/bin/env python3
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +02002# 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
6import argparse
7import datetime
8import os.path
9import re
Ian Zerny68f5c132023-11-01 12:57:07 +010010import shutil
Søren Gjesse4062e9c2023-09-01 12:21:08 +020011import stat
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +020012import subprocess
13import sys
Christoffer Quist Adamsend408d8d2021-01-26 19:50:39 +010014import urllib.request
Søren Gjesse2d6e9372020-11-04 08:17:28 +010015import xml.etree.ElementTree
Søren Gjesse975c5df2019-12-10 13:48:05 +010016import zipfile
Ian Zernycf1eb3c2020-09-24 08:27:23 +020017
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +020018import utils
19
Søren Gjesse448da112023-08-10 09:30:55 +020020R8_DEV_BRANCH = '8.3'
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020021R8_VERSION_FILE = os.path.join('src', 'main', 'java', 'com', 'android', 'tools',
22 'r8', 'Version.java')
Søren Gjesse27251592019-11-06 17:35:23 +010023THIS_FILE_RELATIVE = os.path.join('tools', 'r8_release.py')
Søren Gjesse376b74c2020-06-22 08:42:44 +020024GMAVEN_PUBLISHER = '/google/bin/releases/android-devtools/gmaven/publisher/gmaven-publisher'
Søren Gjesse975c5df2019-12-10 13:48:05 +010025
26DESUGAR_JDK_LIBS = 'desugar_jdk_libs'
27DESUGAR_JDK_LIBS_CONFIGURATION = DESUGAR_JDK_LIBS + '_configuration'
28ANDROID_TOOLS_PACKAGE = 'com.android.tools'
Ian Zerny59dfa4c2019-10-25 10:34:36 +020029
Søren Gjesse07b6aea2019-12-12 11:11:58 +010030GITHUB_DESUGAR_JDK_LIBS = 'https://github.com/google/desugar_jdk_libs'
Ian Zerny59dfa4c2019-10-25 10:34:36 +020031
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020032
Søren Gjesse4062e9c2023-09-01 12:21:08 +020033def install_gerrit_change_id_hook(checkout_dir):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020034 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 Gjesse4062e9c2023-09-01 12:21:08 +020049
Morten Krogh-Jespersend86a3012020-02-21 15:06:13 +010050def checkout_r8(temp, branch):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020051 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-Jespersend86a3012020-02-21 15:06:13 +010059
60
Ian Zerny59dfa4c2019-10-25 10:34:36 +020061def prepare_release(args):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020062 if args.version:
63 print("Cannot manually specify version when making a dev release.")
64 sys.exit(1)
Ian Zerny59dfa4c2019-10-25 10:34:36 +020065
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020066 def make_release(args):
67 commithash = args.dev_release
Ian Zerny59dfa4c2019-10-25 10:34:36 +020068
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020069 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 Zerny59dfa4c2019-10-25 10:34:36 +020088
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020089 old_version = '%s.%s-dev' % (R8_DEV_BRANCH, patch_version)
90 version = '%s.%s-dev' % (R8_DEV_BRANCH, patch_version + 1)
Ian Zerny59dfa4c2019-10-25 10:34:36 +020091
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020092 # 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 Zerny59dfa4c2019-10-25 10:34:36 +0200101
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200102 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 Wind140a5642019-11-26 10:44:21 +0100106
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200107 # Merge the desired commit from main on to the branch.
108 subprocess.check_call(
109 ['git', 'merge', '--no-ff', '--no-edit', commithash])
Ian Zerny59dfa4c2019-10-25 10:34:36 +0200110
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200111 # Rewrite the version, commit and validate.
112 sed(old_version, version, R8_VERSION_FILE)
Ian Zerny59dfa4c2019-10-25 10:34:36 +0200113
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200114 subprocess.check_call(
115 ['git', 'commit', '-a', '-m',
116 'Version %s' % version])
Ian Zerny59dfa4c2019-10-25 10:34:36 +0200117
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200118 version_diff_output = subprocess.check_output(
119 ['git', 'diff', '%s..HEAD' % commithash]).decode('utf-8')
Ian Zerny59dfa4c2019-10-25 10:34:36 +0200120
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200121 validate_version_change_diff(version_diff_output, "main",
122 version)
Ian Zerny59dfa4c2019-10-25 10:34:36 +0200123
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200124 cmd = ['git', 'cl', 'upload', '--no-squash']
125 if args.bypass_hooks:
126 cmd.append('--bypass-hooks')
127 maybe_check_call(args, cmd)
Ian Zerny59dfa4c2019-10-25 10:34:36 +0200128
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200129 if args.dry_run:
130 input(
131 'DryRun: check %s for content of version %s [enter to continue]:'
132 % (temp, version))
Ian Zerny59dfa4c2019-10-25 10:34:36 +0200133
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200134 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 Zerny59dfa4c2019-10-25 10:34:36 +0200137
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200138 return make_release
Ian Zerny59dfa4c2019-10-25 10:34:36 +0200139
140
Søren Gjesse4e5c6fe2019-11-05 17:17:43 +0100141def maybe_tag(args, version):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200142 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 Gjesse4e5c6fe2019-11-05 17:17:43 +0100146
Morten Krogh-Jespersend86a3012020-02-21 15:06:13 +0100147
Ian Zerny59dfa4c2019-10-25 10:34:36 +0200148def version_change_diff(diff, old_version, new_version):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200149 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 Zerny59dfa4c2019-10-25 10:34:36 +0200158
Søren Gjesseddeb02e2019-11-06 15:48:07 +0100159
Søren Gjesse4e5c6fe2019-11-05 17:17:43 +0100160def validate_version_change_diff(version_diff_output, old_version, new_version):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200161 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 Gjesse4e5c6fe2019-11-05 17:17:43 +0100174
Ian Zerny59dfa4c2019-10-25 10:34:36 +0200175
176def maybe_check_call(args, cmd):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200177 if args.dry_run:
178 print('DryRun:', ' '.join(cmd))
179 else:
180 print(' '.join(cmd))
181 return subprocess.check_call(cmd)
Ian Zerny59dfa4c2019-10-25 10:34:36 +0200182
183
Ian Zerny8c5f7b42023-05-25 11:24:05 +0200184def update_prebuilds(r8_checkout, version, checkout, keepanno=False):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200185 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-Jespersen1947a862019-09-26 14:06:48 +0200191
192
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200193def 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-Jespersen1947a862019-09-26 14:06:48 +0200203
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200204 prebuilts_r8 = os.path.join(path, 'prebuilts', 'r8')
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +0200205
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200206 if not options.use_existing_work_branch:
207 with utils.ChangedWorkingDirectory(prebuilts_r8):
208 subprocess.check_call(['repo', 'start', 'update-r8'])
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +0200209
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200210 update_prebuilds(r8_checkout, options.version, path, keepanno)
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +0200211
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200212 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-Jespersen1947a862019-09-26 14:06:48 +0200226
227
Morten Krogh-Jespersenb4a7acc2019-10-02 10:46:32 +0200228def prepare_aosp(args):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200229 assert args.version
230 assert os.path.exists(args.aosp), "Could not find AOSP path %s" % args.aosp
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +0200231
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200232 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 Zerny59dfa4c2019-10-25 10:34:36 +0200236
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200237 git_message = ("""Update D8 and R8 to %s
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +0200238
Morten Krogh-Jespersendbbf9a82020-08-11 21:38:08 +0200239Version: %s
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +0200240This build IS NOT suitable for preview or public release.
241
Morten Krogh-Jespersenb4a7acc2019-10-02 10:46:32 +0200242Built here: go/r8-releases/raw/%s
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +0200243
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200244Test: 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-Jespersen1947a862019-09-26 14:06:48 +0200254
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200255 return release_aosp
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +0200256
257
Søren Gjesse376b74c2020-06-22 08:42:44 +0200258def prepare_maven(args):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200259 assert args.version
Søren Gjesse376b74c2020-06-22 08:42:44 +0200260
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200261 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 Gjesse376b74c2020-06-22 08:42:44 +0200264
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200265 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 Gjesse376b74c2020-06-22 08:42:44 +0200268
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200269 print
270 answer = input("Continue with publishing [y/N]:")
Søren Gjesse376b74c2020-06-22 08:42:44 +0200271
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200272 if answer != 'y':
273 print('Aborting release to Google maven')
274 sys.exit(1)
Søren Gjesse376b74c2020-06-22 08:42:44 +0200275
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200276 gmaven_publisher_publish(args, release_id)
Søren Gjesse376b74c2020-06-22 08:42:44 +0200277
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200278 print("")
279 print("Published. Use the email workflow for approval.")
Søren Gjesse376b74c2020-06-22 08:42:44 +0200280
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200281 return release_maven
282
Søren Gjesse376b74c2020-06-22 08:42:44 +0200283
Ian Zernyacfaf292020-09-24 07:14:56 +0200284# ------------------------------------------------------ column 70 --v
Ian Zernycf1eb3c2020-09-24 08:27:23 +0200285def git_message_dev(version, bugs):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200286 return """Update D8 R8 to %s
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +0200287
Ian Zernyacfaf292020-09-24 07:14:56 +0200288This is a development snapshot, it's fine to use for studio canary
289build, but not for BETA or release, for those we would need a release
290version of R8 binaries. This build IS suitable for preview release
291but IS NOT suitable for public release.
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +0200292
Morten Krogh-Jespersenb4a7acc2019-10-02 10:46:32 +0200293Built here: go/r8-releases/raw/%s
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +0200294Test: ./gradlew check
Ian Zernyfec00092022-03-16 08:25:07 +0100295Bug: %s""" % (version, version, '\nBug: '.join(map(bug_fmt, bugs)))
Morten Krogh-Jespersenb4a7acc2019-10-02 10:46:32 +0200296
297
Morten Krogh-Jespersena1396cd2019-10-02 16:14:40 +0200298def git_message_release(version, bugs):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200299 return """D8 R8 version %s
Morten Krogh-Jespersena1396cd2019-10-02 16:14:40 +0200300
301Built here: go/r8-releases/raw/%s/
302Test: ./gradlew check
Morten Krogh-Jespersend86a3012020-02-21 15:06:13 +0100303
Ian Zernyfec00092022-03-16 08:25:07 +0100304Bug: %s""" % (version, version, '\nBug: '.join(map(bug_fmt, bugs)))
Morten Krogh-Jespersena1396cd2019-10-02 16:14:40 +0200305
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200306
Ian Zernyfec00092022-03-16 08:25:07 +0100307def bug_fmt(bug):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200308 return "b/%s" % bug
309
Morten Krogh-Jespersena1396cd2019-10-02 16:14:40 +0200310
Morten Krogh-Jespersenb4a7acc2019-10-02 10:46:32 +0200311def prepare_studio(args):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200312 assert args.version
313 assert os.path.exists(args.studio), ("Could not find STUDIO path %s" %
314 args.studio)
Søren Gjesse25e61912023-11-06 16:02:07 +0100315 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-Jespersenb4a7acc2019-10-02 10:46:32 +0200322
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200323 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 Zerny59dfa4c2019-10-25 10:34:36 +0200327
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200328 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-Jespersen1947a862019-09-26 14:06:48 +0200340
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200341 return release_studio
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +0200342
343
344def g4_cp(old, new, file):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200345 subprocess.check_call('g4 cp {%s,%s}/%s' % (old, new, file), shell=True)
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +0200346
347
348def g4_open(file):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200349 if not os.access(file, os.W_OK):
350 subprocess.check_call('g4 open %s' % file, shell=True)
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +0200351
352
Rico Wind8d008ca2020-04-22 12:13:15 +0200353def g4_change(version):
Ian Zerny68f5c132023-11-01 12:57:07 +0100354 message = f'Update R8 to {version}'
355 if version == 'main':
356 message = f'DO NOT SUBMIT: {message}'
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200357 return subprocess.check_output(
Ian Zerny68f5c132023-11-01 12:57:07 +0100358 f'g4 change --desc "{message}\n"',
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200359 shell=True).decode('utf-8')
360
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +0200361
Morten Krogh-Jespersen1f2f5142020-09-21 11:20:23 +0200362def get_cl_id(c4_change_output):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200363 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-Jespersen1947a862019-09-26 14:06:48 +0200369
370def sed(pattern, replace, path):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200371 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-Jespersen1947a862019-09-26 14:06:48 +0200376
Morten Krogh-Jespersenb4a7acc2019-10-02 10:46:32 +0200377def download_file(version, file, dst):
Ian Zerny68f5c132023-11-01 12:57:07 +0100378 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 Adamsen2434a4d2023-10-16 11:29:03 +0200385 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-Jespersen1947a862019-09-26 14:06:48 +0200390
Søren Gjesseb093b672020-06-23 16:23:10 +0200391def download_gfile(gfile, dst):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200392 if not gfile.startswith('/bigstore/r8-releases'):
393 print('Unexpected gfile prefix for %s' % gfile)
394 sys.exit(1)
Søren Gjesseb093b672020-06-23 16:23:10 +0200395
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200396 urllib.request.urlretrieve(
397 'https://storage.googleapis.com/%s' % gfile[len('/bigstore/'):], dst)
398
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +0200399
400def blaze_run(target):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200401 return subprocess.check_output('blaze run %s' % target,
402 shell=True,
403 stderr=subprocess.STDOUT).decode('utf-8')
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +0200404
405
Ian Zerny59dfa4c2019-10-25 10:34:36 +0200406def prepare_google3(args):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200407 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-Jespersen1947a862019-09-26 14:06:48 +0200411
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200412 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-Jespersen1947a862019-09-26 14:06:48 +0200416
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200417 google3_base = subprocess.check_output(
418 ['p4', 'g4d', '-f', args.p4_client]).decode('utf-8').rstrip()
419 third_party_r8 = os.path.join(google3_base, 'third_party', 'java', 'r8')
420 today = datetime.date.today()
421 with utils.ChangedWorkingDirectory(third_party_r8):
422 # download files
423 g4_open('full.jar')
424 g4_open('src.jar')
425 g4_open('lib.jar')
426 g4_open('lib.jar.map')
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200427 g4_open('desugar_jdk_libs_configuration.jar')
Ian Zerny68f5c132023-11-01 12:57:07 +0100428 g4_open('threading-module-blocking.jar')
429 g4_open('threading-module-single-threaded.jar')
430 download_file(options.version,
431 'r8-full-exclude-deps.jar',
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200432 'full.jar')
Ian Zerny68f5c132023-11-01 12:57:07 +0100433 download_file(options.version,
Ian Zerny68f5c132023-11-01 12:57:07 +0100434 'r8-src.jar',
435 'src.jar')
436 download_file(options.version,
437 'r8lib-exclude-deps.jar',
438 'lib.jar')
439 download_file(options.version,
440 'r8lib-exclude-deps.jar.map',
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200441 'lib.jar.map')
Ian Zerny68f5c132023-11-01 12:57:07 +0100442 download_file(options.version,
443 'desugar_jdk_libs_configuration.jar',
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200444 'desugar_jdk_libs_configuration.jar')
Ian Zerny68f5c132023-11-01 12:57:07 +0100445 download_file(options.version,
Ian Zerny68f5c132023-11-01 12:57:07 +0100446 'threading-module-blocking.jar',
447 'threading-module-blocking.jar')
448 download_file(options.version,
449 'threading-module-single-threaded.jar',
450 'threading-module-single-threaded.jar')
451 if options.version != 'main':
452 g4_open('METADATA')
453 metadata_path = os.path.join(third_party_r8, 'METADATA')
454 match_count = 0
Ian Zernyed1f8512023-11-07 11:07:57 +0100455 match_count_expected = 11
Ian Zerny68f5c132023-11-01 12:57:07 +0100456 version_match_regexp = r'[1-9]\.[0-9]{1,2}\.[0-9]{1,3}-dev'
457 for line in open(metadata_path, 'r'):
458 result = re.search(version_match_regexp, line)
459 if result:
460 match_count = match_count + 1
461 if match_count != match_count_expected:
462 print(f"""WARNING:
463 Could not find the previous -dev release string to replace in METADATA.
464 Expected to find it mentioned {match_count_expected} times, but found
465 {match_count} occurrences. Please update {metadata_path} manually and
466 run again with options --google3 --use-existing-work-branch.
467 """)
468 sys.exit(1)
469 sed(version_match_regexp, options.version, metadata_path)
470 sed(r'\{ year.*\}',
471 f'{{ year: {today.year} month: {today.month} day: {today.day} }}',
472 metadata_path)
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200473 subprocess.check_output('chmod u+w *', shell=True)
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +0200474
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200475 with utils.ChangedWorkingDirectory(google3_base):
476 blaze_result = blaze_run('//third_party/java/r8:d8 -- --version')
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +0200477
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200478 assert options.version in blaze_result
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +0200479
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200480 if not options.no_upload:
481 change_result = g4_change(options.version)
482 change_result += 'Run \'(g4d ' + args.p4_client \
483 + ' && tap_presubmit -p all --train -c ' \
484 + get_cl_id(change_result) + ')\' for running TAP global' \
485 + ' presubmit using the train.\n' \
486 + 'Run \'(g4d ' + args.p4_client \
487 + ' && tap_presubmit -p all --notrain --detach --email' \
488 + ' --skip_flaky_targets --skip_already_failing -c ' \
489 + get_cl_id(change_result) + ')\' for running an isolated' \
490 + ' TAP global presubmit.'
491 return change_result
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +0200492
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200493 return release_google3
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +0200494
495
Søren Gjesse73355ec2020-06-29 09:19:44 +0200496def update_desugar_library_in_studio(args):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200497 assert os.path.exists(args.studio), ("Could not find STUDIO path %s" %
498 args.studio)
Søren Gjesse73355ec2020-06-29 09:19:44 +0200499
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200500 def make_release(args):
501 library_version = args.update_desugar_library_in_studio[0]
502 configuration_version = args.update_desugar_library_in_studio[1]
503 change_name = 'update-desugar-library-dependencies'
Søren Gjesse73355ec2020-06-29 09:19:44 +0200504
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200505 with utils.ChangedWorkingDirectory(args.studio):
506 if not args.use_existing_work_branch:
507 subprocess.call(['repo', 'abandon', change_name])
508 if not args.no_sync:
509 subprocess.check_call(['repo', 'sync', '-cq', '-j', '16'])
Søren Gjesse73355ec2020-06-29 09:19:44 +0200510
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200511 cmd = [
512 'tools/base/bazel/bazel', 'run',
513 '//tools/base/bazel:add_dependency', '--',
514 '--repo=https://maven.google.com com.android.tools:desugar_jdk_libs:%s'
515 % library_version
516 ]
517 utils.PrintCmd(cmd)
518 subprocess.check_call(" ".join(cmd), shell=True)
519 cmd = ['tools/base/bazel/bazel', 'shutdown']
520 utils.PrintCmd(cmd)
521 subprocess.check_call(cmd)
Søren Gjesse73355ec2020-06-29 09:19:44 +0200522
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200523 prebuilts_tools = os.path.join(args.studio, 'prebuilts', 'tools')
Søren Gjesse73355ec2020-06-29 09:19:44 +0200524 with utils.ChangedWorkingDirectory(prebuilts_tools):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200525 if not args.use_existing_work_branch:
526 with utils.ChangedWorkingDirectory(prebuilts_tools):
527 subprocess.check_call(['repo', 'start', change_name])
528 m2_dir = os.path.join('common', 'm2', 'repository', 'com',
529 'android', 'tools')
530 subprocess.check_call([
531 'git', 'add',
532 os.path.join(m2_dir, DESUGAR_JDK_LIBS, library_version)
533 ])
534 subprocess.check_call([
535 'git', 'add',
536 os.path.join(m2_dir, DESUGAR_JDK_LIBS_CONFIGURATION,
537 configuration_version)
538 ])
Søren Gjesse73355ec2020-06-29 09:19:44 +0200539
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200540 git_message = ("""Update library desugaring dependencies
Søren Gjesse73355ec2020-06-29 09:19:44 +0200541
542 com.android.tools:desugar_jdk_libs:%s
543 com.android.tools:desugar_jdk_libs_configuration:%s
544
545Bug: %s
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200546Test: L8ToolTest, L8DexDesugarTest""" %
547 (library_version, configuration_version,
548 '\nBug: '.join(map(bug_fmt, args.bug))))
Søren Gjesse73355ec2020-06-29 09:19:44 +0200549
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200550 if not args.use_existing_work_branch:
551 subprocess.check_call(
552 ['git', 'commit', '-a', '-m', git_message])
553 else:
554 print('Not committing when --use-existing-work-branch. ' +
555 'Commit message should be:\n\n' + git_message + '\n')
556 # Don't upload if requested not to, or if changes are not committed due
557 # to --use-existing-work-branch
558 if not args.no_upload and not args.use_existing_work_branch:
559 process = subprocess.Popen(['repo', 'upload', '.', '--verify'],
560 stdin=subprocess.PIPE)
561 return process.communicate(input='y\n')[0]
Søren Gjesse73355ec2020-06-29 09:19:44 +0200562
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200563 return make_release
Søren Gjesse73355ec2020-06-29 09:19:44 +0200564
565
Søren Gjesse975c5df2019-12-10 13:48:05 +0100566def prepare_desugar_library(args):
567
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200568 def make_release(args):
569 library_version = args.desugar_library[0]
570 configuration_version = args.desugar_library[1]
Søren Gjesse975c5df2019-12-10 13:48:05 +0100571
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200572 # TODO(b/237636871): Cleanup and generalize.
573 if (not (library_version.startswith('1.1') or
574 library_version.startswith('1.2') or
575 library_version.startswith('2.0'))):
576 print(
577 "Release script does not support desugared library version %s" %
578 library_version)
579 sys.exit(1)
Søren Gjessee78b1652022-06-30 12:38:36 +0200580
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200581 postfixes = ['']
582 if library_version.startswith('1.2'):
583 postfixes = ['_legacy']
584 if library_version.startswith('2.0'):
585 postfixes = ['_minimal', '', '_nio']
Søren Gjesseb093b672020-06-23 16:23:10 +0200586
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200587 with utils.TempDir() as temp:
588 with utils.ChangedWorkingDirectory(temp):
589 artifacts = []
590 for postfix in postfixes:
591 group_postfix = ('' if postfix == '_legacy' else postfix)
592 archive_postfix = (postfix
593 if library_version.startswith('1.1') else
594 '_jdk11' + postfix)
595 library_jar = DESUGAR_JDK_LIBS + postfix + '.jar'
596 library_archive = DESUGAR_JDK_LIBS + archive_postfix + '.zip'
597 configuration_archive = DESUGAR_JDK_LIBS_CONFIGURATION + archive_postfix + '.zip'
598 library_gfile = ('/bigstore/r8-releases/raw/%s/%s/%s' %
599 (DESUGAR_JDK_LIBS + group_postfix,
600 library_version, library_archive))
601 configuration_gfile = (
602 '/bigstore/r8-releases/raw/main/%s/%s' %
603 (configuration_version, configuration_archive))
Søren Gjesse975c5df2019-12-10 13:48:05 +0100604
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200605 download_gfile(library_gfile, library_archive)
606 download_gfile(configuration_gfile, configuration_archive)
607 check_configuration(configuration_archive, group_postfix)
608 artifacts.append(library_gfile)
609 artifacts.append(configuration_gfile)
Søren Gjesseb093b672020-06-23 16:23:10 +0200610
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200611 release_id = gmaven_publisher_stage(args, artifacts)
Søren Gjesseb093b672020-06-23 16:23:10 +0200612
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200613 print("Staged Release ID " + release_id + ".\n")
614 library_artifact_id = \
615 '%s:%s:%s' % (ANDROID_TOOLS_PACKAGE, DESUGAR_JDK_LIBS, library_version)
616 gmaven_publisher_stage_redir_test_info(release_id,
617 library_artifact_id,
618 library_jar)
Søren Gjesseb093b672020-06-23 16:23:10 +0200619
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200620 print("")
621 answer = input("Continue with publishing [y/N]:")
Søren Gjesse975c5df2019-12-10 13:48:05 +0100622
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200623 if answer != 'y':
624 print('Aborting release to Google maven')
625 sys.exit(1)
Søren Gjesse975c5df2019-12-10 13:48:05 +0100626
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200627 gmaven_publisher_publish(args, release_id)
Søren Gjesseb093b672020-06-23 16:23:10 +0200628
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200629 print("")
630 print("Published. Use the email workflow for approval.")
Søren Gjesse975c5df2019-12-10 13:48:05 +0100631
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200632 return make_release
Søren Gjesse975c5df2019-12-10 13:48:05 +0100633
634
Søren Gjesse3e459092023-01-05 09:40:28 +0100635def check_configuration(configuration_archive, postfix):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200636 zip = zipfile.ZipFile(configuration_archive)
637 zip.extractall()
638 dirs = os.listdir(
639 os.path.join('com', 'android', 'tools',
640 DESUGAR_JDK_LIBS_CONFIGURATION + postfix))
641 if len(dirs) != 1:
642 print('Unexpected archive content, %s' + dirs)
643 sys.exit(1)
Søren Gjesse975c5df2019-12-10 13:48:05 +0100644
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200645 version = dirs[0]
646 pom_file = os.path.join(
647 'com', 'android', 'tools', DESUGAR_JDK_LIBS_CONFIGURATION + postfix,
648 version,
649 '%s-%s.pom' % (DESUGAR_JDK_LIBS_CONFIGURATION + postfix, version))
650 version_from_pom = extract_version_from_pom(pom_file)
651 if version != version_from_pom:
652 print('Version mismatch, %s != %s' % (version, version_from_pom))
653 sys.exit(1)
654
Søren Gjesse07b6aea2019-12-12 11:11:58 +0100655
656def check_no_google3_client(args, client_name):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200657 if not args.use_existing_work_branch:
658 clients = subprocess.check_output('g4 myclients',
659 shell=True).decode('utf-8')
660 if ':%s:' % client_name in clients:
661 if args.delete_work_branch:
662 subprocess.check_call('g4 citc -d -f %s' % client_name,
663 shell=True)
664 else:
665 print(("Remove the existing '%s' client before continuing " +
666 "(force delete: 'g4 citc -d -f %s'), " +
667 "or use either --use-existing-work-branch or " +
668 "--delete-work-branch.") % (client_name, client_name))
669 sys.exit(1)
Søren Gjesse07b6aea2019-12-12 11:11:58 +0100670
671
Søren Gjesse975c5df2019-12-10 13:48:05 +0100672def extract_version_from_pom(pom_file):
673 ns = "http://maven.apache.org/POM/4.0.0"
674 xml.etree.ElementTree.register_namespace('', ns)
675 tree = xml.etree.ElementTree.ElementTree()
676 tree.parse(pom_file)
677 return tree.getroot().find("{%s}version" % ns).text
678
Søren Gjesse376b74c2020-06-22 08:42:44 +0200679
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200680GMAVEN_PUBLISH_STAGE_RELEASE_ID_PATTERN = re.compile(
681 'Release ID = ([0-9a-f\-]+)')
Søren Gjesse376b74c2020-06-22 08:42:44 +0200682
Søren Gjesseb093b672020-06-23 16:23:10 +0200683
684def gmaven_publisher_stage(args, gfiles):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200685 if args.dry_run:
686 print('Dry-run, would have staged %s' % gfiles)
687 return 'dry-run-release-id'
Søren Gjesse376b74c2020-06-22 08:42:44 +0200688
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200689 print("Staging: %s" % ', '.join(gfiles))
690 print("")
Søren Gjesse376b74c2020-06-22 08:42:44 +0200691
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200692 cmd = [GMAVEN_PUBLISHER, 'stage', '--gfile', ','.join(gfiles)]
693 output = subprocess.check_output(cmd)
Søren Gjesse376b74c2020-06-22 08:42:44 +0200694
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200695 # Expect output to contain:
696 # [INFO] 06/19/2020 09:35:12 CEST: >>>>>>>>>> Staged
697 # [INFO] 06/19/2020 09:35:12 CEST: Release ID = 9171d015-18f6-4a90-9984-1c362589dc1b
698 # [INFO] 06/19/2020 09:35:12 CEST: Stage Path = /bigstore/studio_staging/maven2/sgjesse/9171d015-18f6-4a90-9984-1c362589dc1b
Søren Gjesse376b74c2020-06-22 08:42:44 +0200699
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200700 matches = GMAVEN_PUBLISH_STAGE_RELEASE_ID_PATTERN.findall(
701 output.decode("utf-8"))
702 if matches == None or len(matches) > 1:
703 print("Could not determine the release ID from the gmaven_publisher " +
704 "output. Expected a line with 'Release ID = <release id>'.")
705 print("Output was:")
706 print(output)
707 sys.exit(1)
708
Morten Krogh-Jespersen8a4d1ca2021-01-19 08:27:02 +0100709 print(output)
Søren Gjesse376b74c2020-06-22 08:42:44 +0200710
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200711 release_id = matches[0]
712 return release_id
Søren Gjesse376b74c2020-06-22 08:42:44 +0200713
Søren Gjesseb093b672020-06-23 16:23:10 +0200714
715def gmaven_publisher_stage_redir_test_info(release_id, artifact, dst):
716
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200717 redir_command = ("/google/data/ro/teams/android-devtools-infra/tools/redir "
718 + "--alsologtostderr " +
719 "--gcs_bucket_path=/bigstore/gmaven-staging/${USER}/%s " +
720 "--port=1480") % release_id
Søren Gjesseb093b672020-06-23 16:23:10 +0200721
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200722 get_command = (
723 "mvn org.apache.maven.plugins:maven-dependency-plugin:2.4:get " +
724 "-Dmaven.repo.local=/tmp/maven_repo_local " +
725 "-DremoteRepositories=http://localhost:1480 " + "-Dartifact=%s " +
726 "-Ddest=%s") % (artifact, dst)
Søren Gjesseb093b672020-06-23 16:23:10 +0200727
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200728 print("""To test the staged content with 'redir' run:
Søren Gjesseb093b672020-06-23 16:23:10 +0200729
730%s
731
Søren Gjesse3d3a9202023-11-02 11:04:28 +0100732Then add the following repository to settings.gradle.kts (Kotlin Script) to
733search the 'redir' repository:
734
735dependencyResolutionManagement {
736 repositories {
737 maven {
738 url = uri("http://localhost:1480")
739 isAllowInsecureProtocol = true
740 }
741 }
742}
743
744or the following to settings.gradle (Groovy);
Søren Gjesseb093b672020-06-23 16:23:10 +0200745
Søren Gjessee78b1652022-06-30 12:38:36 +0200746dependencyResolutionManagement {
747 repositories {
748 maven {
749 url 'http://localhost:1480'
750 allowInsecureProtocol true
751 }
Søren Gjesse44eee512021-09-24 11:44:11 +0200752 }
Søren Gjessee78b1652022-06-30 12:38:36 +0200753}
754
Søren Gjesse3d3a9202023-11-02 11:04:28 +0100755and add the following repository to gradle.build.kts (Kotlin Script) for the
756staged version:
757
758coreLibraryDesugaring("%s") {
759 isChanging = true
760}
761
762or the following to settings.gradle (Groovy);
Søren Gjessee78b1652022-06-30 12:38:36 +0200763
764dependencies {
765 coreLibraryDesugaring('%s') {
766 changing = true
Søren Gjesseb093b672020-06-23 16:23:10 +0200767 }
768}
769
770Use this commands to get artifact from 'redir':
771
772rm -rf /tmp/maven_repo_local
773%s
Søren Gjesse3d3a9202023-11-02 11:04:28 +0100774""" % (redir_command, artifact, artifact, get_command))
Søren Gjesseb093b672020-06-23 16:23:10 +0200775
776
Søren Gjesse376b74c2020-06-22 08:42:44 +0200777def gmaven_publisher_publish(args, release_id):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200778 if args.dry_run:
779 print('Dry-run, would have published %s' % release_id)
780 return
Søren Gjesse376b74c2020-06-22 08:42:44 +0200781
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200782 cmd = [GMAVEN_PUBLISHER, 'publish', release_id]
783 output = subprocess.check_output(cmd)
784
Søren Gjesse975c5df2019-12-10 13:48:05 +0100785
Søren Gjesseddeb02e2019-11-06 15:48:07 +0100786def branch_change_diff(diff, old_version, new_version):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200787 invalid_line = None
788 for line in str(diff).splitlines():
789 if line.startswith('-R8') and \
790 line != "-R8_DEV_BRANCH = '%s'" % old_version:
791 print(line)
792 invalid_line = line
793 elif line.startswith('+R8') and \
794 line != "+R8_DEV_BRANCH = '%s'" % new_version:
795 print(line)
796 invalid_line = line
797 return invalid_line
Søren Gjesseddeb02e2019-11-06 15:48:07 +0100798
799
800def validate_branch_change_diff(version_diff_output, old_version, new_version):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200801 invalid = branch_change_diff(version_diff_output, old_version, new_version)
802 if invalid:
803 print("")
804 print(
805 "The diff for the branch change in tools/release.py is not as expected:"
806 )
807 print("")
808 print("=" * 80)
809 print(version_diff_output)
810 print("=" * 80)
811 print("")
812 print("Validate the uploaded CL before landing.")
813 print("")
Søren Gjesseddeb02e2019-11-06 15:48:07 +0100814
815
Søren Gjesse4e5c6fe2019-11-05 17:17:43 +0100816def prepare_branch(args):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200817 branch_version = args.new_dev_branch[0]
818 commithash = args.new_dev_branch[1]
Søren Gjesse4e5c6fe2019-11-05 17:17:43 +0100819
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200820 current_semver = utils.check_basic_semver_version(
821 R8_DEV_BRANCH, ", current release branch version should be x.y", 2)
822 semver = utils.check_basic_semver_version(
823 branch_version, ", release branch version should be x.y", 2)
824 if not semver.larger_than(current_semver):
825 print('New branch version "' + branch_version +
826 '" must be strictly larger than the current "' + R8_DEV_BRANCH +
827 '"')
828 sys.exit(1)
Søren Gjesse4e5c6fe2019-11-05 17:17:43 +0100829
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200830 def make_branch(options):
831 with utils.TempDir() as temp:
832 subprocess.check_call(['git', 'clone', utils.REPO_SOURCE, temp])
833 with utils.ChangedWorkingDirectory(temp):
834 subprocess.check_call(
835 ['git', 'branch', branch_version, commithash])
Søren Gjesse4e5c6fe2019-11-05 17:17:43 +0100836
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200837 subprocess.check_call(['git', 'checkout', branch_version])
Søren Gjesse4e5c6fe2019-11-05 17:17:43 +0100838
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200839 # Rewrite the version, commit and validate.
840 old_version = 'main'
841 full_version = branch_version + '.0-dev'
842 version_prefix = 'public static final String LABEL = "'
843 sed(version_prefix + old_version, version_prefix + full_version,
844 R8_VERSION_FILE)
Søren Gjesse4e5c6fe2019-11-05 17:17:43 +0100845
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200846 subprocess.check_call(
847 ['git', 'commit', '-a', '-m',
848 'Version %s' % full_version])
Søren Gjesse4e5c6fe2019-11-05 17:17:43 +0100849
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200850 version_diff_output = subprocess.check_output(
851 ['git', 'diff', '%s..HEAD' % commithash])
Søren Gjesse4e5c6fe2019-11-05 17:17:43 +0100852
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200853 validate_version_change_diff(version_diff_output, old_version,
854 full_version)
Søren Gjesse4e5c6fe2019-11-05 17:17:43 +0100855
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200856 # Double check that we want to create a new release branch.
857 if not options.dry_run:
858 answer = input('Create new branch for %s [y/N]:' %
859 branch_version)
860 if answer != 'y':
861 print('Aborting new branch for %s' % branch_version)
862 sys.exit(1)
Søren Gjesse4e5c6fe2019-11-05 17:17:43 +0100863
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200864 maybe_check_call(
865 options,
866 ['git', 'push', 'origin',
867 'HEAD:%s' % branch_version])
868 maybe_tag(options, full_version)
Søren Gjesse4e5c6fe2019-11-05 17:17:43 +0100869
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200870 print(
871 'Updating tools/r8_release.py to make new dev releases on %s'
872 % branch_version)
Søren Gjesseddeb02e2019-11-06 15:48:07 +0100873
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200874 subprocess.check_call(
875 ['git', 'new-branch', 'update-release-script'])
Søren Gjesseddeb02e2019-11-06 15:48:07 +0100876
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200877 # Check this file for the setting of the current dev branch.
878 result = None
879 for line in open(THIS_FILE_RELATIVE, 'r'):
880 result = re.match(r"^R8_DEV_BRANCH = '(\d+).(\d+)'", line)
881 if result:
882 break
883 if not result or not result.group(1):
884 print('Failed to find version label in %s' %
885 THIS_FILE_RELATIVE)
886 sys.exit(1)
Søren Gjesseddeb02e2019-11-06 15:48:07 +0100887
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200888 # Update this file with the new dev branch.
889 sed(
890 "R8_DEV_BRANCH = '%s.%s" %
891 (result.group(1), result.group(2)),
892 "R8_DEV_BRANCH = '%s.%s" %
893 (str(semver.major), str(semver.minor)), THIS_FILE_RELATIVE)
Søren Gjesseddeb02e2019-11-06 15:48:07 +0100894
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200895 message = \
896 'Prepare %s for branch %s' % (THIS_FILE_RELATIVE, branch_version)
897 subprocess.check_call(['git', 'commit', '-a', '-m', message])
Søren Gjesseddeb02e2019-11-06 15:48:07 +0100898
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200899 branch_diff_output = subprocess.check_output(
900 ['git', 'diff', 'HEAD~'])
Søren Gjesseddeb02e2019-11-06 15:48:07 +0100901
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200902 validate_branch_change_diff(branch_diff_output, R8_DEV_BRANCH,
903 branch_version)
Søren Gjesseddeb02e2019-11-06 15:48:07 +0100904
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200905 maybe_check_call(options,
906 ['git', 'cl', 'upload', '-f', '-m', message])
Søren Gjesseddeb02e2019-11-06 15:48:07 +0100907
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200908 print('')
909 print('Make sure to send out the branch change CL for review.')
910 print('')
Søren Gjesse4e5c6fe2019-11-05 17:17:43 +0100911
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200912 return make_branch
Søren Gjesse4e5c6fe2019-11-05 17:17:43 +0100913
914
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +0200915def parse_options():
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200916 result = argparse.ArgumentParser(description='Release r8')
917 group = result.add_mutually_exclusive_group()
918 group.add_argument('--dev-release',
919 metavar=('<main hash>'),
920 help='The hash to use for the new dev version of R8')
921 group.add_argument(
922 '--version',
923 metavar=('<version>'),
924 help=
925 'The new version of R8 (e.g., 1.4.51) to release to selected channels')
926 group.add_argument(
927 '--desugar-library',
928 nargs=2,
929 metavar=('<version>', '<configuration hash>'),
930 help='The new version of com.android.tools:desugar_jdk_libs')
931 group.add_argument(
932 '--update-desugar-library-in-studio',
933 nargs=2,
934 metavar=('<version>', '<configuration version>'),
935 help='Update studio mirror of com.android.tools:desugar_jdk_libs')
936 group.add_argument(
937 '--new-dev-branch',
938 nargs=2,
939 metavar=('<version>', '<main hash>'),
940 help='Create a new branch starting a version line (e.g. 2.0)')
941 result.add_argument('--dev-pre-cherry-pick',
942 metavar=('<main hash(s)>'),
943 default=[],
944 action='append',
945 help='List of commits to cherry pick before doing full '
946 'merge, mostly used for reverting cherry picks')
947 result.add_argument('--no-sync',
948 '--no_sync',
949 default=False,
950 action='store_true',
951 help='Do not sync repos before uploading')
952 result.add_argument('--bug',
953 metavar=('<bug(s)>'),
954 default=[],
955 action='append',
956 help='List of bugs for release version')
957 result.add_argument('--no-bugs',
958 default=False,
959 action='store_true',
960 help='Allow Studio release without specifying any bugs')
961 result.add_argument(
962 '--studio',
963 metavar=('<path>'),
964 help='Release for studio by setting the path to a studio '
965 'checkout')
Søren Gjesse25e61912023-11-06 16:02:07 +0100966 result.add_argument('--studio-legacy-release',
967 default=False,
968 action='store_true',
969 help='Allow Studio release using the legacy process')
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200970 result.add_argument('--aosp',
971 metavar=('<path>'),
972 help='Release for aosp by setting the path to the '
973 'checkout')
974 result.add_argument('--maven',
975 default=False,
976 action='store_true',
977 help='Release to Google Maven')
978 result.add_argument('--google3',
979 default=False,
980 action='store_true',
981 help='Release for google 3')
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200982 result.add_argument('--p4-client',
983 default='update-r8',
984 metavar=('<client name>'),
985 help='P4 client name for google 3')
986 result.add_argument(
987 '--use-existing-work-branch',
988 '--use_existing_work_branch',
989 default=False,
990 action='store_true',
991 help='Use existing work branch/CL in aosp/studio/google3')
992 result.add_argument('--delete-work-branch',
993 '--delete_work_branch',
994 default=False,
995 action='store_true',
996 help='Delete CL in google3')
997 result.add_argument('--bypass-hooks',
998 '--bypass_hooks',
999 default=False,
1000 action='store_true',
1001 help="Bypass hooks when uploading")
1002 result.add_argument('--no-upload',
1003 '--no_upload',
1004 default=False,
1005 action='store_true',
1006 help="Don't upload for code review")
1007 result.add_argument(
1008 '--dry-run',
1009 default=False,
1010 action='store_true',
1011 help='Only perform non-commiting tasks and print others.')
1012 result.add_argument('--dry-run-output',
1013 '--dry_run_output',
1014 default=os.getcwd(),
1015 metavar=('<path>'),
1016 help='Location for dry run output.')
1017 args = result.parse_args()
1018 if (len(args.bug) > 0 and args.no_bugs):
1019 print("Use of '--bug' and '--no-bugs' are mutually exclusive")
1020 sys.exit(1)
Søren Gjesse5aa4a682022-08-26 09:17:27 +02001021
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +02001022 if (args.studio and args.version and not 'dev' in args.version and
1023 args.bug == [] and not args.no_bugs):
1024 print("When releasing a release version to Android Studio add the " +
1025 "list of bugs by using '--bug'")
1026 sys.exit(1)
Morten Krogh-Jespersena1396cd2019-10-02 16:14:40 +02001027
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +02001028 if args.version and not 'dev' in args.version and args.google3:
1029 print("WARNING: You should not roll a release version into google 3")
Morten Krogh-Jespersen52d3ab02019-10-29 08:57:06 +01001030
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +02001031 return args
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +02001032
1033
1034def main():
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +02001035 args = parse_options()
1036 targets_to_run = []
Ian Zerny59dfa4c2019-10-25 10:34:36 +02001037
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +02001038 if args.new_dev_branch:
1039 if args.google3 or args.studio or args.aosp:
1040 print('Cannot create a branch and roll at the same time.')
1041 sys.exit(1)
1042 targets_to_run.append(prepare_branch(args))
Søren Gjesse4e5c6fe2019-11-05 17:17:43 +01001043
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +02001044 if args.dev_release:
1045 if args.google3 or args.studio or args.aosp:
1046 print('Cannot create a dev release and roll at the same time.')
1047 sys.exit(1)
1048 targets_to_run.append(prepare_release(args))
Ian Zerny59dfa4c2019-10-25 10:34:36 +02001049
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +02001050 if (args.google3 or args.maven or (args.studio and not args.no_sync) or
1051 (args.desugar_library and not args.dry_run)):
1052 utils.check_gcert()
Søren Gjesseb8dec612019-10-10 09:15:43 +02001053
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +02001054 if args.google3:
1055 targets_to_run.append(prepare_google3(args))
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +02001056 if args.studio and not args.update_desugar_library_in_studio:
1057 targets_to_run.append(prepare_studio(args))
1058 if args.aosp:
1059 targets_to_run.append(prepare_aosp(args))
1060 if args.maven:
1061 targets_to_run.append(prepare_maven(args))
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +02001062
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +02001063 if args.desugar_library:
1064 targets_to_run.append(prepare_desugar_library(args))
Søren Gjesse975c5df2019-12-10 13:48:05 +01001065
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +02001066 if args.update_desugar_library_in_studio:
1067 if not args.studio:
1068 print("--studio required")
1069 sys.exit(1)
1070 if args.bug == []:
1071 print(
1072 "Update studio mirror of com.android.tools:desugar_jdk_libs " +
1073 "requires at least one bug by using '--bug'")
1074 sys.exit(1)
1075 targets_to_run.append(update_desugar_library_in_studio(args))
Søren Gjesse73355ec2020-06-29 09:19:44 +02001076
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +02001077 final_results = []
1078 for target_closure in targets_to_run:
1079 final_results.append(target_closure(args))
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +02001080
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +02001081 print('\n\n**************************************************************')
1082 print('PRINTING SUMMARY')
1083 print('**************************************************************\n\n')
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +02001084
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +02001085 for result in final_results:
1086 if result is not None:
1087 print(result)
Morten Krogh-Jespersen1947a862019-09-26 14:06:48 +02001088
1089
1090if __name__ == '__main__':
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +02001091 sys.exit(main())