From 98e1b30ea46e249c33cae9ff25986c919448d3f1 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 18 Oct 2023 02:54:12 -0700 Subject: [PATCH] Make `android_lint_action` a subrule PiperOrigin-RevId: 574416239 Change-Id: Ib00dd6d034d4437e9c55682a26306106fdf41034 --- .../builtins_bzl/bazel/java/bazel_java_binary.bzl | 2 ++ .../starlark/builtins_bzl/common/java/android_lint.bzl | 8 ++++++-- .../builtins_bzl/common/java/basic_java_library.bzl | 5 ++--- .../starlark/builtins_bzl/common/java/java_library.bzl | 2 ++ .../starlark/builtins_bzl/common/java/java_plugin.bzl | 6 ++++-- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/starlark/builtins_bzl/bazel/java/bazel_java_binary.bzl b/src/main/starlark/builtins_bzl/bazel/java/bazel_java_binary.bzl index e55749c299410a..efe78761e5b98a 100644 --- a/src/main/starlark/builtins_bzl/bazel/java/bazel_java_binary.bzl +++ b/src/main/starlark/builtins_bzl/bazel/java/bazel_java_binary.bzl @@ -13,6 +13,7 @@ # limitations under the License. load(":common/cc/cc_helper.bzl", "cc_helper") +load(":common/java/android_lint.bzl", "android_lint_subrule") load(":common/java/java_binary.bzl", "BASE_TEST_ATTRIBUTES", "BASIC_JAVA_BINARY_ATTRIBUTES", "basic_java_binary") load(":common/java/java_helper.bzl", "helper") load(":common/java/java_info.bzl", "JavaInfo") @@ -288,6 +289,7 @@ def _make_binary_rule(implementation, attrs, executable = False, test = False): exec_groups = { "cpp_link": exec_group(toolchains = cc_helper.use_cpp_toolchain()), }, + subrules = [android_lint_subrule], ) _BASE_BINARY_ATTRS = merge_attrs( diff --git a/src/main/starlark/builtins_bzl/common/java/android_lint.bzl b/src/main/starlark/builtins_bzl/common/java/android_lint.bzl index e05e2be469c681..43f2ae86087425 100644 --- a/src/main/starlark/builtins_bzl/common/java/android_lint.bzl +++ b/src/main/starlark/builtins_bzl/common/java/android_lint.bzl @@ -16,7 +16,7 @@ load(":common/java/java_semantics.bzl", "semantics") -def android_lint_action(ctx, source_files, source_jars, compilation_info): +def _android_lint_action(ctx, source_files, source_jars, compilation_info): """ Creates an action that runs Android lint against Java source files. @@ -125,10 +125,14 @@ def android_lint_action(ctx, source_files, source_jars, compilation_info): tools = tools, arguments = args_list, execution_requirements = {"supports-workers": "1"}, - toolchain = semantics.JAVA_TOOLCHAIN_TYPE, env = { # TODO(b/279025786): replace with setting --XskipJarVerification in AndroidLintRunner "ANDROID_LINT_SKIP_BYTECODE_VERIFIER": "true", }, ) return android_lint_out + +android_lint_subrule = subrule( + implementation = _android_lint_action, + toolchains = [semantics.JAVA_TOOLCHAIN_TYPE], +) diff --git a/src/main/starlark/builtins_bzl/common/java/basic_java_library.bzl b/src/main/starlark/builtins_bzl/common/java/basic_java_library.bzl index 9afe121e1ce91f..03fcd72d1dc6a8 100644 --- a/src/main/starlark/builtins_bzl/common/java/basic_java_library.bzl +++ b/src/main/starlark/builtins_bzl/common/java/basic_java_library.bzl @@ -17,7 +17,7 @@ Common code for reuse across java_* rules """ load(":common/cc/cc_info.bzl", "CcInfo") -load(":common/java/android_lint.bzl", "android_lint_action") +load(":common/java/android_lint.bzl", "android_lint_subrule") load(":common/java/compile_action.bzl", "compile_action") load(":common/java/java_common.bzl", "java_common") load(":common/java/java_common_internal_for_builtins.bzl", "target_kind") @@ -161,8 +161,7 @@ def basic_java_library( for output in java_info.java_outputs if output.generated_source_jar != None ] - lint_output = android_lint_action( - ctx, + lint_output = android_lint_subrule( source_files, source_jars + generated_source_jars, compilation_info, diff --git a/src/main/starlark/builtins_bzl/common/java/java_library.bzl b/src/main/starlark/builtins_bzl/common/java/java_library.bzl index f81e3a1aa76d1a..e803c9ce7cf337 100644 --- a/src/main/starlark/builtins_bzl/common/java/java_library.bzl +++ b/src/main/starlark/builtins_bzl/common/java/java_library.bzl @@ -17,6 +17,7 @@ Definition of java_library rule. """ load(":common/cc/cc_info.bzl", "CcInfo") +load(":common/java/android_lint.bzl", "android_lint_subrule") load(":common/java/basic_java_library.bzl", "BASIC_JAVA_LIBRARY_IMPLICIT_ATTRS", "basic_java_library", "construct_defaultinfo") load(":common/java/java_info.bzl", "JavaInfo", "JavaPluginInfo") load(":common/java/java_semantics.bzl", "semantics") @@ -180,6 +181,7 @@ def _make_java_library_rule(extra_attrs = {}): }, fragments = ["java", "cpp"], toolchains = [semantics.JAVA_TOOLCHAIN], + subrules = [android_lint_subrule], ) java_library = _make_java_library_rule() diff --git a/src/main/starlark/builtins_bzl/common/java/java_plugin.bzl b/src/main/starlark/builtins_bzl/common/java/java_plugin.bzl index ccf51b7aec54dd..e0aaad77b85f57 100644 --- a/src/main/starlark/builtins_bzl/common/java/java_plugin.bzl +++ b/src/main/starlark/builtins_bzl/common/java/java_plugin.bzl @@ -16,11 +16,12 @@ Definition of java_plugin rule. """ +load(":common/java/android_lint.bzl", "android_lint_subrule") load(":common/java/basic_java_library.bzl", "basic_java_library", "construct_defaultinfo") +load(":common/java/java_info.bzl", "JavaPluginInfo") load(":common/java/java_library.bzl", "JAVA_LIBRARY_ATTRS", "JAVA_LIBRARY_IMPLICIT_ATTRS") -load(":common/rule_util.bzl", "merge_attrs") load(":common/java/java_semantics.bzl", "semantics") -load(":common/java/java_info.bzl", "JavaPluginInfo") +load(":common/rule_util.bzl", "merge_attrs") def bazel_java_plugin_rule( ctx, @@ -138,4 +139,5 @@ java_plugin = rule( }, fragments = ["java", "cpp"], toolchains = [semantics.JAVA_TOOLCHAIN], + subrules = [android_lint_subrule], )