Skip to content

Commit 7b45c59

Browse files
authored
fix(coverage): produce combined coverage report (#520)
Bazel is not producing combined coverage report for targets that don't define the `_lcov_merger` attribute, the `collect_coverage.sh` script just exits silently in this case: https://github.com/bazelbuild/bazel/blob/fde4b67009d377a3543a3dc8481147307bd37d36/tools/test/collect_coverage.sh#L186-L194 Since `rules_python` defines this attribute both for `py_binary` and `py_test`, we're mirroring this behavior by modifying `py_base.attrs`. Tested by applying the patch and verifying that `bazel-out/_coverage/_coverage_report.dat` is not empty after running `bazel coverage --combined_report=lcov [target]`.
1 parent a23ffaa commit 7b45c59

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

py/private/py_binary.bzl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ A collision can occur when multiple packages providing the same file are install
175175
"_allowlist_function_transition": attr.label(
176176
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
177177
),
178+
# Magic attribute to make coverage work. There's no
179+
# docs about this; see TestActionBuilder.java
180+
"_lcov_merger": attr.label(
181+
default = configuration_field(fragment = "coverage", name = "output_generator"),
182+
executable = True,
183+
cfg = "exec",
184+
),
178185
})
179186

180187
_attrs.update(**_py_library.attrs)

0 commit comments

Comments
 (0)