Skip to content

Commit

Permalink
Expose JacocoRunner from JavaToolchain to Starlark.
Browse files Browse the repository at this point in the history
Issue bazelbuild#11674

Closes bazelbuild#12829.

PiperOrigin-RevId: 352380657
  • Loading branch information
comius authored and copybara-github committed Jan 18, 2021
1 parent 8ab5a61 commit bbac0c3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,6 +59,14 @@ public interface JavaToolchainStarlarkApiProviderApi extends ToolchainInfoApi {
structField = true)
Sequence<String> 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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,6 +49,11 @@ public Sequence<String> getStarlarkJvmOptions() {
return null;
}

@Override
public FilesToRunProviderApi<?> getJacocoRunner() {
return null;
}

@Override
public Depset getStarlarkTools() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'],",
Expand Down

0 comments on commit bbac0c3

Please sign in to comment.