Søren Gjesse | e6893fd | 2022-04-26 13:34:51 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # Copyright (c) 2022, the R8 project authors. Please see the AUTHORS file |
| 3 | # for details. All rights reserved. Use of this source code is governed by a |
| 4 | # BSD-style license that can be found in the LICENSE file. |
| 5 | |
| 6 | import argparse |
| 7 | import os |
| 8 | from os.path import join |
| 9 | import shutil |
| 10 | import subprocess |
| 11 | import sys |
| 12 | |
| 13 | import utils |
| 14 | import create_maven_release |
| 15 | |
| 16 | def parse_options(): |
| 17 | result = argparse.ArgumentParser( |
| 18 | description='Local desugared library repository for JDK 11 legacy configuration') |
| 19 | result.add_argument('--repo-root', '--repo_root', |
| 20 | default='/tmp/repo', |
| 21 | metavar=('<path>'), |
| 22 | help='Location for Maven repository.') |
| 23 | args = result.parse_args() |
| 24 | return args |
| 25 | |
| 26 | def jar_or_pom_file(unzip_dir, artifact, version, extension): |
| 27 | return join( |
| 28 | unzip_dir, |
| 29 | 'com', |
| 30 | 'android', |
| 31 | 'tools', |
| 32 | artifact, |
| 33 | version, |
| 34 | artifact + '-' + version + '.' + extension) |
| 35 | |
| 36 | def jar_file(unzip_dir, artifact, version): |
| 37 | return jar_or_pom_file(unzip_dir, artifact, version, 'jar') |
| 38 | |
| 39 | def pom_file(unzip_dir, artifact, version): |
| 40 | return jar_or_pom_file(unzip_dir, artifact, version, 'pom') |
| 41 | |
| 42 | def main(): |
| 43 | args = parse_options() |
| 44 | shutil.rmtree(args.repo_root, ignore_errors=True) |
| 45 | utils.makedirs_if_needed(args.repo_root) |
| 46 | with utils.TempDir() as tmp_dir: |
| 47 | version = utils.desugar_configuration_version(utils.DESUGAR_CONFIGURATION_JDK11_LEGACY) |
| 48 | |
| 49 | # Checkout desugar_jdk_libs from GitHub |
| 50 | checkout_dir = join(tmp_dir, 'desugar_jdk_libs') |
| 51 | utils.RunCmd(['git', 'clone', 'https://github.com/google/desugar_jdk_libs.git', checkout_dir]) |
| 52 | with utils.ChangedWorkingDirectory(checkout_dir): |
| 53 | with open('VERSION_JDK11.txt') as version_file: |
| 54 | version_file_lines = version_file.readlines() |
| 55 | for line in version_file_lines: |
| 56 | if not line.startswith('#'): |
| 57 | desugar_jdk_libs_version = line.strip() |
| 58 | if (version != desugar_jdk_libs_version): |
| 59 | raise Exception( |
| 60 | "Version mismatch. Configuration has version '" |
| 61 | + version |
| 62 | + "', and desugar_jdk_libs has version '" |
| 63 | + desugar_jdk_libs_version |
| 64 | + "'") |
| 65 | |
| 66 | # Build desugared library configuration. |
| 67 | print("Building desugared library configuration " + version) |
| 68 | maven_zip = join(tmp_dir, 'desugar_configuration.zip') |
| 69 | create_maven_release.generate_desugar_configuration_maven_zip( |
| 70 | maven_zip, |
| 71 | utils.DESUGAR_CONFIGURATION_JDK11_LEGACY, |
| 72 | utils.DESUGAR_IMPLEMENTATION_JDK11) |
| 73 | unzip_dir = join(tmp_dir, 'desugar_jdk_libs_configuration_unzipped') |
| 74 | cmd = ['unzip', '-q', maven_zip, '-d', unzip_dir] |
| 75 | utils.RunCmd(cmd) |
| 76 | cmd = [ |
| 77 | 'mvn', |
| 78 | 'deploy:deploy-file', |
| 79 | '-Durl=file:' + args.repo_root, |
| 80 | '-DrepositoryId=someName', |
| 81 | '-Dfile=' + jar_file(unzip_dir, 'desugar_jdk_libs_configuration', version), |
| 82 | '-DpomFile=' + pom_file(unzip_dir, 'desugar_jdk_libs_configuration', version)] |
| 83 | utils.RunCmd(cmd) |
| 84 | |
| 85 | # Build desugared library. |
| 86 | print("Building desugared library " + version) |
| 87 | with utils.ChangedWorkingDirectory(checkout_dir): |
| 88 | utils.RunCmd([ |
| 89 | 'bazel', |
| 90 | '--bazelrc=/dev/null', |
| 91 | 'build', |
| 92 | '--spawn_strategy=local', |
| 93 | '--verbose_failures', |
| 94 | ':maven_release_jdk11']) |
| 95 | unzip_dir = join(tmp_dir, 'desugar_jdk_libs_unzipped') |
| 96 | cmd = [ |
| 97 | 'unzip', |
| 98 | '-q', |
| 99 | join(checkout_dir, 'bazel-bin', 'desugar_jdk_libs_jdk11.zip'), |
| 100 | '-d', |
| 101 | unzip_dir] |
| 102 | utils.RunCmd(cmd) |
| 103 | cmd = [ |
| 104 | 'mvn', |
| 105 | 'deploy:deploy-file', |
| 106 | '-Durl=file:' + args.repo_root, |
| 107 | '-DrepositoryId=someName', |
| 108 | '-Dfile=' + jar_file(unzip_dir, 'desugar_jdk_libs', version), |
| 109 | '-DpomFile=' + pom_file(unzip_dir, 'desugar_jdk_libs', version)] |
| 110 | utils.RunCmd(cmd) |
| 111 | |
| 112 | print() |
| 113 | print("Artifacts:") |
| 114 | print(" com.android.tools:desugar_jdk_libs_configuration:" + version) |
| 115 | print(" com.android.tools:desugar_jdk_libs:" + version) |
| 116 | print() |
| 117 | print("deployed to Maven repository at " + args.repo_root + ".") |
| 118 | print() |
| 119 | print("Add") |
| 120 | print() |
| 121 | print(" maven {") |
| 122 | print(" url uri('file://" + args.repo_root + "')") |
| 123 | print(" }") |
| 124 | print() |
| 125 | print("to dependencyResolutionManagement.repositories in settings.gradle.") |
| 126 | print() |
| 127 | print("Remember to run gradle with --refresh-dependencies " |
| 128 | + "(./gradlew --refresh-dependencies ...) " |
| 129 | + "to ensure the cache is not used when the same version is published.") |
| 130 | |
| 131 | if __name__ == '__main__': |
| 132 | sys.exit(main()) |