From 0dab1e0ff9d3614a8c62320658e8e977c16bb1a5 Mon Sep 17 00:00:00 2001 From: Benjamin Lee Date: Thu, 11 May 2023 13:39:32 -0700 Subject: [PATCH] Use http_jar instead of rules_jvm_external to download bundletool --- MODULE.bazel | 19 +++----------- defs.bzl | 12 --------- examples/basicapp/WORKSPACE | 8 ------ prereqs.bzl | 52 +++++++++++++++++++++---------------- tools/android/BUILD | 2 +- 5 files changed, 33 insertions(+), 60 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 8d9479007..e8decb6db 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -10,7 +10,6 @@ rules_java_toolchains = use_extension("@rules_java//java:extensions.bzl", "toolc use_repo(rules_java_toolchains, "remote_java_tools") bazel_dep(name = "protobuf", version = "3.19.0", repo_name = "com_google_protobuf") -bazel_dep(name = "rules_jvm_external", version = "4.5") bazel_dep(name = "bazel_skylib", version = "1.0.3") bazel_dep(name = "rules_robolectric", version = "4.10") @@ -30,21 +29,9 @@ use_repo( "com_github_google_go_cmp", "org_golang_x_sync", ) -maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven") -maven.install( - name = "rules_android_maven", - artifacts = [ - "com.android.tools.build:bundletool:1.6.1", - ], - repositories = [ - "https://maven.google.com", - "https://repo1.maven.org/maven2", - ], -) -use_repo( - maven, - "rules_android_maven" -) + +rules_android_extensions = use_extension("//:prereqs.bzl", "rules_android_extensions") +use_repo(rules_android_extensions, "bundletool_all", "py_absl") remote_android_extensions = use_extension("@bazel_tools//tools/android:android_extensions.bzl", "remote_android_tools_extensions") use_repo(remote_android_extensions, "android_tools", "android_gmaven_r8") diff --git a/defs.bzl b/defs.bzl index 8abd100b3..ff8bd06fb 100644 --- a/defs.bzl +++ b/defs.bzl @@ -18,23 +18,11 @@ load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository") load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") load("@robolectric//bazel:robolectric.bzl", "robolectric_repositories") -load("@rules_jvm_external//:defs.bzl", "maven_install") def rules_android_workspace(): """ Sets up workspace dependencies for rules_android.""" protobuf_deps() - maven_install( - name = "rules_android_maven", - artifacts = [ - "com.android.tools.build:bundletool:1.6.1", - ], - repositories = [ - "https://maven.google.com", - "https://repo1.maven.org/maven2", - ], - ) - go_rules_dependencies() go_register_toolchains(version = "1.18.3") diff --git a/examples/basicapp/WORKSPACE b/examples/basicapp/WORKSPACE index b7aa64a43..361889219 100644 --- a/examples/basicapp/WORKSPACE +++ b/examples/basicapp/WORKSPACE @@ -9,14 +9,6 @@ android_ndk_repository( name = "androidndk", ) -maybe( - http_archive, - name = "rules_jvm_external", - strip_prefix = "rules_jvm_external-fa73b1a8e4846cee88240d0019b8f80d39feb1c3", - sha256 = "7e13e48b50f9505e8a99cc5a16c557cbe826e9b68d733050cd1e318d69f94bb5", - url = "https://github.com/bazelbuild/rules_jvm_external/archive/fa73b1a8e4846cee88240d0019b8f80d39feb1c3.zip", -) - maybe( http_archive, name = "bazel_skylib", diff --git a/prereqs.bzl b/prereqs.bzl index d71d03d5b..d27b14db5 100644 --- a/prereqs.bzl +++ b/prereqs.bzl @@ -14,20 +14,31 @@ """Sets up prerequisites for rules_android.""" -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_jar") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") +def _rules_android_bzlmod_prereqs(): + """Downloads prerequisite repositories specific to Bzlmod that can't otherwise be handled in the MODULE.bazel""" + maybe( + http_jar, + name = "bundletool_all", + sha256 = "2f78f9c8d059db1c7ea4ac6ffb2527466af03838d150b70f4b77fe7deefca011", + urls = ["https://github.com/google/bundletool/releases/download/1.14.1/bundletool-all-1.14.1.jar"], + ) -def rules_android_prereqs(): - """Downloads prerequisite repositories for rules_android.""" maybe( http_archive, - name = "rules_jvm_external", - strip_prefix = "rules_jvm_external-fa73b1a8e4846cee88240d0019b8f80d39feb1c3", - sha256 = "7e13e48b50f9505e8a99cc5a16c557cbe826e9b68d733050cd1e318d69f94bb5", - url = "https://github.com/bazelbuild/rules_jvm_external/archive/fa73b1a8e4846cee88240d0019b8f80d39feb1c3.zip", + name = "py_absl", + sha256 = "0fb3a4916a157eb48124ef309231cecdfdd96ff54adf1660b39c0d4a9790a2c0", + urls = ["https://github.com/abseil/abseil-py/archive/refs/tags/v1.4.0.tar.gz"], + strip_prefix = "abseil-py-1.4.0", ) +def rules_android_prereqs(): + """Downloads prerequisite repositories for rules_android.""" + + _rules_android_bzlmod_prereqs() + maybe( http_archive, name = "com_google_protobuf", @@ -41,8 +52,8 @@ def rules_android_prereqs(): name = "remote_java_tools_for_rules_android", sha256 = "8fb4d3138bd92a9d3324dae29c9f70d91ca2db18cd0bf1997446eed4657d19b3", urls = [ - "https://mirror.bazel.build/bazel_java_tools/releases/java/v11.8/java_tools-v11.8.zip", - "https://github.com/bazelbuild/java_tools/releases/download/java_v11.8/java_tools-v11.8.zip", + "https://mirror.bazel.build/bazel_java_tools/releases/java/v11.8/java_tools-v11.8.zip", + "https://github.com/bazelbuild/java_tools/releases/download/java_v11.8/java_tools-v11.8.zip", ], ) @@ -84,23 +95,18 @@ def rules_android_prereqs(): sha256 = "7e007fcfdca7b7228cb4de72707e8b317026ea95000f963e91d5ae365be52d0d", ) - maybe( - http_archive, - name = "rules_license", - urls = [ - "https://github.com/bazelbuild/rules_license/releases/download/0.0.4/rules_license-0.0.4.tar.gz", - "https://mirror.bazel.build/github.com/bazelbuild/rules_license/releases/download/0.0.4/rules_license-0.0.4.tar.gz", - ], - sha256 = "6157e1e68378532d0241ecd15d3c45f6e5cfd98fc10846045509fb2a7cc9e381", - ) - maybe( http_archive, - name = "py_absl", - sha256 = "0fb3a4916a157eb48124ef309231cecdfdd96ff54adf1660b39c0d4a9790a2c0", + name = "rules_license", urls = [ - "https://github.com/abseil/abseil-py/archive/refs/tags/v1.4.0.tar.gz", + "https://github.com/bazelbuild/rules_license/releases/download/0.0.4/rules_license-0.0.4.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/rules_license/releases/download/0.0.4/rules_license-0.0.4.tar.gz", ], - strip_prefix = "abseil-py-1.4.0", + sha256 = "6157e1e68378532d0241ecd15d3c45f6e5cfd98fc10846045509fb2a7cc9e381", ) +def _rules_android_extensions_impl(_): + """Downloads prerequisite repositories for rules_android specifically needed for Bzlmod.""" + _rules_android_bzlmod_prereqs() + +rules_android_extensions = module_extension(implementation = _rules_android_extensions_impl) diff --git a/tools/android/BUILD b/tools/android/BUILD index 7a85b590e..33495daa1 100644 --- a/tools/android/BUILD +++ b/tools/android/BUILD @@ -28,7 +28,7 @@ java_binary( name = "bundletool", main_class = "com.android.tools.build.bundletool.BundleToolMain", visibility = ["//visibility:public"], - runtime_deps = ["@rules_android_maven//:com_android_tools_build_bundletool"], + runtime_deps = ["@bundletool_all//jar"], ) java_plugin(