Skip to content

Commit

Permalink
Fix coverage support when using default_java_toolchain. (#12801)
Browse files Browse the repository at this point in the history
* Fix coverage support when using default_java_toolchain.

In such case jacoco runner was not set on the java_toolchain.

Issue #12793

* Additional coverage test for predefined toolchains.

* Revert "Additional coverage test for predefined toolchains."

This reverts commit da3f7fd.
  • Loading branch information
comius authored and meisterT committed Jan 12, 2021
1 parent 021576d commit 6a60b30
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/test/shell/bazel/bazel_coverage_java_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ function get_coverage_file_path_from_test_log() {

function test_java_test_coverage() {
cat <<EOF > BUILD
load("//tools/jdk:default_java_toolchain.bzl", "default_java_toolchain")
java_test(
name = "test",
srcs = glob(["src/test/**/*.java"]),
Expand All @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion tools/jdk/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down
1 change: 1 addition & 0 deletions tools/jdk/default_java_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 6a60b30

Please sign in to comment.