From 022f7a5bb8573ab8858a0662fca14920a4c4d0fe Mon Sep 17 00:00:00 2001 From: Ted Xie Date: Wed, 4 Dec 2024 17:25:14 -0500 Subject: [PATCH 1/2] Make robolectric-bazel work for bazel 6 and 7 * Replace http_jar() with http_file() * Create java_library wrappers for each http_file in bazel/BUILD * Verified for Bazel 6.5.0 and 7.4.1, bzlmod on/off. --- bazel/BUILD | 15 ++++++++++++++- bazel/robolectric.bzl | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/bazel/BUILD b/bazel/BUILD index df58ce7..bcaecbd 100644 --- a/bazel/BUILD +++ b/bazel/BUILD @@ -1,3 +1,4 @@ +load("@rules_java//java:java_import.bzl", "java_import") load("@rules_java//java:java_library.bzl", "java_library") load("@rules_python//python:py_binary.bzl", "py_binary") load(":robolectric.bzl", "DEFAULT_AVAILABLE_VERSIONS") @@ -8,7 +9,19 @@ package( ], ) -_ANDROID_ALL_JARS = ["@{}//jar".format(v.name) for v in DEFAULT_AVAILABLE_VERSIONS] +[ + java_import( + name = "import_" + v.name, + jars = ["@{}//file".format(v.name)], + visibility = [ + ":__pkg__", + "//tests:__subpackages__", + ], + ) + for v in DEFAULT_AVAILABLE_VERSIONS +] + +_ANDROID_ALL_JARS = ["import_{}".format(v.name) for v in DEFAULT_AVAILABLE_VERSIONS] java_library( name = "android-all", diff --git a/bazel/robolectric.bzl b/bazel/robolectric.bzl index 74f1286..ceddd5c 100644 --- a/bazel/robolectric.bzl +++ b/bazel/robolectric.bzl @@ -1,7 +1,7 @@ """Robolectric repositories """ -load("@rules_java//java:http_jar.bzl", "http_jar") +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file") def robolectric_version(version, sha256, url = None): """Define a struct representation of an instrumented Robolectric jar. @@ -92,4 +92,4 @@ def robolectric_repositories(): """Creates http_jar repositories for the given versions of Robolectric. """ for v in DEFAULT_AVAILABLE_VERSIONS: - http_jar(name = v.name, url = v.url, downloaded_file_name = "android-all-instrumented-%s.jar" % (v.version), sha256 = v.sha256) + http_file(name = v.name, url = v.url, downloaded_file_path = "android-all-instrumented-%s.jar" % (v.version), sha256 = v.sha256) From 737edaa32fbdff29eae031c682a38741d22d05e7 Mon Sep 17 00:00:00 2001 From: Ted Xie Date: Wed, 4 Dec 2024 17:29:31 -0500 Subject: [PATCH 2/2] Adjust CI bazel versions --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 941fb35..5ac7b09 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -40,7 +40,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-2022, macos-13] - bazel: [7.4.1, 8.0.0rc4] + bazel: [6.5.0, 7.4.1, 8.0.0rc7] bzlmod: [ true, false ] runs-on: ${{ matrix.os }} steps: