From 6a60b30cd0f22d0ab84b2ddd658d5ccb899a8a76 Mon Sep 17 00:00:00 2001 From: Ivo List Date: Tue, 12 Jan 2021 12:54:08 +0100 Subject: [PATCH] Fix coverage support when using default_java_toolchain. (#12801) * Fix coverage support when using default_java_toolchain. In such case jacoco runner was not set on the java_toolchain. Issue https://github.com/bazelbuild/bazel/issues/12793 * Additional coverage test for predefined toolchains. * Revert "Additional coverage test for predefined toolchains." This reverts commit da3f7fd420a525b26aa542b89b768d1d6dce9237. --- src/test/shell/bazel/bazel_coverage_java_test.sh | 11 ++++++++++- tools/jdk/BUILD | 2 +- tools/jdk/default_java_toolchain.bzl | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/test/shell/bazel/bazel_coverage_java_test.sh b/src/test/shell/bazel/bazel_coverage_java_test.sh index deafebec367f18..082bace4eec2c3 100755 --- a/src/test/shell/bazel/bazel_coverage_java_test.sh +++ b/src/test/shell/bazel/bazel_coverage_java_test.sh @@ -99,6 +99,8 @@ function get_coverage_file_path_from_test_log() { function test_java_test_coverage() { cat < BUILD +load("//tools/jdk:default_java_toolchain.bzl", "default_java_toolchain") + java_test( name = "test", srcs = glob(["src/test/**/*.java"]), @@ -110,6 +112,10 @@ java_library( name = "collatz-lib", srcs = glob(["src/main/**/*.java"]), ) + +default_java_toolchain( + name = "custom_toolchain" +) EOF mkdir -p src/main/com/example @@ -179,7 +185,10 @@ LH:5 LF:6 end_of_record" -assert_coverage_result "$expected_result" "$coverage_file_path" + assert_coverage_result "$expected_result" "$coverage_file_path" + + bazel coverage --test_output=all --java_toolchain=//:custom_toolchain //:test &>$TEST_log || fail "Coverage with default_java_toolchain for //:test failed" + assert_coverage_result "$expected_result" "$coverage_file_path" } function test_java_test_coverage_combined_report() { diff --git a/tools/jdk/BUILD b/tools/jdk/BUILD index 9e005b3c1f8862..13f575a8afb0c5 100644 --- a/tools/jdk/BUILD +++ b/tools/jdk/BUILD @@ -271,7 +271,7 @@ remote_java_tools_java_import( target = ":java_tools/JacocoCoverage_jarjar_deploy.jar", ) -remote_java_tools_java_import( +remote_java_tools_filegroup( name = "JacocoCoverage", target = ":java_tools/JacocoCoverage_jarjar_deploy.jar", ) diff --git a/tools/jdk/default_java_toolchain.bzl b/tools/jdk/default_java_toolchain.bzl index 9d410919950932..2fe21259c01abc 100644 --- a/tools/jdk/default_java_toolchain.bzl +++ b/tools/jdk/default_java_toolchain.bzl @@ -56,6 +56,7 @@ DEFAULT_TOOLCHAIN_CONFIGURATION = { "header_compiler_direct": ["@bazel_tools//tools/jdk:turbine_direct"], "ijar": ["@bazel_tools//tools/jdk:ijar"], "javabuilder": ["@bazel_tools//tools/jdk:javabuilder"], + "jacocorunner": "@bazel_tools//tools/jdk:JacocoCoverage", "tools": [ "@bazel_tools//tools/jdk:javac_jar", "@bazel_tools//tools/jdk:java_compiler_jar",