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