diff --git a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/java/JavaToolchainStarlarkApiProviderApi.java b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/java/JavaToolchainStarlarkApiProviderApi.java index 34e5cd8c7f656e..e136358992c919 100644 --- a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/java/JavaToolchainStarlarkApiProviderApi.java +++ b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/java/JavaToolchainStarlarkApiProviderApi.java @@ -17,7 +17,9 @@ import com.google.devtools.build.docgen.annot.DocCategory; import com.google.devtools.build.lib.collect.nestedset.Depset; import com.google.devtools.build.lib.starlarkbuildapi.FileApi; +import com.google.devtools.build.lib.starlarkbuildapi.FilesToRunProviderApi; import com.google.devtools.build.lib.starlarkbuildapi.platform.ToolchainInfoApi; +import javax.annotation.Nullable; import net.starlark.java.annot.StarlarkBuiltin; import net.starlark.java.annot.StarlarkMethod; import net.starlark.java.eval.Sequence; @@ -57,6 +59,14 @@ public interface JavaToolchainStarlarkApiProviderApi extends ToolchainInfoApi { structField = true) Sequence getStarlarkJvmOptions(); + @StarlarkMethod( + name = "jacocorunner", + doc = "The jacocorunner used by the toolchain.", + structField = true, + allowReturnNones = true) + @Nullable + FilesToRunProviderApi getJacocoRunner(); + @StarlarkMethod(name = "tools", doc = "The compilation tools.", structField = true) Depset getStarlarkTools(); } diff --git a/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/java/FakeJavaToolchainStarlarkApiProviderApi.java b/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/java/FakeJavaToolchainStarlarkApiProviderApi.java index 264d0529160ecb..6de9a1a5dbc4de 100644 --- a/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/java/FakeJavaToolchainStarlarkApiProviderApi.java +++ b/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/java/FakeJavaToolchainStarlarkApiProviderApi.java @@ -16,6 +16,7 @@ import com.google.devtools.build.lib.collect.nestedset.Depset; import com.google.devtools.build.lib.starlarkbuildapi.FileApi; +import com.google.devtools.build.lib.starlarkbuildapi.FilesToRunProviderApi; import com.google.devtools.build.lib.starlarkbuildapi.java.JavaToolchainStarlarkApiProviderApi; import net.starlark.java.eval.EvalException; import net.starlark.java.eval.Printer; @@ -48,6 +49,11 @@ public Sequence getStarlarkJvmOptions() { return null; } + @Override + public FilesToRunProviderApi getJacocoRunner() { + return null; + } + @Override public Depset getStarlarkTools() { return null; diff --git a/src/test/java/com/google/devtools/build/lib/rules/java/JavaStarlarkApiTest.java b/src/test/java/com/google/devtools/build/lib/rules/java/JavaStarlarkApiTest.java index 1164eb084c345e..62317c187e03e8 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/java/JavaStarlarkApiTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/java/JavaStarlarkApiTest.java @@ -295,6 +295,37 @@ public void testExposesJavaCommonProvider() throws Exception { assertThat(outputs.getJdeps().getFilename()).isEqualTo("libdep.jdeps"); } + @Test + public void javaToolchainInfo_jacocoRunnerAttribute() throws Exception { + writeBuildFileForJavaToolchain(); + scratch.file("java/test/B.jar"); + scratch.file( + "java/test/BUILD", + "load(':custom_rule.bzl', 'java_custom_library')", + "java_custom_library(name = 'dep')"); + scratch.file( + "java/test/custom_rule.bzl", + "def _impl(ctx):", + " jacoco = ctx.attr._java_toolchain[java_common.JavaToolchainInfo].jacocorunner", + " return [", + " DefaultInfo(", + " files = depset([jacoco.executable]),", + " ),", + " ]", + "java_custom_library = rule(", + " implementation = _impl,", + " attrs = {", + " '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),", + " },", + " fragments = ['java']", + ")"); + + ConfiguredTarget configuredTarget = getConfiguredTarget("//java/test:dep"); + + assertThat(ActionsTestUtil.baseArtifactNames(getFilesToBuild(configuredTarget))) + .containsExactly("jacocorunner.jar"); + } + @Test public void testJavaCommonCompileExposesOutputJarProvider() throws Exception { writeBuildFileForJavaToolchain(); diff --git a/src/test/java/com/google/devtools/build/lib/testutil/FoundationTestCase.java b/src/test/java/com/google/devtools/build/lib/testutil/FoundationTestCase.java index a8d94f3c7b286c..6d0dd733d678eb 100644 --- a/src/test/java/com/google/devtools/build/lib/testutil/FoundationTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/testutil/FoundationTestCase.java @@ -157,6 +157,7 @@ protected void writeBuildFileForJavaToolchain() throws Exception { " },", " tools = [':javac_canary.jar'],", " javabuilder = [':JavaBuilder_deploy.jar'],", + " jacocorunner = ':jacocorunner.jar',", " header_compiler = [':turbine_canary_deploy.jar'],", " header_compiler_direct = [':turbine_graal'],", " singlejar = ['SingleJar_deploy.jar'],",