Skip to content

Commit 591d125

Browse files
fmeumcopybara-github
authored andcommitted
Remove unnecessary cc_test coverage handling
Both the `lcov_merger` and the `collect_cc_coverage` script are obtained from "well-known" implicit attributes of Starlark rules and do not require any further special handling. Removing this special handling also fixes a fringe bug: When a `cc_test` is wrapped in another test target that applies a transition to it, the removed logic set the `LCOV_MERGER` variable to the untransitioned path of the `lcov_merger`, which will then not be available in the test sandbox since it is only added as a runfile, but the test action references it via its exec path. This resulted in a "file not found" error that broke coverage. Closes #20349. PiperOrigin-RevId: 589252093 Change-Id: I810f1b414dcfedcc8930a74390ef5c9bfd2cd030
1 parent f6746f5 commit 591d125

File tree

1 file changed

+1
-29
lines changed

1 file changed

+1
-29
lines changed

src/main/starlark/builtins_bzl/common/cc/semantics.bzl

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -86,35 +86,7 @@ def _get_coverage_attrs():
8686
}
8787

8888
def _get_coverage_env(ctx):
89-
runfiles = ctx.runfiles()
90-
test_env = {}
91-
if ctx.configuration.coverage_enabled:
92-
# Bazel’s coverage runner
93-
# (https://github.com/bazelbuild/bazel/blob/3.0.0/tools/test/collect_coverage.sh)
94-
# needs a binary called “lcov_merge.” Its location is passed in the
95-
# LCOV_MERGER environmental variable. For builtin rules, this variable
96-
# is set automatically based on a magic “$lcov_merger” or
97-
# “:lcov_merger” attribute, but it’s not possible to create such
98-
# attributes in Starlark. Therefore we specify the variable ourselves.
99-
# Note that the coverage runner runs in the runfiles root instead of
100-
# the execution root, therefore we use “path” instead of “short_path.”
101-
test_env["LCOV_MERGER"] = ctx.executable._lcov_merger.path
102-
103-
# C/C++ coverage instrumentation needs another binary that wraps gcov;
104-
# see
105-
# https://github.com/bazelbuild/bazel/blob/5.0.0/tools/test/collect_coverage.sh#L199.
106-
# This is normally set from a hidden “$collect_cc_coverage” attribute;
107-
# see
108-
# https://github.com/bazelbuild/bazel/blob/5.0.0/src/main/java/com/google/devtools/build/lib/analysis/test/TestActionBuilder.java#L253-L258.
109-
test_env["CC_CODE_COVERAGE_SCRIPT"] = ctx.executable._collect_cc_coverage.path
110-
111-
# The test runfiles need all applicable runfiles for the tools above.
112-
runfiles = runfiles.merge_all([
113-
ctx.attr._lcov_merger[DefaultInfo].default_runfiles,
114-
ctx.attr._collect_cc_coverage[DefaultInfo].default_runfiles,
115-
])
116-
117-
return runfiles, test_env
89+
return ctx.runfiles(), {}
11890

11991
def _get_cc_runtimes(ctx, is_library):
12092
if is_library:

0 commit comments

Comments
 (0)