Skip to content

Commit 7153103

Browse files
JonathanPerry651Gemini CLI
authored andcommitted
Fix unused_deps_mode attribute crash on older Bazel versions
1 parent 0879997 commit 7153103

5 files changed

Lines changed: 17 additions & 1 deletion

File tree

java/common/rules/impl/basic_java_library_impl.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def basic_java_library(
110110
add_opens: (list[str]) Allow this library to reflectively access the given <module>/<package>.
111111
bootclasspath: (Target) The JDK APIs to compile this library against.
112112
javabuilder_jvm_flags: (list[str]) Additional JVM flags to pass to JavaBuilder.
113+
unused_deps_mode: (str) Unused dependency checking mode.
113114
is_library: (bool) Whether the target is a library. Primarily for static analysis purposes.
114115
disable_lint_checks: (list[str]) A list of AndroidLint checks to be skipped.
115116
Returns:

java/common/rules/impl/bazel_java_library_impl.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def bazel_java_library_rule(
6060
add_opens: (list[str]) Allow this library to reflectively access the given <module>/<package>.
6161
bootclasspath: (Target) The JDK APIs to compile this library against.
6262
javabuilder_jvm_flags: (list[str]) Additional JVM flags to pass to JavaBuilder.
63+
unused_deps_mode: (str) Unused dependency checking mode.
6364
disable_lint_checks: (list[str]) A list of AndroidLint checks to be skipped.
6465
Returns:
6566
(dict[str, provider]) A list containing DefaultInfo, JavaInfo,

java/common/rules/impl/compile_action.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def compile_action(
116116
Possible values: 'OFF', 'ERROR', 'WARN' and 'DEFAULT'. For more details
117117
see https://bazel.build/docs/user-manual#strict-java-deps.
118118
By default 'ERROR'.
119+
unused_deps_mode: (str) Unused dependency checking mode.
119120
enable_compile_jar_action: (bool) Enables header compilation or ijar
120121
creation. If set to False, it forces use of the full class jar in the
121122
compilation classpaths of any dependants. Doing so is intended for use

java/private/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ bzl_library(
3838
"//java/common:semantics_bzl",
3939
"//java/common/rules:java_helper_bzl",
4040
"//java/common/rules:toolchain_rules",
41+
"@bazel_features//:features",
4142
"@bazel_skylib//lib:paths",
4243
"@bazel_skylib//rules:common_settings",
4344
"@rules_cc//cc:find_cc_toolchain_bzl",

java/private/java_common_internal.bzl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515
""" Private utilities for Java compilation support in Starlark. """
1616

17+
load(
18+
"@bazel_features//private:util.bzl",
19+
"BAZEL_VERSION",
20+
_bazel_version_ge = "ge",
21+
)
1722
load("@bazel_skylib//lib:paths.bzl", "paths")
1823
load("//java/common:java_semantics.bzl", "semantics")
1924
load("//java/common/rules:java_helper.bzl", "helper")
@@ -27,6 +32,8 @@ load(
2732
)
2833
load(":native.bzl", "get_internal_java_common")
2934

35+
_HAS_UNUSED_DEPS_MODE = BAZEL_VERSION[0] == [999999, 999999, 999999] or _bazel_version_ge("10.0.0")
36+
3037
# copybara: default multiline visibility
3138

3239
_STRICT_DEPS_VALUES = [
@@ -195,6 +202,7 @@ def compile(
195202
compilation action will output in addition to the class jar from annotation processing.
196203
strict_deps: (str) A string that specifies how to handle strict deps. Possible values:
197204
'OFF', 'ERROR', 'WARN' and 'DEFAULT'.
205+
unused_deps_mode: (str) Unused dependency checking mode.
198206
bootclasspath: (BootClassPathInfo) If present, overrides the bootclasspath associated with
199207
the provided java_toolchain. Optional.
200208
javabuilder_jvm_flags: (list[str]) Additional JVM flags to pass to JavaBuilder.
@@ -315,6 +323,10 @@ def compile(
315323
if uses_annotation_processing:
316324
generated_class_jar = _derive_output_file(ctx, output, name_suffix = "-gen")
317325
generated_source_jar = _derive_output_file(ctx, output, name_suffix = "-gensrc")
326+
compilation_action_kwargs = {}
327+
if _HAS_UNUSED_DEPS_MODE:
328+
compilation_action_kwargs["unused_deps_mode"] = unused_deps_mode
329+
318330
get_internal_java_common().create_compilation_action(
319331
ctx,
320332
java_toolchain,
@@ -344,7 +356,7 @@ def compile(
344356
enable_direct_classpath,
345357
annotation_processor_additional_inputs,
346358
annotation_processor_additional_outputs,
347-
unused_deps_mode = unused_deps_mode,
359+
**compilation_action_kwargs
348360
)
349361

350362
create_output_source_jar = len(source_files) > 0 or source_jars != [output_source_jar]

0 commit comments

Comments
 (0)