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 |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 8 | import shutil |
Clément Béra | ff8a1cb | 2023-09-13 14:38:04 +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 | |
| 14 | REPOSITORIES = [ |
| 15 | 'Maven Central=https://repo1.maven.org/maven2/', |
| 16 | 'Google=https://maven.google.com/', |
| 17 | "Gradle Plugins=https://plugins.gradle.org/m2/", |
| 18 | ] |
| 19 | |
| 20 | ANDRDID_SUPPORT_VERSION = '25.4.0' |
| 21 | ASM_VERSION = '9.5' |
| 22 | ESPRESSO_VERSION = '3.0.0' |
| 23 | FASTUTIL_VERSION = '7.2.1' |
Clément Béra | ff8a1cb | 2023-09-13 14:38:04 +0200 | [diff] [blame] | 24 | KOTLIN_METADATA_VERSION = '0.7.0' |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 25 | KOTLIN_VERSION = '1.8.0' |
| 26 | GUAVA_VERSION = '31.1-jre' |
Søren Gjesse | bd1698c | 2023-08-14 09:09:27 +0200 | [diff] [blame] | 27 | GUAVA_VERSION_NEW = '32.1.2-jre' |
Søren Gjesse | 40db6da | 2023-08-11 08:04:19 +0200 | [diff] [blame] | 28 | GSON_VERSION = '2.10.1' |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 29 | JAVASSIST_VERSION = '3.29.2-GA' |
| 30 | JUNIT_VERSION = '4.13-beta-2' |
| 31 | MOCKITO_VERSION = '2.10.0' |
| 32 | SMALI_VERSION = '3.0.3' |
| 33 | ERROR_PRONE_VERSION = '2.18.0' |
| 34 | TESTNG_VERSION = '6.10' |
| 35 | |
Rico Wind | be22bff | 2023-07-03 13:40:21 +0200 | [diff] [blame] | 36 | # Resource shrinker dependency versions |
| 37 | AAPT2_PROTO_VERSION = '8.2.0-alpha10-10154469' |
| 38 | PROTOBUF_VERSION = '3.19.3' |
| 39 | STUDIO_SDK_VERSION = '31.2.0-alpha10' |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 40 | |
| 41 | BUILD_DEPENDENCIES = [ |
| 42 | 'com.google.code.gson:gson:{version}'.format(version = GSON_VERSION), |
| 43 | 'com.google.guava:guava:{version}'.format(version = GUAVA_VERSION), |
| 44 | 'it.unimi.dsi:fastutil:{version}'.format(version = FASTUTIL_VERSION), |
| 45 | 'org.jetbrains.kotlinx:kotlinx-metadata-jvm:{version}'.format(version = KOTLIN_METADATA_VERSION), |
| 46 | 'org.ow2.asm:asm:{version}'.format(version = ASM_VERSION), |
| 47 | 'org.ow2.asm:asm-util:{version}'.format(version = ASM_VERSION), |
| 48 | 'org.ow2.asm:asm-commons:{version}'.format(version = ASM_VERSION), |
| 49 | ] |
| 50 | |
| 51 | TEST_DEPENDENCIES = [ |
| 52 | 'junit:junit:{version}'.format(version = JUNIT_VERSION), |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 53 | 'com.android.tools.smali:smali:{version}'.format(version = SMALI_VERSION), |
Morten Krogh-Jespersen | cef9a9d | 2023-09-10 23:06:41 +0200 | [diff] [blame] | 54 | 'com.android.tools.smali:smali-util:{version}'.format(version = SMALI_VERSION), |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 55 | 'com.google.errorprone:error_prone_core:{version}'.format(version = ERROR_PRONE_VERSION), |
| 56 | 'org.javassist:javassist:{version}'.format(version = JAVASSIST_VERSION), |
| 57 | 'org.jetbrains.kotlin:kotlin-stdlib:{version}'.format(version = KOTLIN_VERSION), |
| 58 | 'org.jetbrains.kotlin:kotlin-reflect:{version}'.format(version = KOTLIN_VERSION), |
| 59 | 'org.mockito:mockito-core:{version}'.format(version = MOCKITO_VERSION), |
| 60 | 'org.testng:testng:{version}'.format(version = TESTNG_VERSION), |
| 61 | ] |
| 62 | |
| 63 | NEW_DEPENDENCIES = [ |
Søren Gjesse | bd1698c | 2023-08-14 09:09:27 +0200 | [diff] [blame] | 64 | 'com.google.guava:guava:{version}'.format(version = GUAVA_VERSION_NEW), |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 65 | 'org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:4.0.6', |
| 66 | 'org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.8.10', |
| 67 | 'org.jetbrains.kotlin:kotlin-gradle-plugin-idea:1.8.10', |
| 68 | 'org.jetbrains.kotlin:kotlin-reflect:1.6.10', |
| 69 | 'org.jetbrains.kotlin:kotlin-reflect:1.8.10', |
| 70 | 'org.jetbrains.kotlin:kotlin-script-runtime:1.8.10', |
| 71 | 'org.jetbrains.kotlin:kotlin-tooling-core:1.8.10', |
Rico Wind | be22bff | 2023-07-03 13:40:21 +0200 | [diff] [blame] | 72 | 'net.ltgt.errorprone:net.ltgt.errorprone.gradle.plugin:3.0.1', |
Rico Wind | 9b0a342 | 2023-08-31 15:28:03 +0200 | [diff] [blame] | 73 | 'com.google.errorprone:javac:9+181-r4173-1', |
Rico Wind | 51853ee | 2023-09-06 11:26:42 +0200 | [diff] [blame] | 74 | # Gradle 8.3 |
| 75 | 'org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:4.1.0', |
| 76 | 'org.jetbrains.kotlin:kotlin-assignment-compiler-plugin-embeddable:1.9.0', |
| 77 | 'org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.9.0', |
| 78 | 'org.jetbrains.kotlin:kotlin-reflect:1.9.0', |
| 79 | 'org.jetbrains.kotlin:kotlin-script-runtime:1.9.0', |
| 80 | 'org.jetbrains.kotlin:kotlin-sam-with-receiver-compiler-plugin-embeddable:1.9.0', |
Rico Wind | be22bff | 2023-07-03 13:40:21 +0200 | [diff] [blame] | 81 | # Resource shrinker |
| 82 | 'com.android.tools.build:aapt2-proto:{version}'.format(version = AAPT2_PROTO_VERSION), |
| 83 | 'com.android.tools.layoutlib:layoutlib-api:{version}'.format(version = STUDIO_SDK_VERSION), |
| 84 | 'com.android.tools:common:{version}'.format(version = STUDIO_SDK_VERSION), |
| 85 | 'com.android.tools:sdk-common:{version}'.format(version = STUDIO_SDK_VERSION), |
| 86 | 'com.google.protobuf:protobuf-java:{version}'.format(version = PROTOBUF_VERSION), |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 87 | ] |
| 88 | |
| 89 | def dependencies_tar(dependencies_path): |
| 90 | return os.path.join( |
| 91 | os.path.dirname(dependencies_path), |
| 92 | os.path.basename(dependencies_path) + '.tar.gz') |
| 93 | |
| 94 | def dependencies_tar_sha1(dependencies_path): |
| 95 | return os.path.join( |
| 96 | os.path.dirname(dependencies_path), |
| 97 | os.path.basename(dependencies_path) + '.tar.gz.sha1') |
| 98 | |
| 99 | def remove_local_maven_repository(dependencies_path): |
| 100 | if os.path.exists(dependencies_path): |
| 101 | shutil.rmtree(dependencies_path) |
| 102 | tar = dependencies_tar(dependencies_path) |
| 103 | if os.path.exists(tar): |
| 104 | os.remove(tar) |
| 105 | sha1 = dependencies_tar_sha1(dependencies_path) |
| 106 | if os.path.exists(sha1): |
| 107 | os.remove(sha1) |
| 108 | |
| 109 | def create_local_maven_repository(args, dependencies_path, repositories, dependencies): |
| 110 | with utils.ChangedWorkingDirectory(args.studio): |
| 111 | cmd = [ |
| 112 | os.path.join('tools', 'base', 'bazel', 'bazel'), |
| 113 | 'run', |
| 114 | '//tools/base/bazel:local_maven_repository_generator_cli', |
| 115 | '--', |
| 116 | '--repo-path', |
| 117 | dependencies_path, |
| 118 | '--fetch'] |
| 119 | for repository in repositories: |
| 120 | cmd.extend(['--remote-repo', repository]) |
| 121 | for dependency in dependencies: |
| 122 | cmd.append(dependency) |
| 123 | subprocess.check_call(cmd) |
| 124 | |
| 125 | def parse_options(): |
| 126 | result = argparse.ArgumentParser( |
| 127 | description='Create local Maven repository woth dependencies') |
| 128 | result.add_argument('--studio', |
| 129 | metavar=('<path>'), |
| 130 | required=True, |
| 131 | help='Path to a studio-main checkout (to get the tool ' |
| 132 | '//tools/base/bazel:local_maven_repository_generator_cli)') |
| 133 | return result.parse_args() |
| 134 | |
| 135 | |
| 136 | def main(): |
| 137 | args = parse_options() |
| 138 | |
| 139 | dependencies_path = os.path.join(utils.THIRD_PARTY, 'dependencies') |
| 140 | print("Downloading to " + dependencies_path) |
| 141 | remove_local_maven_repository(dependencies_path) |
| 142 | create_local_maven_repository( |
| 143 | args, dependencies_path, REPOSITORIES, BUILD_DEPENDENCIES + TEST_DEPENDENCIES) |
| 144 | |
| 145 | dependencies_new_path = os.path.join(utils.THIRD_PARTY, 'dependencies_new') |
| 146 | print("Downloading to " + dependencies_new_path) |
| 147 | remove_local_maven_repository(dependencies_new_path) |
| 148 | create_local_maven_repository( |
| 149 | args, dependencies_new_path, REPOSITORIES, NEW_DEPENDENCIES) |
| 150 | |
Søren Gjesse | d31e7f9 | 2023-08-14 09:07:38 +0200 | [diff] [blame] | 151 | print("Uploading to Google Cloud Storage:") |
| 152 | with utils.ChangedWorkingDirectory(utils.THIRD_PARTY): |
| 153 | for dependency in ['dependencies', 'dependencies_new']: |
| 154 | cmd = [ |
| 155 | 'upload_to_google_storage.py', |
| 156 | '-a', |
| 157 | '--bucket', |
| 158 | 'r8-deps', |
| 159 | dependency] |
| 160 | subprocess.check_call(cmd) |
Søren Gjesse | 44faa87 | 2023-05-23 12:21:22 +0200 | [diff] [blame] | 161 | |
| 162 | if __name__ == '__main__': |
| 163 | sys.exit(main()) |