blob: 4cace6a9ee5f019a2c3807f9481c7d09805e0f2d [file] [log] [blame]
Søren Gjessee6893fd2022-04-26 13:34:51 +02001#!/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
6import argparse
7import os
8from os.path import join
9import shutil
10import subprocess
11import sys
12
13import utils
14import create_maven_release
15
16def 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
26def 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
36def jar_file(unzip_dir, artifact, version):
37 return jar_or_pom_file(unzip_dir, artifact, version, 'jar')
38
39def pom_file(unzip_dir, artifact, version):
40 return jar_or_pom_file(unzip_dir, artifact, version, 'pom')
41
42def 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
131if __name__ == '__main__':
132 sys.exit(main())