Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose JacocoRunner from JavaToolchain to Starlark. #12829

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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