Ian Zerny | dcb172e | 2022-02-22 15:36:45 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Mads Ager | a974561 | 2017-11-02 12:42:15 +0100 | [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 | |
Mads Ager | a974561 | 2017-11-02 12:42:15 +0100 | [diff] [blame] | 6 | import argparse |
Mads Ager | a4911eb | 2017-11-22 13:19:36 +0100 | [diff] [blame] | 7 | import gradle |
| 8 | import hashlib |
Søren Gjesse | a70d3bd | 2019-09-24 15:07:00 +0200 | [diff] [blame] | 9 | import jdk |
Søren Gjesse | 6e5e584 | 2019-09-03 08:48:30 +0200 | [diff] [blame] | 10 | import json |
Mads Ager | a974561 | 2017-11-02 12:42:15 +0100 | [diff] [blame] | 11 | from os import makedirs |
Rico Wind | cdc39b6 | 2022-04-08 12:37:57 +0200 | [diff] [blame] | 12 | from os.path import join, basename |
Søren Gjesse | 6e5e584 | 2019-09-03 08:48:30 +0200 | [diff] [blame] | 13 | from shutil import copyfile, make_archive, move, rmtree |
Mads Ager | a974561 | 2017-11-02 12:42:15 +0100 | [diff] [blame] | 14 | import subprocess |
| 15 | import sys |
| 16 | from string import Template |
| 17 | import tempfile |
Mads Ager | 0fab491 | 2017-11-20 13:52:48 +0100 | [diff] [blame] | 18 | import utils |
Søren Gjesse | 17fc67d | 2019-12-04 14:50:17 +0100 | [diff] [blame] | 19 | import zipfile |
Mads Ager | a974561 | 2017-11-02 12:42:15 +0100 | [diff] [blame] | 20 | |
Søren Gjesse | c425e6a | 2019-06-28 11:41:14 +0200 | [diff] [blame] | 21 | LICENSETEMPLATE = Template( |
| 22 | """ |
| 23 | <license> |
| 24 | <name>$name</name> |
| 25 | <url>$url</url> |
| 26 | <distribution>repo</distribution> |
| 27 | </license>""") |
| 28 | |
Søren Gjesse | 6e5e584 | 2019-09-03 08:48:30 +0200 | [diff] [blame] | 29 | R8_POMTEMPLATE = Template( |
Mads Ager | a974561 | 2017-11-02 12:42:15 +0100 | [diff] [blame] | 30 | """<project |
| 31 | xmlns="http://maven.apache.org/POM/4.0.0" |
| 32 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 33 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
| 34 | <modelVersion>4.0.0</modelVersion> |
| 35 | <groupId>com.android.tools</groupId> |
| 36 | <artifactId>r8</artifactId> |
| 37 | <version>$version</version> |
| 38 | <name>D8 dexer and R8 shrinker</name> |
| 39 | <description> |
| 40 | D8 dexer and R8 shrinker. |
| 41 | </description> |
| 42 | <url>http://r8.googlesource.com/r8</url> |
| 43 | <inceptionYear>2016</inceptionYear> |
| 44 | <licenses> |
| 45 | <license> |
| 46 | <name>BSD-3-Clause</name> |
| 47 | <url>https://opensource.org/licenses/BSD-3-Clause</url> |
| 48 | <distribution>repo</distribution> |
Søren Gjesse | c425e6a | 2019-06-28 11:41:14 +0200 | [diff] [blame] | 49 | </license>$library_licenses |
Mads Ager | 7346019 | 2017-11-08 10:02:50 +0100 | [diff] [blame] | 50 | </licenses> |
Rico Wind | d6323ad | 2023-09-14 09:33:59 +0200 | [diff] [blame] | 51 | <dependencies> |
Mads Ager | a4911eb | 2017-11-22 13:19:36 +0100 | [diff] [blame] | 52 | </dependencies> |
Mads Ager | a974561 | 2017-11-02 12:42:15 +0100 | [diff] [blame] | 53 | <developers> |
| 54 | <developer> |
| 55 | <name>The Android Open Source Project</name> |
| 56 | </developer> |
| 57 | </developers> |
| 58 | <scm> |
| 59 | <connection> |
| 60 | https://r8.googlesource.com/r8.git |
| 61 | </connection> |
| 62 | <url> |
| 63 | https://r8.googlesource.com/r8 |
| 64 | </url> |
| 65 | </scm> |
| 66 | </project> |
| 67 | """) |
| 68 | |
Søren Gjesse | 6e5e584 | 2019-09-03 08:48:30 +0200 | [diff] [blame] | 69 | DESUGAR_CONFIGUATION_POMTEMPLATE = Template( |
| 70 | """<project |
| 71 | xmlns="http://maven.apache.org/POM/4.0.0" |
| 72 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 73 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
| 74 | <modelVersion>4.0.0</modelVersion> |
| 75 | <groupId>com.android.tools</groupId> |
Søren Gjesse | 2b04769 | 2022-08-19 16:34:38 +0200 | [diff] [blame] | 76 | <artifactId>$artifactId</artifactId> |
Søren Gjesse | 6e5e584 | 2019-09-03 08:48:30 +0200 | [diff] [blame] | 77 | <version>$version</version> |
| 78 | <name>D8 configuration to desugar desugar_jdk_libs</name> |
| 79 | <description> |
| 80 | D8 configuration to desugar desugar_jdk_libs. |
| 81 | </description> |
| 82 | <url>http://r8.googlesource.com/r8</url> |
| 83 | <inceptionYear>2019</inceptionYear> |
| 84 | <licenses> |
| 85 | <license> |
| 86 | <name>BSD-3-Clause</name> |
| 87 | <url>https://opensource.org/licenses/BSD-3-Clause</url> |
| 88 | <distribution>repo</distribution> |
| 89 | </license> |
| 90 | </licenses> |
Søren Gjesse | 6e5e584 | 2019-09-03 08:48:30 +0200 | [diff] [blame] | 91 | <developers> |
| 92 | <developer> |
| 93 | <name>The Android Open Source Project</name> |
| 94 | </developer> |
| 95 | </developers> |
| 96 | <scm> |
| 97 | <connection> |
| 98 | https://r8.googlesource.com/r8.git |
| 99 | </connection> |
| 100 | <url> |
| 101 | https://r8.googlesource.com/r8 |
| 102 | </url> |
| 103 | </scm> |
| 104 | </project> |
| 105 | """) |
| 106 | |
Mads Ager | a974561 | 2017-11-02 12:42:15 +0100 | [diff] [blame] | 107 | def parse_options(argv): |
| 108 | result = argparse.ArgumentParser() |
Rico Wind | 8fc8bfa | 2019-03-22 09:57:36 +0100 | [diff] [blame] | 109 | result.add_argument('--out', help='The zip file to output') |
Søren Gjesse | 705a3b1 | 2022-03-17 11:37:30 +0100 | [diff] [blame] | 110 | group = result.add_mutually_exclusive_group() |
Søren Gjesse | 705a3b1 | 2022-03-17 11:37:30 +0100 | [diff] [blame] | 111 | group.add_argument('--desugar-configuration', action='store_true', |
| 112 | help='Build desugar library configuration (original JDK-8)') |
| 113 | group.add_argument('--desugar-configuration-jdk8', action='store_true', |
| 114 | help='Build desugar library configuration (original JDK-8)') |
| 115 | group.add_argument('--desugar-configuration-jdk11-legacy', action='store_true', |
| 116 | help='Build desugar library configuration (JDK-11 legacy)') |
Søren Gjesse | 1a8ccad | 2023-06-06 15:00:46 +0200 | [diff] [blame] | 117 | group.add_argument('--desugar-configuration-jdk11-minimal', action='store_true', |
| 118 | help='Build desugar library configuration (JDK-11 minimal)') |
| 119 | group.add_argument('--desugar-configuration-jdk11', action='store_true', |
| 120 | help='Build desugar library configuration (JDK-11)') |
| 121 | group.add_argument('--desugar-configuration-jdk11-nio', action='store_true', |
| 122 | help='Build desugar library configuration (JDK-11 nio)') |
Mads Ager | a974561 | 2017-11-02 12:42:15 +0100 | [diff] [blame] | 123 | return result.parse_args(argv) |
| 124 | |
Mads Ager | a4911eb | 2017-11-22 13:19:36 +0100 | [diff] [blame] | 125 | def determine_version(): |
| 126 | version_file = join( |
| 127 | utils.SRC_ROOT, 'com', 'android', 'tools', 'r8', 'Version.java') |
| 128 | with open(version_file, 'r') as file: |
| 129 | for line in file: |
| 130 | if 'final String LABEL ' in line: |
Rico Wind | 6feccf2 | 2018-05-08 11:18:22 +0200 | [diff] [blame] | 131 | result = line[line.find('"') + 1:] |
Mads Ager | a4911eb | 2017-11-22 13:19:36 +0100 | [diff] [blame] | 132 | result = result[:result.find('"')] |
| 133 | return result |
| 134 | raise Exception('Unable to determine version.') |
Mads Ager | a974561 | 2017-11-02 12:42:15 +0100 | [diff] [blame] | 135 | |
| 136 | def generate_library_licenses(): |
Søren Gjesse | c425e6a | 2019-06-28 11:41:14 +0200 | [diff] [blame] | 137 | artifact_prefix = '- artifact: ' |
Mads Ager | a974561 | 2017-11-02 12:42:15 +0100 | [diff] [blame] | 138 | license_prefix = 'license: ' |
| 139 | licenses = [] |
| 140 | license_url_prefix = 'licenseUrl: ' |
| 141 | license_urls = [] |
Søren Gjesse | ea67830 | 2019-08-27 14:41:03 +0200 | [diff] [blame] | 142 | # The ./LIBRARY-LICENSE file is a simple yaml file, which for each dependency |
| 143 | # has the following information: |
| 144 | # |
| 145 | # - artifact: <maven artifact> // in the form <group-id>:<artifact-id>:+ |
| 146 | # name: <name of dependency> |
| 147 | # copyrightHolder: <name of copyright holder> |
| 148 | # license: <license name> |
| 149 | # licenseUrl: <url to license test> |
| 150 | # |
| 151 | # E.g. for Guava: |
| 152 | # |
| 153 | # - artifact: com.google.guava:guava:+ |
| 154 | # name: Guava Google Core Libraries for Java |
| 155 | # copyrightHolder: The Guava Authors |
| 156 | # license: The Apache Software License, Version 2.0 |
| 157 | # licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt |
| 158 | # |
| 159 | # This file should always be up to date as the build will fail if it |
| 160 | # is does not have information for all dependencies. |
Mads Ager | a974561 | 2017-11-02 12:42:15 +0100 | [diff] [blame] | 161 | with open('LIBRARY-LICENSE', 'r') as file: |
Søren Gjesse | c425e6a | 2019-06-28 11:41:14 +0200 | [diff] [blame] | 162 | name = None |
| 163 | url = None |
Mads Ager | a974561 | 2017-11-02 12:42:15 +0100 | [diff] [blame] | 164 | for line in file: |
| 165 | trimmed = line.strip() |
Søren Gjesse | c425e6a | 2019-06-28 11:41:14 +0200 | [diff] [blame] | 166 | # Collect license name and url for each artifact. They must come in |
| 167 | # pairs for each artifact. |
| 168 | if trimmed.startswith(artifact_prefix): |
| 169 | assert not name |
| 170 | assert not url |
Mads Ager | a974561 | 2017-11-02 12:42:15 +0100 | [diff] [blame] | 171 | if trimmed.startswith(license_prefix): |
Mads Ager | a974561 | 2017-11-02 12:42:15 +0100 | [diff] [blame] | 172 | name = trimmed[len(license_prefix):] |
Mads Ager | a974561 | 2017-11-02 12:42:15 +0100 | [diff] [blame] | 173 | if trimmed.startswith(license_url_prefix): |
| 174 | url = trimmed[len(license_url_prefix):] |
Søren Gjesse | c425e6a | 2019-06-28 11:41:14 +0200 | [diff] [blame] | 175 | # Licenses come in name/url pairs. When both are present add pair |
| 176 | # to collected licenses if either name or url has not been recorded yet, |
| 177 | # as some licenses with slightly different names point to the same url. |
| 178 | if name and url: |
| 179 | if (not name in licenses) or (not url in license_urls): |
| 180 | licenses.append(name) |
Mads Ager | a974561 | 2017-11-02 12:42:15 +0100 | [diff] [blame] | 181 | license_urls.append(url) |
Søren Gjesse | c425e6a | 2019-06-28 11:41:14 +0200 | [diff] [blame] | 182 | name = None |
| 183 | url = None |
| 184 | assert len(licenses) == len(license_urls) |
Mads Ager | a974561 | 2017-11-02 12:42:15 +0100 | [diff] [blame] | 185 | result = '' |
| 186 | for i in range(len(licenses)): |
| 187 | name = licenses[i] |
| 188 | url = license_urls[i] |
| 189 | result += LICENSETEMPLATE.substitute(name=name, url=url) |
| 190 | return result |
| 191 | |
Rico Wind | 257044c | 2019-11-22 08:21:21 +0100 | [diff] [blame] | 192 | def write_default_r8_pom_file(pom_file, version): |
Rico Wind | df585e8 | 2023-09-14 09:16:49 +0200 | [diff] [blame] | 193 | write_pom_file(R8_POMTEMPLATE, pom_file, version) |
Rico Wind | 257044c | 2019-11-22 08:21:21 +0100 | [diff] [blame] | 194 | |
Søren Gjesse | 2b04769 | 2022-08-19 16:34:38 +0200 | [diff] [blame] | 195 | def write_pom_file( |
Rico Wind | d6323ad | 2023-09-14 09:33:59 +0200 | [diff] [blame] | 196 | template, pom_file, version, artifact_id=None, library_licenses=''): |
Søren Gjesse | 2b04769 | 2022-08-19 16:34:38 +0200 | [diff] [blame] | 197 | version_pom = ( |
| 198 | template.substitute( |
| 199 | artifactId=artifact_id, |
| 200 | version=version, |
Søren Gjesse | 2b04769 | 2022-08-19 16:34:38 +0200 | [diff] [blame] | 201 | library_licenses=library_licenses) |
| 202 | if artifact_id else |
| 203 | template.substitute( |
Rico Wind | d6323ad | 2023-09-14 09:33:59 +0200 | [diff] [blame] | 204 | version=version, library_licenses=library_licenses)) |
Mads Ager | a974561 | 2017-11-02 12:42:15 +0100 | [diff] [blame] | 205 | with open(pom_file, 'w') as file: |
| 206 | file.write(version_pom) |
| 207 | |
| 208 | def hash_for(file, hash): |
| 209 | with open(file, 'rb') as f: |
| 210 | while True: |
| 211 | # Read chunks of 1MB |
| 212 | chunk = f.read(2 ** 20) |
| 213 | if not chunk: |
| 214 | break |
| 215 | hash.update(chunk) |
| 216 | return hash.hexdigest() |
| 217 | |
| 218 | def write_md5_for(file): |
| 219 | hexdigest = hash_for(file, hashlib.md5()) |
| 220 | with (open(file + '.md5', 'w')) as file: |
| 221 | file.write(hexdigest) |
| 222 | |
| 223 | def write_sha1_for(file): |
| 224 | hexdigest = hash_for(file, hashlib.sha1()) |
| 225 | with (open(file + '.sha1', 'w')) as file: |
| 226 | file.write(hexdigest) |
| 227 | |
Søren Gjesse | 6e5e584 | 2019-09-03 08:48:30 +0200 | [diff] [blame] | 228 | def generate_maven_zip(name, version, pom_file, jar_file, out): |
Mads Ager | 14d9b07 | 2017-11-20 13:42:55 +0100 | [diff] [blame] | 229 | with utils.TempDir() as tmp_dir: |
Søren Gjesse | 6e5e584 | 2019-09-03 08:48:30 +0200 | [diff] [blame] | 230 | # Create the base maven version directory |
| 231 | version_dir = join(tmp_dir, utils.get_maven_path(name, version)) |
Mads Ager | 14d9b07 | 2017-11-20 13:42:55 +0100 | [diff] [blame] | 232 | makedirs(version_dir) |
| 233 | # Write the pom file. |
Søren Gjesse | 6e5e584 | 2019-09-03 08:48:30 +0200 | [diff] [blame] | 234 | pom_file_location = join(version_dir, name + '-' + version + '.pom') |
| 235 | copyfile(pom_file, pom_file_location) |
| 236 | # Write the jar file. |
| 237 | jar_file_location = join(version_dir, name + '-' + version + '.jar') |
| 238 | copyfile(jar_file, jar_file_location) |
Mads Ager | 14d9b07 | 2017-11-20 13:42:55 +0100 | [diff] [blame] | 239 | # Create check sums. |
Søren Gjesse | 6e5e584 | 2019-09-03 08:48:30 +0200 | [diff] [blame] | 240 | write_md5_for(jar_file_location) |
| 241 | write_md5_for(pom_file_location) |
| 242 | write_sha1_for(jar_file_location) |
| 243 | write_sha1_for(pom_file_location) |
Rico Wind | 8fc8bfa | 2019-03-22 09:57:36 +0100 | [diff] [blame] | 244 | # Zip it up - make_archive will append zip to the file, so remove. |
| 245 | assert out.endswith('.zip') |
| 246 | base_no_zip = out[0:len(out)-4] |
| 247 | make_archive(base_no_zip, 'zip', tmp_dir) |
| 248 | |
Rico Wind | 293d6e0 | 2023-09-14 15:15:47 +0200 | [diff] [blame] | 249 | def generate_r8_maven_zip(out, version_file=None, skip_gradle_build=False, |
| 250 | new_gradle=False): |
Søren Gjesse | 1b035b3 | 2022-08-19 08:53:57 +0200 | [diff] [blame] | 251 | if not skip_gradle_build: |
Rico Wind | 293d6e0 | 2023-09-14 15:15:47 +0200 | [diff] [blame] | 252 | if (new_gradle): |
Rico Wind | 49f16fe | 2023-09-15 11:13:23 +0200 | [diff] [blame] | 253 | gradle.RunGradle([':test:r8LibWithRelocatedDeps', |
| 254 | '-Pno_internal'], new_gradle=True) |
Rico Wind | 293d6e0 | 2023-09-14 15:15:47 +0200 | [diff] [blame] | 255 | else: |
| 256 | gradle.RunGradle([utils.R8LIB, '-Pno_internal']) |
Søren Gjesse | 6e5e584 | 2019-09-03 08:48:30 +0200 | [diff] [blame] | 257 | |
| 258 | version = determine_version() |
Rico Wind | 52ece1b | 2020-08-25 14:33:17 +0200 | [diff] [blame] | 259 | with utils.TempDir() as tmp_dir: |
Rico Wind | cdc39b6 | 2022-04-08 12:37:57 +0200 | [diff] [blame] | 260 | file_copy = join(tmp_dir, 'copy_of_jar.jar') |
Rico Wind | d6323ad | 2023-09-14 09:33:59 +0200 | [diff] [blame] | 261 | copyfile(utils.R8LIB_JAR, file_copy) |
Rico Wind | cdc39b6 | 2022-04-08 12:37:57 +0200 | [diff] [blame] | 262 | |
| 263 | if version_file: |
| 264 | with zipfile.ZipFile(file_copy, 'a') as zip: |
| 265 | zip.write(version_file, basename(version_file)) |
| 266 | |
Rico Wind | 52ece1b | 2020-08-25 14:33:17 +0200 | [diff] [blame] | 267 | # Generate the pom file. |
| 268 | pom_file = join(tmp_dir, 'r8.pom') |
| 269 | write_pom_file( |
| 270 | R8_POMTEMPLATE, |
| 271 | pom_file, |
| 272 | version, |
Rico Wind | d6323ad | 2023-09-14 09:33:59 +0200 | [diff] [blame] | 273 | library_licenses=generate_library_licenses()) |
Rico Wind | 52ece1b | 2020-08-25 14:33:17 +0200 | [diff] [blame] | 274 | # Write the maven zip file. |
| 275 | generate_maven_zip( |
| 276 | 'r8', |
| 277 | version, |
| 278 | pom_file, |
Rico Wind | cdc39b6 | 2022-04-08 12:37:57 +0200 | [diff] [blame] | 279 | file_copy, |
Rico Wind | 52ece1b | 2020-08-25 14:33:17 +0200 | [diff] [blame] | 280 | out) |
Søren Gjesse | 6e5e584 | 2019-09-03 08:48:30 +0200 | [diff] [blame] | 281 | |
| 282 | # Write the desugaring configuration of a jar file with the following content: |
Søren Gjesse | 17fc67d | 2019-12-04 14:50:17 +0100 | [diff] [blame] | 283 | # java/ |
| 284 | # util/ |
| 285 | # <java.util conversions classes> |
| 286 | # time/ |
| 287 | # <java.time conversions classes> |
| 288 | # META-INF/ |
| 289 | # desugar/ |
| 290 | # d8/ |
Søren Gjesse | 6e5e584 | 2019-09-03 08:48:30 +0200 | [diff] [blame] | 291 | # desugar.json |
Søren Gjesse | 17fc67d | 2019-12-04 14:50:17 +0100 | [diff] [blame] | 292 | # lint/ |
| 293 | # <lint files> |
Søren Gjesse | d98f24c | 2020-10-30 12:42:31 +0100 | [diff] [blame] | 294 | def generate_jar_with_desugar_configuration( |
| 295 | configuration, implementation, conversions, destination): |
Søren Gjesse | 6e5e584 | 2019-09-03 08:48:30 +0200 | [diff] [blame] | 296 | with utils.TempDir() as tmp_dir: |
Søren Gjesse | 17fc67d | 2019-12-04 14:50:17 +0100 | [diff] [blame] | 297 | # Add conversion classes. |
| 298 | with zipfile.ZipFile(conversions, 'r') as conversions_zip: |
| 299 | conversions_zip.extractall(tmp_dir) |
| 300 | |
Søren Gjesse | 1a8ccad | 2023-06-06 15:00:46 +0200 | [diff] [blame] | 301 | # Add configuration. |
Søren Gjesse | 6e5e584 | 2019-09-03 08:48:30 +0200 | [diff] [blame] | 302 | configuration_dir = join(tmp_dir, 'META-INF', 'desugar', 'd8') |
| 303 | makedirs(configuration_dir) |
| 304 | copyfile(configuration, join(configuration_dir, 'desugar.json')) |
Søren Gjesse | a70d3bd | 2019-09-24 15:07:00 +0200 | [diff] [blame] | 305 | |
Søren Gjesse | 17fc67d | 2019-12-04 14:50:17 +0100 | [diff] [blame] | 306 | # Add lint configuartion. |
Søren Gjesse | a70d3bd | 2019-09-24 15:07:00 +0200 | [diff] [blame] | 307 | lint_dir = join(configuration_dir, 'lint') |
| 308 | makedirs(lint_dir) |
| 309 | cmd = [ |
| 310 | jdk.GetJavaExecutable(), |
| 311 | '-cp', |
| 312 | utils.R8_JAR, |
Clément Béra | 9ef8f84 | 2023-05-01 09:16:50 +0200 | [diff] [blame] | 313 | 'com.android.tools.r8.ir.desugar.desugaredlibrary.lint.GenerateDesugaredLibraryLintFiles', |
Søren Gjesse | a70d3bd | 2019-09-24 15:07:00 +0200 | [diff] [blame] | 314 | configuration, |
Søren Gjesse | d98f24c | 2020-10-30 12:42:31 +0100 | [diff] [blame] | 315 | implementation, |
Søren Gjesse | a70d3bd | 2019-09-24 15:07:00 +0200 | [diff] [blame] | 316 | lint_dir] |
| 317 | utils.PrintCmd(cmd) |
| 318 | subprocess.check_call(cmd) |
| 319 | |
Søren Gjesse | 1a8ccad | 2023-06-06 15:00:46 +0200 | [diff] [blame] | 320 | # Add LICENSE file. |
| 321 | copyfile(join(utils.REPO_ROOT, 'LICENSE'), join(tmp_dir, 'LICENSE')) |
| 322 | |
Søren Gjesse | 6e5e584 | 2019-09-03 08:48:30 +0200 | [diff] [blame] | 323 | make_archive(destination, 'zip', tmp_dir) |
| 324 | move(destination + '.zip', destination) |
| 325 | |
Søren Gjesse | 7929810 | 2022-08-23 16:25:41 +0200 | [diff] [blame] | 326 | def convert_desugar_configuration( |
| 327 | configuration, conversions, implementation, machine_configuration): |
Søren Gjesse | 2b04769 | 2022-08-19 16:34:38 +0200 | [diff] [blame] | 328 | cmd = [jdk.GetJavaExecutable(), |
| 329 | '-cp', |
| 330 | utils.R8_JAR, |
| 331 | 'com.android.tools.r8.ir.desugar.desugaredlibrary.specificationconversion.DesugaredLibraryConverter', |
| 332 | configuration, |
Søren Gjesse | 7929810 | 2022-08-23 16:25:41 +0200 | [diff] [blame] | 333 | implementation, |
| 334 | conversions, |
Søren Gjesse | 2b04769 | 2022-08-19 16:34:38 +0200 | [diff] [blame] | 335 | utils.get_android_jar(33), |
| 336 | machine_configuration] |
| 337 | subprocess.check_call(cmd) |
| 338 | |
Søren Gjesse | 6e5e584 | 2019-09-03 08:48:30 +0200 | [diff] [blame] | 339 | # Generate the maven zip for the configuration to desugar desugar_jdk_libs. |
Søren Gjesse | e18fa6e | 2022-06-24 15:14:53 +0200 | [diff] [blame] | 340 | def generate_desugar_configuration_maven_zip( |
| 341 | out, configuration, implementation, conversions): |
Rico Wind | 52ece1b | 2020-08-25 14:33:17 +0200 | [diff] [blame] | 342 | with utils.TempDir() as tmp_dir: |
Søren Gjesse | 2b04769 | 2022-08-19 16:34:38 +0200 | [diff] [blame] | 343 | (name, version) = utils.desugar_configuration_name_and_version(configuration, False) |
| 344 | |
| 345 | if (not version.startswith("1.")): |
| 346 | machine_configuration = join(tmp_dir, "machine.json") |
Søren Gjesse | 7929810 | 2022-08-23 16:25:41 +0200 | [diff] [blame] | 347 | convert_desugar_configuration(configuration, conversions, implementation, machine_configuration) |
Søren Gjesse | 2b04769 | 2022-08-19 16:34:38 +0200 | [diff] [blame] | 348 | configuration = machine_configuration |
| 349 | |
Rico Wind | 52ece1b | 2020-08-25 14:33:17 +0200 | [diff] [blame] | 350 | # Generate the pom file. |
| 351 | pom_file = join(tmp_dir, 'desugar_configuration.pom') |
Søren Gjesse | 2b04769 | 2022-08-19 16:34:38 +0200 | [diff] [blame] | 352 | write_pom_file(DESUGAR_CONFIGUATION_POMTEMPLATE, pom_file, version, artifact_id=name) |
Rico Wind | 52ece1b | 2020-08-25 14:33:17 +0200 | [diff] [blame] | 353 | # Generate the jar with the configuration file. |
| 354 | jar_file = join(tmp_dir, 'desugar_configuration.jar') |
| 355 | generate_jar_with_desugar_configuration( |
Søren Gjesse | 705a3b1 | 2022-03-17 11:37:30 +0100 | [diff] [blame] | 356 | configuration, |
| 357 | implementation, |
Søren Gjesse | e18fa6e | 2022-06-24 15:14:53 +0200 | [diff] [blame] | 358 | conversions, |
Rico Wind | 52ece1b | 2020-08-25 14:33:17 +0200 | [diff] [blame] | 359 | jar_file) |
| 360 | # Write the maven zip file. |
Søren Gjesse | 2b04769 | 2022-08-19 16:34:38 +0200 | [diff] [blame] | 361 | generate_maven_zip(name, version, pom_file, jar_file, out) |
Søren Gjesse | 6e5e584 | 2019-09-03 08:48:30 +0200 | [diff] [blame] | 362 | |
Rico Wind | 8fc8bfa | 2019-03-22 09:57:36 +0100 | [diff] [blame] | 363 | def main(argv): |
| 364 | options = parse_options(argv) |
Søren Gjesse | 6e5e584 | 2019-09-03 08:48:30 +0200 | [diff] [blame] | 365 | if options.out == None: |
| 366 | raise Exception( |
| 367 | 'Need to supply output zip with --out.') |
Søren Gjesse | 705a3b1 | 2022-03-17 11:37:30 +0100 | [diff] [blame] | 368 | if options.desugar_configuration or options.desugar_configuration_jdk8: |
| 369 | generate_desugar_configuration_maven_zip( |
Søren Gjesse | 1a8ccad | 2023-06-06 15:00:46 +0200 | [diff] [blame] | 370 | options.out, |
| 371 | utils.DESUGAR_CONFIGURATION, |
| 372 | utils.DESUGAR_IMPLEMENTATION, |
| 373 | utils.LIBRARY_DESUGAR_CONVERSIONS_LEGACY_ZIP) |
Søren Gjesse | 705a3b1 | 2022-03-17 11:37:30 +0100 | [diff] [blame] | 374 | elif options.desugar_configuration_jdk11_legacy: |
| 375 | generate_desugar_configuration_maven_zip( |
Søren Gjesse | 1a8ccad | 2023-06-06 15:00:46 +0200 | [diff] [blame] | 376 | options.out, |
| 377 | utils.DESUGAR_CONFIGURATION_JDK11_LEGACY, |
| 378 | utils.DESUGAR_IMPLEMENTATION_JDK11, |
| 379 | utils.LIBRARY_DESUGAR_CONVERSIONS_LEGACY_ZIP) |
| 380 | elif options.desugar_configuration_jdk11_minimal: |
| 381 | generate_desugar_configuration_maven_zip( |
| 382 | options.out, |
| 383 | utils.DESUGAR_CONFIGURATION_JDK11_MINIMAL, |
| 384 | utils.DESUGAR_IMPLEMENTATION_JDK11, |
| 385 | utils.LIBRARY_DESUGAR_CONVERSIONS_ZIP) |
| 386 | elif options.desugar_configuration_jdk11: |
| 387 | generate_desugar_configuration_maven_zip( |
| 388 | options.out, |
| 389 | utils.DESUGAR_CONFIGURATION_JDK11, |
| 390 | utils.DESUGAR_IMPLEMENTATION_JDK11, |
| 391 | utils.LIBRARY_DESUGAR_CONVERSIONS_ZIP) |
| 392 | elif options.desugar_configuration_jdk11_nio: |
| 393 | generate_desugar_configuration_maven_zip( |
| 394 | options.out, |
| 395 | utils.DESUGAR_CONFIGURATION_JDK11_NIO, |
| 396 | utils.DESUGAR_IMPLEMENTATION_JDK11, |
| 397 | utils.LIBRARY_DESUGAR_CONVERSIONS_ZIP) |
Søren Gjesse | 6e5e584 | 2019-09-03 08:48:30 +0200 | [diff] [blame] | 398 | else: |
Rico Wind | d6323ad | 2023-09-14 09:33:59 +0200 | [diff] [blame] | 399 | generate_r8_maven_zip(options.out) |
Mads Ager | a974561 | 2017-11-02 12:42:15 +0100 | [diff] [blame] | 400 | |
| 401 | if __name__ == "__main__": |
| 402 | exit(main(sys.argv[1:])) |