Skip to content

Commit

Permalink
Collect coverage from cc_binary data deps of py_test
Browse files Browse the repository at this point in the history
Before this commit, if a py_test executed a cc_binary from its data
deps, coverage for this cc_binary would not be collected. This is fixed
by adding the implicit `$collect_cc_coverage` attribute to
BazelPyTestRule, similar to how this is already done for
BazelShTestRule.

Fixes bazelbuild#15098.

Closes bazelbuild#15097.

PiperOrigin-RevId: 442800790
  • Loading branch information
fmeum committed Apr 21, 2022
1 parent bbcff18 commit 03deb49
Show file tree
Hide file tree
Showing 3 changed files with 532 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env)
.cfg(HostTransition.createFactory())
.value(env.getToolsLabel("//tools/launcher:launcher")))
.add(attr(":lcov_merger", LABEL).value(BaseRuleClasses.getCoverageOutputGeneratorLabel()))
// Add the script as an attribute in order for py_test to output code coverage results for
// code covered by CC binaries invocations.
.add(
attr("$collect_cc_coverage", LABEL)
.cfg(HostTransition.createFactory())
.singleArtifact()
.value(env.getToolsLabel("//tools/test:collect_cc_coverage")))
.build();
}

Expand Down
9 changes: 9 additions & 0 deletions src/test/shell/bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,15 @@ sh_test(
for java_version in JAVA_VERSIONS_COVERAGE
]

sh_test(
name = "bazel_coverage_py_test",
srcs = ["bazel_coverage_py_test.sh"],
data = [":test-deps"],
tags = [
"no_windows",
],
)

sh_test(
name = "bazel_coverage_sh_test",
srcs = ["bazel_coverage_sh_test.sh"],
Expand Down
Loading

0 comments on commit 03deb49

Please sign in to comment.