Skip to content

Commit cd1ae23

Browse files
committed
Support warn/default strict deps in java_common.compile.
Fixes #3626. PiperOrigin-RevId: 167687039
1 parent 05a704f commit cd1ae23

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/main/java/com/google/devtools/build/lib/rules/java/JavaSkylarkCommon.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,10 @@ private static NestedSet<Artifact> asArtifactNestedSet(Object o) throws EvalExce
264264
positional = false,
265265
named = true,
266266
type = String.class,
267-
doc = "A string that specifies how to handle strict deps. Possible values: 'OFF' (silently"
268-
+ " allowing referencing transitive dependencies) and 'ERROR' (failing to build when"
269-
+ " transitive dependencies are used directly). By default 'OFF'."
267+
doc = "A string that specifies how to handle strict deps. Possible values: 'OFF', 'ERROR',"
268+
+ "'WARN' and 'DEFAULT'. For more details see "
269+
+ "https://docs.bazel.build/versions/master/bazel-user-manual.html#flag--strict_java_deps"
270+
+ ". By default 'ERROR'."
270271
),
271272
@Param(
272273
name = "java_toolchain",
@@ -332,7 +333,7 @@ public JavaInfo createJavaCompileAction(
332333
JavaInfo.fetchProvidersFromList(exports, JavaCompilationArgsProvider.class);
333334
helper.addAllDeps(depsCompilationArgsProviders);
334335
helper.addAllExports(exportsCompilationArgsProviders);
335-
helper.setCompilationStrictDepsMode(getStrictDepsMode(strictDepsMode));
336+
helper.setCompilationStrictDepsMode(getStrictDepsMode(strictDepsMode.toUpperCase()));
336337
MiddlemanProvider hostJavabaseProvider = hostJavabase.getProvider(MiddlemanProvider.class);
337338

338339
helper.addAllPlugins(
@@ -464,7 +465,10 @@ private static StrictDepsMode getStrictDepsMode(String strictDepsMode) {
464465
case "OFF":
465466
return StrictDepsMode.OFF;
466467
case "ERROR":
468+
case "DEFAULT":
467469
return StrictDepsMode.ERROR;
470+
case "WARN":
471+
return StrictDepsMode.WARN;
468472
default:
469473
throw new IllegalArgumentException(
470474
"StrictDepsMode "

src/test/shell/bazel/bazel_java_test.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,27 @@ EOF
10681068
expect_log "Message from C"
10691069
}
10701070

1071+
function test_java_sandwich_default_strict_deps() {
1072+
mkdir -p java/com/google/sandwich
1073+
touch java/com/google/sandwich/{BUILD,A.java,java_custom_library.bzl}
1074+
write_java_custom_rule
1075+
1076+
cat > java/com/google/sandwich/BUILD << EOF
1077+
load(':java_custom_library.bzl', 'java_custom_library')
1078+
1079+
java_custom_library(
1080+
name = "custom",
1081+
srcs = ["A.java"]
1082+
)
1083+
EOF
1084+
1085+
sed -i -- 's/ERROR/DEFAULT/g' 'java/com/google/sandwich/java_custom_library.bzl'
1086+
bazel build java/com/google/sandwich:custom > $TEST_log || fail "Java sandwich build failed"
1087+
1088+
sed -i -- 's/DEFAULT/WARN/g' 'java/com/google/sandwich/java_custom_library.bzl'
1089+
bazel build java/com/google/sandwich:custom > $TEST_log || fail "Java sandwich build failed"
1090+
}
1091+
10711092
function test_basic_java_sandwich_with_transitive_deps_and_java_library_should_fail() {
10721093
mkdir -p java/com/google/sandwich
10731094
touch java/com/google/sandwich/{BUILD,{A,B,C,Main}.java,java_custom_library.bzl}

0 commit comments

Comments
 (0)