From 2829daca9ddbd78631c45ad2ae2e8e17e3061963 Mon Sep 17 00:00:00 2001 From: kshyanashree <109167932+kshyanashree@users.noreply.github.com> Date: Wed, 25 Jan 2023 13:24:59 -0800 Subject: [PATCH] Register JavaCompileActionContext in Bazel. (#17325) 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 Co-authored-by: Benjamin Peterson --- .../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 e1129c5ae7002a..885a610400a4bf 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; @@ -515,6 +518,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