Migrate the `JavaImportConfiguredTargetTest.testPermitsEmptyJars` test to Starlark
The test is removed from Bazel and added to rules_java
(ignore-relnotes)
PiperOrigin-RevId: 756255370
Change-Id: Ia7dd37d7491a3975903f2a2ccbbcb31e81dd2ed4
diff --git a/MODULE.bazel b/MODULE.bazel
index 400a4c2..4b70044 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -8,6 +8,13 @@
bazel_dep(name = "platforms", version = "0.0.11")
bazel_dep(name = "rules_cc", version = "0.0.15")
bazel_dep(name = "bazel_features", version = "1.28.0")
+archive_override(
+ module_name = "bazel_features",
+ integrity = "sha256-SOPLvKDy+RN7GHKN8eFjQ+58Wx4Isj+vcXoUluBqxLo=",
+ strip_prefix = "bazel_features-59915eb2ca215c7b2266c83c49bb7522a5b6737f",
+ urls = ["https://github.com/bazel-contrib/bazel_features/archive/59915eb2ca215c7b2266c83c49bb7522a5b6737f.zip"],
+)
+
bazel_dep(name = "bazel_skylib", version = "1.6.1")
bazel_dep(name = "protobuf", version = "27.0", repo_name = "com_google_protobuf")
bazel_dep(name = "zlib", version = "1.3.1.bcr.5")
diff --git a/WORKSPACE b/WORKSPACE
index 3cb2379..6b8beb6 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -66,9 +66,9 @@
http_archive(
name = "bazel_features",
- sha256 = "2f057dd02098a106095ea291b4344257398a059eadb2c74cc470de0f9664dccd",
- strip_prefix = "bazel_features-1.28.0",
- url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.28.0/bazel_features-v1.28.0.tar.gz",
+ sha256 = "48e3cbbca0f2f9137b18728df1e16343ee7c5b1e08b23faf717a1496e06ac4ba",
+ strip_prefix = "bazel_features-59915eb2ca215c7b2266c83c49bb7522a5b6737f",
+ url = "https://github.com/bazel-contrib/bazel_features/archive/59915eb2ca215c7b2266c83c49bb7522a5b6737f.zip",
)
load("@bazel_features//:deps.bzl", "bazel_features_deps")
diff --git a/test/java/common/rules/java_import_tests.bzl b/test/java/common/rules/java_import_tests.bzl
index 41c1fe0..92dce45 100644
--- a/test/java/common/rules/java_import_tests.bzl
+++ b/test/java/common/rules/java_import_tests.bzl
@@ -421,6 +421,57 @@
"{package}/somelib-src.jar",
])
+def _test_permits_empty_jars_with_flag(name):
+ if not bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags:
+ # exit early because this test case would be a loading phase error otherwise
+ always_passes(name)
+ return
+
+ util.helper_target(
+ java_import,
+ name = name + "/rule",
+ jars = [],
+ )
+
+ analysis_test(
+ name = name,
+ impl = _test_permits_empty_jars_with_flag_impl,
+ target = name + "/rule",
+ config_settings = {
+ "//command_line_option:incompatible_disallow_java_import_empty_jars": False,
+ },
+ )
+
+def _test_permits_empty_jars_with_flag_impl(_env, _target):
+ pass
+
+def _test_disallows_empty_jars(name):
+ if not bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags:
+ # exit early because this test case would be a loading phase error otherwise
+ always_passes(name)
+ return
+
+ util.helper_target(
+ java_import,
+ name = name + "/rule",
+ jars = [],
+ )
+
+ analysis_test(
+ name = name,
+ impl = _test_disallows_empty_jars_impl,
+ target = name + "/rule",
+ config_settings = {
+ "//command_line_option:incompatible_disallow_java_import_empty_jars": True,
+ },
+ expect_failure = True,
+ )
+
+def _test_disallows_empty_jars_impl(env, target):
+ env.expect.that_target(target).failures().contains_predicate(
+ matching.str_matches("empty java_import.jars is no longer supported"),
+ )
+
def java_import_tests(name):
test_suite(
name = name,
@@ -437,5 +488,7 @@
_test_transitive_dependencies,
_test_exposes_java_provider,
_test_jars_allowed_in_srcjar,
+ _test_permits_empty_jars_with_flag,
+ _test_disallows_empty_jars,
],
)