Skip to content

Commit df234d9

Browse files
authored
fix(coverage): add test attributes in transition module (#1649)
This PR is to fix an issue that coverage report is empty when using transition module. This is due to the absence of the `_lcov_merger` and `_collect_cc_coverage` attributes. Coverage reports will be created adding these attributes. Fixes #1600
1 parent fbeb060 commit df234d9

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ A brief description of the categories of changes:
5555
instead with a location to the patch that could be used to silence the warning.
5656
Copy the patch to your workspace and add it to the list if patches for the wheel
5757
file if you decide to do so.
58+
* (coverage): coverage reports are now created when the version-aware
59+
rules are used.
60+
([#1600](https://github.com/bazelbuild/rules_python/issues/1600))
5861

5962
### Added
6063

python/config_settings/transition.bzl

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,33 @@ _COMMON_ATTRS = {
142142
),
143143
}
144144

145+
_PY_TEST_ATTRS = {
146+
# Magic attribute to help C++ coverage work. There's no
147+
# docs about this; see TestActionBuilder.java
148+
"_collect_cc_coverage": attr.label(
149+
default = "@bazel_tools//tools/test:collect_cc_coverage",
150+
executable = True,
151+
cfg = "exec",
152+
),
153+
# Magic attribute to make coverage work. There's no
154+
# docs about this; see TestActionBuilder.java
155+
"_lcov_merger": attr.label(
156+
default = configuration_field(fragment = "coverage", name = "output_generator"),
157+
executable = True,
158+
cfg = "exec",
159+
),
160+
}
161+
145162
_transition_py_binary = rule(
146163
_transition_py_impl,
147-
attrs = _COMMON_ATTRS,
164+
attrs = _COMMON_ATTRS | _PY_TEST_ATTRS,
148165
cfg = _transition_python_version,
149166
executable = True,
150167
)
151168

152169
_transition_py_test = rule(
153170
_transition_py_impl,
154-
attrs = _COMMON_ATTRS,
171+
attrs = _COMMON_ATTRS | _PY_TEST_ATTRS,
155172
cfg = _transition_python_version,
156173
test = True,
157174
)

python/private/common/py_binary_rule_bazel.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ load(
2222
)
2323

2424
_PY_TEST_ATTRS = {
25+
# Magic attribute to help C++ coverage work. There's no
26+
# docs about this; see TestActionBuilder.java
2527
"_collect_cc_coverage": attr.label(
2628
default = "@bazel_tools//tools/test:collect_cc_coverage",
2729
executable = True,
2830
cfg = "exec",
2931
),
32+
# Magic attribute to make coverage work. There's no
33+
# docs about this; see TestActionBuilder.java
3034
"_lcov_merger": attr.label(
3135
default = configuration_field(fragment = "coverage", name = "output_generator"),
3236
executable = True,

0 commit comments

Comments
 (0)