Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # Copyright (c) 2023, 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.path |
Clément Béra | 148faa4 | 2023-09-14 09:26:45 +0000 | [diff] [blame] | 8 | import shutil |
Clément Béra | 77e6c12 | 2023-09-25 13:55:11 +0200 | [diff] [blame] | 9 | import subprocess |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 10 | import sys |
| 11 | |
| 12 | import utils |
| 13 | |
Søren Gjesse | 4569e47 | 2023-10-25 15:15:17 +0200 | [diff] [blame] | 14 | # The local_maven_repository_generator orders the repositories by name, so |
Søren Gjesse | 10dd427 | 2023-09-20 09:46:52 +0200 | [diff] [blame] | 15 | # prefix with X- to control the order, as many dependencies are present |
Søren Gjesse | 4569e47 | 2023-10-25 15:15:17 +0200 | [diff] [blame] | 16 | # in several repositories. Save A- for additional local repository. |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 17 | REPOSITORIES = [ |
Søren Gjesse | 4569e47 | 2023-10-25 15:15:17 +0200 | [diff] [blame] | 18 | 'B-Google=https://maven.google.com/', |
| 19 | 'C-Maven Central=https://repo1.maven.org/maven2/', |
| 20 | "D-Gradle Plugins=https://plugins.gradle.org/m2/", |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 21 | ] |
| 22 | |
| 23 | ANDRDID_SUPPORT_VERSION = '25.4.0' |
Søren Gjesse | 712400e | 2024-04-29 13:08:11 +0200 | [diff] [blame] | 24 | ASM_VERSION = '9.7' # When updating update tools/asmifier.py and Toolhelper as well. |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 25 | ESPRESSO_VERSION = '3.0.0' |
| 26 | FASTUTIL_VERSION = '7.2.1' |
Clément Béra | 77d6c03 | 2024-06-18 13:10:54 +0200 | [diff] [blame] | 27 | KOTLIN_METADATA_VERSION = '2.0.0' |
Søren Gjesse | a076d56 | 2024-02-09 09:02:30 +0100 | [diff] [blame] | 28 | KOTLIN_VERSION = '1.9.20' |
Søren Gjesse | 80ae2c7 | 2023-10-26 12:04:01 +0200 | [diff] [blame] | 29 | GUAVA_VERSION = '32.1.2-jre' |
Søren Gjesse | 40db6da | 2023-08-11 08:04:19 +0200 | [diff] [blame] | 30 | GSON_VERSION = '2.10.1' |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 31 | JAVASSIST_VERSION = '3.29.2-GA' |
| 32 | JUNIT_VERSION = '4.13-beta-2' |
| 33 | MOCKITO_VERSION = '2.10.0' |
| 34 | SMALI_VERSION = '3.0.3' |
| 35 | ERROR_PRONE_VERSION = '2.18.0' |
| 36 | TESTNG_VERSION = '6.10' |
| 37 | |
Ian Zerny | 4c2fae0 | 2024-06-17 15:20:13 +0200 | [diff] [blame] | 38 | # keepanno & resource shrinker dependencies |
| 39 | PROTOBUF_VERSION = '3.19.3' |
| 40 | |
Rico Wind | be22bff | 2023-07-03 13:40:21 +0200 | [diff] [blame] | 41 | # Resource shrinker dependency versions |
| 42 | AAPT2_PROTO_VERSION = '8.2.0-alpha10-10154469' |
Rico Wind | b3c8c29 | 2024-04-10 14:00:58 +0200 | [diff] [blame] | 43 | STUDIO_SDK_VERSION = '31.5.0-alpha04' |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 44 | |
| 45 | BUILD_DEPENDENCIES = [ |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 46 | 'com.google.code.gson:gson:{version}'.format(version=GSON_VERSION), |
| 47 | 'com.google.guava:guava:{version}'.format(version=GUAVA_VERSION), |
| 48 | 'it.unimi.dsi:fastutil:{version}'.format(version=FASTUTIL_VERSION), |
Søren Gjesse | 80ae2c7 | 2023-10-26 12:04:01 +0200 | [diff] [blame] | 49 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 50 | 'org.ow2.asm:asm:{version}'.format(version=ASM_VERSION), |
| 51 | 'org.ow2.asm:asm-util:{version}'.format(version=ASM_VERSION), |
| 52 | 'org.ow2.asm:asm-commons:{version}'.format(version=ASM_VERSION), |
Søren Gjesse | 80ae2c7 | 2023-10-26 12:04:01 +0200 | [diff] [blame] | 53 | |
| 54 | 'com.google.errorprone:javac:9+181-r4173-1', |
| 55 | |
| 56 | 'com.android.tools.build:aapt2-proto:{version}'.format( |
| 57 | version=AAPT2_PROTO_VERSION), |
| 58 | 'com.android.tools.layoutlib:layoutlib-api:{version}'.format( |
| 59 | version=STUDIO_SDK_VERSION), |
| 60 | 'com.android.tools:common:{version}'.format(version=STUDIO_SDK_VERSION), |
| 61 | 'com.android.tools:sdk-common:{version}'.format(version=STUDIO_SDK_VERSION), |
| 62 | 'com.google.protobuf:protobuf-java:{version}'.format( |
| 63 | version=PROTOBUF_VERSION), |
| 64 | |
| 65 | 'org.jetbrains.kotlin:kotlin-assignment-compiler-plugin-embeddable:{version}'.format( |
| 66 | version=KOTLIN_VERSION), |
| 67 | 'org.jetbrains.kotlin:kotlin-compiler-embeddable:{version}'.format( |
| 68 | version=KOTLIN_VERSION), |
| 69 | 'org.jetbrains.kotlin:kotlin-gradle-plugin-api:{version}'.format( |
| 70 | version=KOTLIN_VERSION), |
| 71 | 'org.jetbrains.kotlin:kotlin-gradle-plugin-idea:{version}'.format( |
| 72 | version=KOTLIN_VERSION), |
| 73 | 'org.jetbrains.kotlin:kotlin-reflect:{version}'.format( |
| 74 | version=KOTLIN_VERSION), |
| 75 | 'org.jetbrains.kotlin:kotlin-sam-with-receiver-compiler-plugin-embeddable:{version}'.format( |
| 76 | version=KOTLIN_VERSION), |
| 77 | 'org.jetbrains.kotlin:kotlin-script-runtime:{version}'.format( |
| 78 | version=KOTLIN_VERSION), |
| 79 | 'org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:{version}'.format( |
| 80 | version=KOTLIN_VERSION), |
| 81 | 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:{version}'.format( |
| 82 | version=KOTLIN_VERSION), |
| 83 | 'org.jetbrains.kotlin:kotlin-tooling-core:{version}'.format( |
| 84 | version=KOTLIN_VERSION), |
Søren Gjesse | c922df4 | 2024-05-17 15:37:59 +0200 | [diff] [blame] | 85 | 'org.jetbrains.kotlin:kotlin-metadata-jvm:{version}'.format( |
Søren Gjesse | 80ae2c7 | 2023-10-26 12:04:01 +0200 | [diff] [blame] | 86 | version=KOTLIN_METADATA_VERSION), |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 87 | ] |
| 88 | |
| 89 | TEST_DEPENDENCIES = [ |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 90 | 'junit:junit:{version}'.format(version=JUNIT_VERSION), |
| 91 | 'com.android.tools.smali:smali:{version}'.format(version=SMALI_VERSION), |
| 92 | 'com.android.tools.smali:smali-util:{version}'.format( |
| 93 | version=SMALI_VERSION), |
| 94 | 'com.google.errorprone:error_prone_core:{version}'.format( |
| 95 | version=ERROR_PRONE_VERSION), |
| 96 | 'org.javassist:javassist:{version}'.format(version=JAVASSIST_VERSION), |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 97 | 'org.mockito:mockito-core:{version}'.format(version=MOCKITO_VERSION), |
| 98 | 'org.testng:testng:{version}'.format(version=TESTNG_VERSION), |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 99 | ] |
| 100 | |
Søren Gjesse | 4569e47 | 2023-10-25 15:15:17 +0200 | [diff] [blame] | 101 | PLUGIN_DEPENDENCIES = [ |
Ian Zerny | 4c2fae0 | 2024-06-17 15:20:13 +0200 | [diff] [blame] | 102 | 'com.google.protobuf:protobuf-gradle-plugin:0.9.4', |
Søren Gjesse | a076d56 | 2024-02-09 09:02:30 +0100 | [diff] [blame] | 103 | 'org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:pom:4.2.1', |
Søren Gjesse | 80ae2c7 | 2023-10-26 12:04:01 +0200 | [diff] [blame] | 104 | 'org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.9.10', |
Søren Gjesse | 20a2ee2 | 2024-02-09 08:24:54 +0100 | [diff] [blame] | 105 | 'net.ltgt.errorprone:net.ltgt.errorprone.gradle.plugin:pom:3.0.1', |
| 106 | 'org.spdx.sbom:org.spdx.sbom.gradle.plugin:pom:0.4.0', |
Søren Gjesse | 4569e47 | 2023-10-25 15:15:17 +0200 | [diff] [blame] | 107 | # See https://github.com/FasterXML/jackson-core/issues/999. |
| 108 | 'ch.randelshofer:fastdoubleparser:0.8.0', |
| 109 | ] |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 110 | |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 111 | def dependencies_tar(dependencies_path): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 112 | return os.path.join(os.path.dirname(dependencies_path), |
| 113 | os.path.basename(dependencies_path) + '.tar.gz') |
| 114 | |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 115 | |
| 116 | def dependencies_tar_sha1(dependencies_path): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 117 | return os.path.join(os.path.dirname(dependencies_path), |
| 118 | os.path.basename(dependencies_path) + '.tar.gz.sha1') |
| 119 | |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 120 | |
| 121 | def remove_local_maven_repository(dependencies_path): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 122 | if os.path.exists(dependencies_path): |
| 123 | shutil.rmtree(dependencies_path) |
| 124 | tar = dependencies_tar(dependencies_path) |
| 125 | if os.path.exists(tar): |
| 126 | os.remove(tar) |
| 127 | sha1 = dependencies_tar_sha1(dependencies_path) |
| 128 | if os.path.exists(sha1): |
| 129 | os.remove(sha1) |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 130 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 131 | |
| 132 | def create_local_maven_repository(args, dependencies_path, repositories, |
| 133 | dependencies): |
| 134 | with utils.ChangedWorkingDirectory(args.studio): |
| 135 | cmd = [ |
| 136 | os.path.join('tools', 'base', 'bazel', 'bazel'), 'run', |
| 137 | '//tools/base/bazel:local_maven_repository_generator_cli', '--', |
| 138 | '--repo-path', dependencies_path, '--fetch' |
| 139 | ] |
| 140 | for repository in repositories: |
| 141 | cmd.extend(['--remote-repo', repository]) |
| 142 | for dependency in dependencies: |
| 143 | cmd.append(dependency) |
| 144 | subprocess.check_call(cmd) |
| 145 | |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 146 | |
| 147 | def parse_options(): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 148 | result = argparse.ArgumentParser( |
| 149 | description='Create local Maven repository woth dependencies') |
| 150 | result.add_argument( |
| 151 | '--studio', |
| 152 | metavar=('<path>'), |
| 153 | required=True, |
| 154 | help='Path to a studio-main checkout (to get the tool ' |
| 155 | '//tools/base/bazel:local_maven_repository_generator_cli)') |
Søren Gjesse | 4569e47 | 2023-10-25 15:15:17 +0200 | [diff] [blame] | 156 | result.add_argument( |
| 157 | '--plugin-deps', |
| 158 | '--plugin_deps', |
| 159 | default=False, |
| 160 | action='store_true', |
| 161 | help='Build repository Gradle plugin dependncies') |
| 162 | result.add_argument( |
| 163 | '--include-maven-local', |
| 164 | '--include_maven_local', |
| 165 | metavar=('<path>'), |
| 166 | default=False, |
| 167 | help='Path to maven local repository to include as dependency source') |
| 168 | result.add_argument( |
| 169 | '--no-upload', |
| 170 | '--no_upload', |
| 171 | default=False, |
| 172 | action='store_true', |
| 173 | help="Don't upload to Google CLoud Storage") |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 174 | return result.parse_args() |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 175 | |
| 176 | |
Søren Gjesse | 4569e47 | 2023-10-25 15:15:17 +0200 | [diff] [blame] | 177 | def set_utime(path): |
| 178 | os.utime(path, (0, 0)) |
| 179 | for root, dirs, files in os.walk(path): |
| 180 | for f in files: |
| 181 | os.utime(os.path.join(root, f), (0, 0)) |
| 182 | for d in dirs: |
| 183 | os.utime(os.path.join(root, d), (0, 0)) |
| 184 | |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 185 | def main(): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 186 | args = parse_options() |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 187 | |
Søren Gjesse | 4569e47 | 2023-10-25 15:15:17 +0200 | [diff] [blame] | 188 | repositories = REPOSITORIES |
| 189 | if args.include_maven_local: |
| 190 | # Add the local repository as the first for it to take precedence. |
| 191 | # Use A- prefix as current local_maven_repository_generator orderes by name. |
| 192 | repositories = ['A-Local=file://%s' % args.include_maven_local] + REPOSITORIES |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 193 | |
Søren Gjesse | 4569e47 | 2023-10-25 15:15:17 +0200 | [diff] [blame] | 194 | dependencies = [] |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 195 | |
Søren Gjesse | 4569e47 | 2023-10-25 15:15:17 +0200 | [diff] [blame] | 196 | if args.plugin_deps: |
| 197 | dependencies_plugin_path = os.path.join(utils.THIRD_PARTY, 'dependencies_plugin') |
| 198 | remove_local_maven_repository(dependencies_plugin_path) |
| 199 | print("Downloading to " + dependencies_plugin_path) |
| 200 | create_local_maven_repository( |
| 201 | args, dependencies_plugin_path, repositories, PLUGIN_DEPENDENCIES) |
| 202 | set_utime(dependencies_plugin_path) |
| 203 | dependencies.append('dependencies_plugin') |
| 204 | else: |
| 205 | dependencies_path = os.path.join(utils.THIRD_PARTY, 'dependencies') |
| 206 | remove_local_maven_repository(dependencies_path) |
| 207 | print("Downloading to " + dependencies_path) |
| 208 | create_local_maven_repository( |
| 209 | args, dependencies_path, repositories, BUILD_DEPENDENCIES + TEST_DEPENDENCIES) |
| 210 | set_utime(dependencies_path) |
| 211 | dependencies.append('dependencies') |
Søren Gjesse | 4569e47 | 2023-10-25 15:15:17 +0200 | [diff] [blame] | 212 | |
| 213 | upload_cmds = [] |
| 214 | for dependency in dependencies: |
| 215 | upload_cmds.append([ |
| 216 | 'upload_to_google_storage.py', |
| 217 | '-a', |
| 218 | '--bucket', |
| 219 | 'r8-deps', |
| 220 | dependency]) |
| 221 | |
| 222 | if not args.no_upload: |
| 223 | print("Uploading to Google Cloud Storage:") |
| 224 | with utils.ChangedWorkingDirectory(utils.THIRD_PARTY): |
| 225 | for cmd in upload_cmds: |
| 226 | subprocess.check_call(cmd) |
| 227 | else: |
| 228 | print("Not uploading to Google Cloud Storage. " |
| 229 | + "Run the following commands in %s to do so manually" % utils.THIRD_PARTY) |
| 230 | for cmd in upload_cmds: |
| 231 | print(" ".join(cmd)) |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 232 | |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 233 | |
| 234 | if __name__ == '__main__': |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 235 | sys.exit(main()) |