From ac504cbb463e76b1374d0060534acabbccb408d2 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Tue, 13 Dec 2022 01:18:20 -0800 Subject: [PATCH] Register JavaCompileActionContext in Bazel. This makes --experimental_java_classpath=bazel work. This CL is similar to https://github.com/bazelbuild/bazel/pull/16636 but applies the code review feedback. (Though, I put the context registration in BazelRulesModule rather than BazelStrategyModule as JavaCompileActionContext isn't really a strategy.) Fixes https://github.com/bazelbuild/bazel/issues/16635. Closes #16921. PiperOrigin-RevId: 494950719 Change-Id: Ia32e2d0e67ddacaf18ba52591f7b67b3c6c7b792 --- .../build/lib/bazel/rules/BazelRulesModule.java | 11 +++++++++++ src/test/shell/bazel/bazel_java_test.sh | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRulesModule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRulesModule.java index d9a7c64cfece81..7f454bb813187b 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRulesModule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRulesModule.java @@ -19,10 +19,13 @@ import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider; import com.google.devtools.build.lib.bazel.rules.cpp.BazelCppRuleClasses; import com.google.devtools.build.lib.bazel.rules.sh.BazelShRuleClasses; +import com.google.devtools.build.lib.buildtool.BuildRequest; +import com.google.devtools.build.lib.exec.ModuleActionContextRegistry; import com.google.devtools.build.lib.remote.options.RemoteOptions; import com.google.devtools.build.lib.rules.cpp.CcSkyframeFdoSupportFunction; import com.google.devtools.build.lib.rules.cpp.CcSkyframeFdoSupportValue; import com.google.devtools.build.lib.rules.cpp.CppOptions; +import com.google.devtools.build.lib.rules.java.JavaCompileActionContext; import com.google.devtools.build.lib.rules.java.JavaOptions; import com.google.devtools.build.lib.runtime.BlazeModule; import com.google.devtools.build.lib.runtime.BlazeRuntime; @@ -523,6 +526,14 @@ public Iterable> getCommandOptions(Command command) : ImmutableList.of(AllCommandGraveyardOptions.class); } + @Override + public void registerActionContexts( + ModuleActionContextRegistry.Builder registryBuilder, + CommandEnvironment env, + BuildRequest buildRequest) { + registryBuilder.register(JavaCompileActionContext.class, new JavaCompileActionContext()); + } + private static void validateRemoteOutputsMode(CommandEnvironment env) throws AbruptExitException { RemoteOptions remoteOptions = env.getOptions().getOptions(RemoteOptions.class); if (remoteOptions == null) { diff --git a/src/test/shell/bazel/bazel_java_test.sh b/src/test/shell/bazel/bazel_java_test.sh index 5e55ff302f6b1b..a30ba12f961930 100755 --- a/src/test/shell/bazel/bazel_java_test.sh +++ b/src/test/shell/bazel/bazel_java_test.sh @@ -325,6 +325,12 @@ function test_build_hello_world() { bazel build //java/main:main &> $TEST_log || fail "build failed" } +function test_build_hello_world_reduced_classpath() { + write_hello_library_files + + bazel build --experimental_java_classpath=bazel //java/main:main &> $TEST_log || fail "build failed" +} + function test_worker_strategy_is_default() { write_hello_library_files