Ian Zerny | dcb172e | 2022-02-22 15:36:45 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Rico Wind | b4621c1 | 2017-08-28 12:48:53 +0200 | [diff] [blame] | 2 | # Copyright (c) 2017, 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 | |
Ian Zerny | 3f54e22 | 2019-02-12 10:51:17 +0100 | [diff] [blame] | 6 | import jdk |
Rico Wind | 63a1356 | 2018-12-10 14:31:02 +0100 | [diff] [blame] | 7 | import optparse |
Rico Wind | b4621c1 | 2017-08-28 12:48:53 +0200 | [diff] [blame] | 8 | import os |
Clément Béra | 3718ad0 | 2023-09-05 14:12:48 +0200 | [diff] [blame] | 9 | |
| 10 | import create_maven_release |
| 11 | import gradle |
| 12 | |
Morten Krogh-Jespersen | fe0d7e1 | 2020-01-31 08:50:17 +0100 | [diff] [blame] | 13 | try: |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 14 | import resource |
Morten Krogh-Jespersen | fe0d7e1 | 2020-01-31 08:50:17 +0100 | [diff] [blame] | 15 | except ImportError: |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 16 | # Not a Unix system. Do what Gandalf tells you not to. |
| 17 | pass |
Mathias Rav | dd6a6de | 2018-05-18 10:18:33 +0200 | [diff] [blame] | 18 | import shutil |
Rico Wind | 0c24ae7 | 2017-09-08 11:33:56 +0200 | [diff] [blame] | 19 | import subprocess |
Rico Wind | b4621c1 | 2017-08-28 12:48:53 +0200 | [diff] [blame] | 20 | import sys |
| 21 | import utils |
Yohann Roussel | 73f58e1 | 2017-10-13 17:33:14 +0200 | [diff] [blame] | 22 | import zipfile |
Rico Wind | b4621c1 | 2017-08-28 12:48:53 +0200 | [diff] [blame] | 23 | |
Rico Wind | 792e8c7 | 2017-08-30 09:43:46 +0200 | [diff] [blame] | 24 | ARCHIVE_BUCKET = 'r8-releases' |
Rico Wind | b4621c1 | 2017-08-28 12:48:53 +0200 | [diff] [blame] | 25 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 26 | |
Rico Wind | 63a1356 | 2018-12-10 14:31:02 +0100 | [diff] [blame] | 27 | def ParseOptions(): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 28 | result = optparse.OptionParser() |
| 29 | result.add_option('--dry-run', |
| 30 | '--dry_run', |
| 31 | help='Build only, no upload.', |
| 32 | default=False, |
| 33 | action='store_true') |
| 34 | result.add_option('--dry-run-output', |
| 35 | '--dry_run_output', |
| 36 | help='Output directory for \'build only, no upload\'.', |
| 37 | type="string", |
| 38 | action="store") |
| 39 | result.add_option( |
| 40 | '--skip-gradle-build', |
| 41 | '--skip_gradle_build', |
| 42 | help='Skip Gradle build. Can only be used for local testing.', |
| 43 | default=False, |
| 44 | action='store_true') |
| 45 | return result.parse_args() |
| 46 | |
Rico Wind | 63a1356 | 2018-12-10 14:31:02 +0100 | [diff] [blame] | 47 | |
Rico Wind | b4621c1 | 2017-08-28 12:48:53 +0200 | [diff] [blame] | 48 | def GetVersion(): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 49 | output = subprocess.check_output([ |
| 50 | jdk.GetJavaExecutable(), '-cp', utils.R8_JAR, 'com.android.tools.r8.R8', |
| 51 | '--version' |
| 52 | ]).decode('utf-8') |
| 53 | r8_version = output.splitlines()[0].strip() |
| 54 | return r8_version.split()[1] |
| 55 | |
Rico Wind | b4621c1 | 2017-08-28 12:48:53 +0200 | [diff] [blame] | 56 | |
Rico Wind | 0c24ae7 | 2017-09-08 11:33:56 +0200 | [diff] [blame] | 57 | def GetGitBranches(): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 58 | return subprocess.check_output(['git', 'show', '-s', '--pretty=%d', 'HEAD']) |
| 59 | |
Rico Wind | b4621c1 | 2017-08-28 12:48:53 +0200 | [diff] [blame] | 60 | |
Rico Wind | 0c24ae7 | 2017-09-08 11:33:56 +0200 | [diff] [blame] | 61 | def GetGitHash(): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 62 | return subprocess.check_output(['git', 'rev-parse', |
| 63 | 'HEAD']).decode('utf-8').strip() |
| 64 | |
Rico Wind | b4621c1 | 2017-08-28 12:48:53 +0200 | [diff] [blame] | 65 | |
Rico Wind | 1b52acf | 2021-03-21 12:36:55 +0100 | [diff] [blame] | 66 | def IsMain(version): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 67 | branches = subprocess.check_output( |
| 68 | ['git', 'branch', '-r', '--contains', 'HEAD']).decode('utf-8') |
| 69 | # CL runs from gerrit does not have a branch, we always treat them as main |
| 70 | # commits to archive these to the hash based location |
| 71 | if len(branches) == 0: |
| 72 | return True |
| 73 | if not version == 'main': |
| 74 | # Sanity check, we don't want to archive on top of release builds EVER |
| 75 | # Note that even though we branch, we never push the bots to build the same |
| 76 | # commit as main on a branch since we always change the version to |
| 77 | # not be just 'main' (or we crash here :-)). |
| 78 | if 'origin/main' in branches: |
| 79 | raise Exception('We are seeing origin/main in a commit that ' |
| 80 | 'don\'t have \'main\' as version') |
| 81 | return False |
| 82 | if not 'origin/main' in branches: |
| 83 | raise Exception('We are not seeing origin/main ' |
| 84 | 'in a commit that have \'main\' as version') |
Rico Wind | d450ba1 | 2019-04-24 13:18:40 +0200 | [diff] [blame] | 85 | return True |
Rico Wind | 0c24ae7 | 2017-09-08 11:33:56 +0200 | [diff] [blame] | 86 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 87 | |
| 88 | def GetStorageDestination(storage_prefix, version_or_path, file_name, is_main): |
| 89 | # We archive main commits under raw/main instead of directly under raw |
| 90 | version_dir = GetVersionDestination(storage_prefix, version_or_path, |
| 91 | is_main) |
| 92 | return '%s/%s' % (version_dir, file_name) |
| 93 | |
Rico Wind | 1a29c4f | 2018-01-25 08:43:08 +0100 | [diff] [blame] | 94 | |
Rico Wind | 72e8870 | 2023-10-03 16:55:30 +0200 | [diff] [blame] | 95 | def GetVersionDestination(storage_prefix, version_or_path, is_main): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 96 | archive_dir = 'raw/main' if is_main else 'raw' |
| 97 | return '%s%s/%s/%s' % (storage_prefix, ARCHIVE_BUCKET, archive_dir, |
| 98 | version_or_path) |
| 99 | |
Rico Wind | 0c24ae7 | 2017-09-08 11:33:56 +0200 | [diff] [blame] | 100 | |
Rico Wind | 72e8870 | 2023-10-03 16:55:30 +0200 | [diff] [blame] | 101 | def GetUploadDestination(version_or_path, file_name, is_main): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 102 | return GetStorageDestination('gs://', version_or_path, file_name, is_main) |
| 103 | |
Rico Wind | 0c24ae7 | 2017-09-08 11:33:56 +0200 | [diff] [blame] | 104 | |
Rico Wind | 72e8870 | 2023-10-03 16:55:30 +0200 | [diff] [blame] | 105 | def GetUrl(version_or_path, file_name, is_main): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 106 | return GetStorageDestination('https://storage.googleapis.com/', |
| 107 | version_or_path, file_name, is_main) |
| 108 | |
Rico Wind | c0b1638 | 2018-05-17 13:23:43 +0200 | [diff] [blame] | 109 | |
Rico Wind | 72e8870 | 2023-10-03 16:55:30 +0200 | [diff] [blame] | 110 | def GetMavenUrl(is_main): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 111 | return GetVersionDestination('https://storage.googleapis.com/', '', is_main) |
| 112 | |
Rico Wind | b4621c1 | 2017-08-28 12:48:53 +0200 | [diff] [blame] | 113 | |
Rico Wind | 7219bb0 | 2019-03-18 08:30:12 +0100 | [diff] [blame] | 114 | def SetRLimitToMax(): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 115 | (soft, hard) = resource.getrlimit(resource.RLIMIT_NOFILE) |
| 116 | resource.setrlimit(resource.RLIMIT_NOFILE, (hard, hard)) |
| 117 | |
Rico Wind | 7219bb0 | 2019-03-18 08:30:12 +0100 | [diff] [blame] | 118 | |
Rico Wind | cea9ce0 | 2019-03-06 14:25:52 +0100 | [diff] [blame] | 119 | def PrintResourceInfo(): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 120 | (soft, hard) = resource.getrlimit(resource.RLIMIT_NOFILE) |
| 121 | print('INFO: Open files soft limit: %s' % soft) |
| 122 | print('INFO: Open files hard limit: %s' % hard) |
Rico Wind | cea9ce0 | 2019-03-06 14:25:52 +0100 | [diff] [blame] | 123 | |
Rico Wind | 293d6e0 | 2023-09-14 15:15:47 +0200 | [diff] [blame] | 124 | |
Ian Zerny | 566046e | 2024-01-04 14:24:56 +0100 | [diff] [blame] | 125 | def RSyncDir(src_dir, version_or_path, dst_dir, is_main, options): |
| 126 | destination = GetUploadDestination(version_or_path, dst_dir, is_main) |
| 127 | print(f'RSyncing {src_dir} to {destination}') |
| 128 | if options.dry_run: |
| 129 | if options.dry_run_output: |
| 130 | dry_run_destination = os.path.join(options.dry_run_output, version_or_path, dst_dir) |
| 131 | print(f'Dry run, not actually syncing. Copying to {dry_run_destination}') |
| 132 | shutil.copytree(src_dir, dry_run_destination) |
| 133 | else: |
| 134 | print('Dry run, not actually uploading') |
| 135 | else: |
| 136 | utils.rsync_directory_to_cloud_storage(src_dir, destination) |
| 137 | print(f'Directory available at: {GetUrl(version_or_path, dst_dir, is_main)}') |
| 138 | |
Ian Zerny | 1548e3e | 2023-11-22 10:11:37 +0100 | [diff] [blame] | 139 | def UploadDir(src_dir, version_or_path, dst_dir, is_main, options): |
| 140 | destination = GetUploadDestination(version_or_path, dst_dir, is_main) |
| 141 | print(f'Uploading {src_dir} to {destination}') |
| 142 | if options.dry_run: |
| 143 | if options.dry_run_output: |
| 144 | dry_run_destination = os.path.join(options.dry_run_output, version_or_path, dst_dir) |
| 145 | print(f'Dry run, not actually uploading. Copying to {dry_run_destination}') |
| 146 | shutil.copytree(src_dir, dry_run_destination) |
| 147 | else: |
| 148 | print('Dry run, not actually uploading') |
| 149 | else: |
| 150 | utils.upload_directory_to_cloud_storage(src_dir, destination) |
| 151 | print(f'Directory available at: {GetUrl(version_or_path, dst_dir, is_main)}') |
| 152 | |
| 153 | |
Rico Wind | b4621c1 | 2017-08-28 12:48:53 +0200 | [diff] [blame] | 154 | def Main(): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 155 | (options, args) = ParseOptions() |
| 156 | Run(options) |
| 157 | |
Rico Wind | 293d6e0 | 2023-09-14 15:15:47 +0200 | [diff] [blame] | 158 | |
Rico Wind | 72e8870 | 2023-10-03 16:55:30 +0200 | [diff] [blame] | 159 | def Run(options): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 160 | if not utils.is_bot() and not options.dry_run: |
| 161 | raise Exception('You are not a bot, don\'t archive builds. ' + |
| 162 | 'Use --dry-run to test locally') |
| 163 | if (options.dry_run_output and |
| 164 | (not os.path.exists(options.dry_run_output) or |
| 165 | not os.path.isdir(options.dry_run_output))): |
| 166 | raise Exception(options.dry_run_output + |
| 167 | ' does not exist or is not a directory') |
| 168 | if (options.skip_gradle_build and not options.dry_run): |
| 169 | raise Exception( |
| 170 | 'Using --skip-gradle-build only supported with --dry-run') |
Tamas Kenez | 180be09 | 2018-12-05 15:23:06 +0100 | [diff] [blame] | 171 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 172 | if utils.is_bot() and not utils.IsWindows(): |
| 173 | SetRLimitToMax() |
| 174 | if not utils.IsWindows(): |
| 175 | PrintResourceInfo() |
Søren Gjesse | 6e5e584 | 2019-09-03 08:48:30 +0200 | [diff] [blame] | 176 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 177 | with utils.TempDir() as temp: |
| 178 | version_file = os.path.join(temp, 'r8-version.properties') |
| 179 | with open(version_file, 'w') as version_writer: |
| 180 | version_writer.write('version.sha=' + GetGitHash() + '\n') |
| 181 | if not os.environ.get('SWARMING_BOT_ID') and not options.dry_run: |
| 182 | raise Exception('Environment variable SWARMING_BOT_ID not set') |
Søren Gjesse | c425e6a | 2019-06-28 11:41:14 +0200 | [diff] [blame] | 183 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 184 | releaser = \ |
| 185 | ("<local developer build>" if options.dry_run |
| 186 | else 'releaser=go/r8bot (' |
| 187 | + (os.environ.get('SWARMING_BOT_ID') or 'foo') + ')\n') |
| 188 | version_writer.write(releaser) |
| 189 | version_writer.write('version-file.version.code=1\n') |
Yohann Roussel | 73f58e1 | 2017-10-13 17:33:14 +0200 | [diff] [blame] | 190 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 191 | create_maven_release.generate_r8_maven_zip( |
| 192 | utils.MAVEN_ZIP_LIB, |
| 193 | version_file=version_file, |
| 194 | skip_gradle_build=options.skip_gradle_build) |
Rico Wind | 293d6e0 | 2023-09-14 15:15:47 +0200 | [diff] [blame] | 195 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 196 | # Ensure all archived artifacts has been built before archiving. |
| 197 | # The target tasks postfixed by 'lib' depend on the actual target task so |
| 198 | # building it invokes the original task first. |
| 199 | # The '-Pno_internal' flag is important because we generate the lib based on uses in tests. |
| 200 | if (not options.skip_gradle_build): |
| 201 | gradle.RunGradle([ |
| 202 | utils.GRADLE_TASK_CONSOLIDATED_LICENSE, |
Ian Zerny | a6af777 | 2023-11-21 14:05:57 +0100 | [diff] [blame] | 203 | utils.GRADLE_TASK_KEEP_ANNO_JAR, |
| 204 | utils.GRADLE_TASK_KEEP_ANNO_DOC, |
| 205 | utils.GRADLE_TASK_R8, |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 206 | utils.GRADLE_TASK_R8LIB, utils.GRADLE_TASK_R8LIB_NO_DEPS, |
Ian Zerny | 077a73f | 2023-10-31 09:05:47 +0100 | [diff] [blame] | 207 | utils.GRADLE_TASK_THREADING_MODULE_BLOCKING, |
| 208 | utils.GRADLE_TASK_THREADING_MODULE_SINGLE_THREADED, |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 209 | utils.GRADLE_TASK_SOURCE_JAR, |
| 210 | utils.GRADLE_TASK_SWISS_ARMY_KNIFE, '-Pno_internal' |
| 211 | ]) |
Rico Wind | cdc39b6 | 2022-04-08 12:37:57 +0200 | [diff] [blame] | 212 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 213 | # Create maven release of the desuage_jdk_libs configuration. This require |
| 214 | # an r8.jar with dependencies to have been built. |
| 215 | create_maven_release.generate_desugar_configuration_maven_zip( |
| 216 | utils.DESUGAR_CONFIGURATION_MAVEN_ZIP, utils.DESUGAR_CONFIGURATION, |
| 217 | utils.DESUGAR_IMPLEMENTATION, |
| 218 | utils.LIBRARY_DESUGAR_CONVERSIONS_LEGACY_ZIP) |
| 219 | create_maven_release.generate_desugar_configuration_maven_zip( |
| 220 | utils.DESUGAR_CONFIGURATION_JDK11_LEGACY_MAVEN_ZIP, |
| 221 | utils.DESUGAR_CONFIGURATION_JDK11_LEGACY, |
| 222 | utils.DESUGAR_IMPLEMENTATION_JDK11, |
| 223 | utils.LIBRARY_DESUGAR_CONVERSIONS_LEGACY_ZIP) |
Rico Wind | cdc39b6 | 2022-04-08 12:37:57 +0200 | [diff] [blame] | 224 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 225 | create_maven_release.generate_desugar_configuration_maven_zip( |
| 226 | utils.DESUGAR_CONFIGURATION_JDK11_MINIMAL_MAVEN_ZIP, |
| 227 | utils.DESUGAR_CONFIGURATION_JDK11_MINIMAL, |
| 228 | utils.DESUGAR_IMPLEMENTATION_JDK11, |
| 229 | utils.LIBRARY_DESUGAR_CONVERSIONS_ZIP) |
| 230 | create_maven_release.generate_desugar_configuration_maven_zip( |
| 231 | utils.DESUGAR_CONFIGURATION_JDK11_MAVEN_ZIP, |
| 232 | utils.DESUGAR_CONFIGURATION_JDK11, |
| 233 | utils.DESUGAR_IMPLEMENTATION_JDK11, |
| 234 | utils.LIBRARY_DESUGAR_CONVERSIONS_ZIP) |
| 235 | create_maven_release.generate_desugar_configuration_maven_zip( |
| 236 | utils.DESUGAR_CONFIGURATION_JDK11_NIO_MAVEN_ZIP, |
| 237 | utils.DESUGAR_CONFIGURATION_JDK11_NIO, |
| 238 | utils.DESUGAR_IMPLEMENTATION_JDK11, |
| 239 | utils.LIBRARY_DESUGAR_CONVERSIONS_ZIP) |
Søren Gjesse | 2b04769 | 2022-08-19 16:34:38 +0200 | [diff] [blame] | 240 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 241 | version = GetVersion() |
| 242 | is_main = IsMain(version) |
| 243 | if is_main: |
| 244 | # On main we use the git hash to archive with |
| 245 | print('On main, using git hash for archiving') |
| 246 | version = GetGitHash() |
Rico Wind | cdc39b6 | 2022-04-08 12:37:57 +0200 | [diff] [blame] | 247 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 248 | destination = GetVersionDestination('gs://', version, is_main) |
| 249 | if utils.cloud_storage_exists(destination) and not options.dry_run: |
| 250 | raise Exception('Target archive directory %s already exists' % |
| 251 | destination) |
Rico Wind | cdc39b6 | 2022-04-08 12:37:57 +0200 | [diff] [blame] | 252 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 253 | # Create pom file for our maven repository that we build for testing. |
| 254 | default_pom_file = os.path.join(temp, 'r8.pom') |
| 255 | create_maven_release.write_default_r8_pom_file(default_pom_file, |
| 256 | version) |
Søren Gjesse | 4569e47 | 2023-10-25 15:15:17 +0200 | [diff] [blame] | 257 | gradle.RunGradle([ |
| 258 | ':main:spdxSbom', |
| 259 | '-PspdxVersion=' + version, |
| 260 | '-PspdxRevision=' + GetGitHash() |
| 261 | ]) |
| 262 | |
Ian Zerny | 1548e3e | 2023-11-22 10:11:37 +0100 | [diff] [blame] | 263 | # Upload keep-anno javadoc to a fixed "docs" location. |
| 264 | if is_main: |
| 265 | version_or_path = 'docs' |
| 266 | dst_dir = 'keepanno/javadoc' |
Ian Zerny | 566046e | 2024-01-04 14:24:56 +0100 | [diff] [blame] | 267 | RSyncDir(utils.KEEPANNO_ANNOTATIONS_DOC, version_or_path, dst_dir, is_main, options) |
Ian Zerny | 1548e3e | 2023-11-22 10:11:37 +0100 | [diff] [blame] | 268 | |
Ian Zerny | a6af777 | 2023-11-21 14:05:57 +0100 | [diff] [blame] | 269 | # Upload directories. |
| 270 | dirs_for_archiving = [ |
Ian Zerny | 1548e3e | 2023-11-22 10:11:37 +0100 | [diff] [blame] | 271 | (utils.KEEPANNO_ANNOTATIONS_DOC, 'keepanno/javadoc'), |
Ian Zerny | a6af777 | 2023-11-21 14:05:57 +0100 | [diff] [blame] | 272 | ] |
| 273 | for (src_dir, dst_dir) in dirs_for_archiving: |
Ian Zerny | 1548e3e | 2023-11-22 10:11:37 +0100 | [diff] [blame] | 274 | UploadDir(src_dir, version, dst_dir, is_main, options) |
Ian Zerny | a6af777 | 2023-11-21 14:05:57 +0100 | [diff] [blame] | 275 | |
| 276 | # Upload files. |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 277 | for_archiving = [ |
| 278 | utils.R8_JAR, utils.R8LIB_JAR, utils.R8LIB_JAR + '.map', |
| 279 | utils.R8LIB_JAR + '_map.zip', utils.R8_FULL_EXCLUDE_DEPS_JAR, |
| 280 | utils.R8LIB_EXCLUDE_DEPS_JAR, utils.R8LIB_EXCLUDE_DEPS_JAR + '.map', |
| 281 | utils.R8LIB_EXCLUDE_DEPS_JAR + '_map.zip', utils.MAVEN_ZIP_LIB, |
Ian Zerny | 077a73f | 2023-10-31 09:05:47 +0100 | [diff] [blame] | 282 | utils.THREADING_MODULE_BLOCKING_JAR, |
| 283 | utils.THREADING_MODULE_SINGLE_THREADED_JAR, |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 284 | utils.DESUGAR_CONFIGURATION, utils.DESUGAR_CONFIGURATION_MAVEN_ZIP, |
| 285 | utils.DESUGAR_CONFIGURATION_JDK11_LEGACY, |
| 286 | utils.DESUGAR_CONFIGURATION_JDK11_LEGACY_MAVEN_ZIP, |
| 287 | utils.DESUGAR_CONFIGURATION_JDK11_MINIMAL_MAVEN_ZIP, |
| 288 | utils.DESUGAR_CONFIGURATION_JDK11_MAVEN_ZIP, |
| 289 | utils.DESUGAR_CONFIGURATION_JDK11_NIO_MAVEN_ZIP, utils.R8_SRC_JAR, |
Søren Gjesse | 4569e47 | 2023-10-25 15:15:17 +0200 | [diff] [blame] | 290 | utils.KEEPANNO_ANNOTATIONS_JAR, |
| 291 | utils.GENERATED_LICENSE, |
| 292 | 'd8_r8/main/build/spdx/r8.spdx.json' |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 293 | ] |
| 294 | for file in for_archiving: |
| 295 | file_name = os.path.basename(file) |
| 296 | tagged_jar = os.path.join(temp, file_name) |
| 297 | shutil.copyfile(file, tagged_jar) |
| 298 | if file_name.endswith( |
| 299 | '.jar') and not file_name.endswith('-src.jar'): |
| 300 | with zipfile.ZipFile(tagged_jar, 'a') as zip: |
| 301 | zip.write(version_file, os.path.basename(version_file)) |
| 302 | destination = GetUploadDestination(version, file_name, is_main) |
| 303 | print('Uploading %s to %s' % (tagged_jar, destination)) |
| 304 | if options.dry_run: |
| 305 | if options.dry_run_output: |
Ian Zerny | 1548e3e | 2023-11-22 10:11:37 +0100 | [diff] [blame] | 306 | dry_run_destination = os.path.join( |
| 307 | options.dry_run_output, version, file_name) |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 308 | print('Dry run, not actually uploading. Copying to ' + |
| 309 | dry_run_destination) |
| 310 | shutil.copyfile(tagged_jar, dry_run_destination) |
| 311 | else: |
| 312 | print('Dry run, not actually uploading') |
| 313 | else: |
| 314 | utils.upload_file_to_cloud_storage(tagged_jar, destination) |
| 315 | print('File available at: %s' % |
| 316 | GetUrl(version, file_name, is_main)) |
Søren Gjesse | 6e5e584 | 2019-09-03 08:48:30 +0200 | [diff] [blame] | 317 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 318 | # Upload R8 to a maven compatible location. |
| 319 | if file == utils.R8_JAR: |
| 320 | maven_dst = GetUploadDestination( |
| 321 | utils.get_maven_path('r8', version), 'r8-%s.jar' % version, |
| 322 | is_main) |
| 323 | maven_pom_dst = GetUploadDestination( |
| 324 | utils.get_maven_path('r8', version), 'r8-%s.pom' % version, |
| 325 | is_main) |
| 326 | if options.dry_run: |
| 327 | print('Dry run, not actually creating maven repo for R8') |
| 328 | else: |
| 329 | utils.upload_file_to_cloud_storage(tagged_jar, maven_dst) |
| 330 | utils.upload_file_to_cloud_storage(default_pom_file, |
| 331 | maven_pom_dst) |
| 332 | print('Maven repo root available at: %s' % |
| 333 | GetMavenUrl(is_main)) |
Rico Wind | c0b1638 | 2018-05-17 13:23:43 +0200 | [diff] [blame] | 334 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 335 | # Upload desugar_jdk_libs configuration to a maven compatible location. |
| 336 | if file == utils.DESUGAR_CONFIGURATION: |
| 337 | jar_basename = 'desugar_jdk_libs_configuration.jar' |
| 338 | jar_version_name = 'desugar_jdk_libs_configuration-%s.jar' % version |
| 339 | maven_dst = GetUploadDestination( |
| 340 | utils.get_maven_path('desugar_jdk_libs_configuration', |
| 341 | version), jar_version_name, is_main) |
Søren Gjesse | 6e5e584 | 2019-09-03 08:48:30 +0200 | [diff] [blame] | 342 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 343 | with utils.TempDir() as tmp_dir: |
| 344 | desugar_jdk_libs_configuration_jar = os.path.join( |
| 345 | tmp_dir, jar_version_name) |
| 346 | create_maven_release.generate_jar_with_desugar_configuration( |
| 347 | utils.DESUGAR_CONFIGURATION, |
| 348 | utils.DESUGAR_IMPLEMENTATION, |
| 349 | utils.LIBRARY_DESUGAR_CONVERSIONS_ZIP, |
| 350 | desugar_jdk_libs_configuration_jar) |
Søren Gjesse | 6e5e584 | 2019-09-03 08:48:30 +0200 | [diff] [blame] | 351 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 352 | if options.dry_run: |
| 353 | print('Dry run, not actually creating maven repo for ' + |
| 354 | 'desugar configuration.') |
| 355 | if options.dry_run_output: |
| 356 | shutil.copyfile( |
| 357 | desugar_jdk_libs_configuration_jar, |
| 358 | os.path.join(options.dry_run_output, |
| 359 | jar_version_name)) |
| 360 | else: |
| 361 | utils.upload_file_to_cloud_storage( |
| 362 | desugar_jdk_libs_configuration_jar, maven_dst) |
| 363 | print('Maven repo root available at: %s' % |
| 364 | GetMavenUrl(is_main)) |
| 365 | # Also archive the jar as non maven destination for Google3 |
| 366 | jar_destination = GetUploadDestination( |
| 367 | version, jar_basename, is_main) |
| 368 | utils.upload_file_to_cloud_storage( |
| 369 | desugar_jdk_libs_configuration_jar, jar_destination) |
Rico Wind | 92f796f | 2020-08-25 14:36:18 +0200 | [diff] [blame] | 370 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 371 | # TODO(b/237636871): Refactor this to avoid the duplication of what is above. |
| 372 | # Upload desugar_jdk_libs JDK-11 legacyconfiguration to a maven compatible location. |
| 373 | if file == utils.DESUGAR_CONFIGURATION_JDK11_LEGACY: |
| 374 | jar_basename = 'desugar_jdk_libs_configuration.jar' |
| 375 | jar_version_name = 'desugar_jdk_libs_configuration-%s-jdk11-legacy.jar' % version |
| 376 | maven_dst = GetUploadDestination( |
| 377 | utils.get_maven_path('desugar_jdk_libs_configuration', |
| 378 | version), jar_version_name, is_main) |
Søren Gjesse | e18fa6e | 2022-06-24 15:14:53 +0200 | [diff] [blame] | 379 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 380 | with utils.TempDir() as tmp_dir: |
| 381 | desugar_jdk_libs_configuration_jar = os.path.join( |
| 382 | tmp_dir, jar_version_name) |
| 383 | create_maven_release.generate_jar_with_desugar_configuration( |
| 384 | utils.DESUGAR_CONFIGURATION_JDK11_LEGACY, |
| 385 | utils.DESUGAR_IMPLEMENTATION_JDK11, |
| 386 | utils.LIBRARY_DESUGAR_CONVERSIONS_ZIP, |
| 387 | desugar_jdk_libs_configuration_jar) |
Søren Gjesse | e18fa6e | 2022-06-24 15:14:53 +0200 | [diff] [blame] | 388 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 389 | if options.dry_run: |
| 390 | print('Dry run, not actually creating maven repo for ' + |
| 391 | 'desugar configuration.') |
| 392 | if options.dry_run_output: |
| 393 | shutil.copyfile( |
| 394 | desugar_jdk_libs_configuration_jar, |
| 395 | os.path.join(options.dry_run_output, |
| 396 | jar_version_name)) |
| 397 | else: |
| 398 | utils.upload_file_to_cloud_storage( |
| 399 | desugar_jdk_libs_configuration_jar, maven_dst) |
| 400 | print('Maven repo root available at: %s' % |
| 401 | GetMavenUrl(is_main)) |
| 402 | # Also archive the jar as non maven destination for Google3 |
| 403 | jar_destination = GetUploadDestination( |
| 404 | version, jar_basename, is_main) |
| 405 | utils.upload_file_to_cloud_storage( |
| 406 | desugar_jdk_libs_configuration_jar, jar_destination) |
| 407 | |
Rico Wind | b4621c1 | 2017-08-28 12:48:53 +0200 | [diff] [blame] | 408 | |
| 409 | if __name__ == '__main__': |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 410 | sys.exit(Main()) |