Skip to content

Commit

Permalink
fix(coverage): add test attributes in transition module (#1649)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tanan authored Dec 21, 2023
1 parent fbeb060 commit df234d9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ A brief description of the categories of changes:
instead with a location to the patch that could be used to silence the warning.
Copy the patch to your workspace and add it to the list if patches for the wheel
file if you decide to do so.
* (coverage): coverage reports are now created when the version-aware
rules are used.
([#1600](https://github.com/bazelbuild/rules_python/issues/1600))

### Added

Expand Down
21 changes: 19 additions & 2 deletions python/config_settings/transition.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,33 @@ _COMMON_ATTRS = {
),
}

_PY_TEST_ATTRS = {
# Magic attribute to help C++ coverage work. There's no
# docs about this; see TestActionBuilder.java
"_collect_cc_coverage": attr.label(
default = "@bazel_tools//tools/test:collect_cc_coverage",
executable = True,
cfg = "exec",
),
# Magic attribute to make coverage work. There's no
# docs about this; see TestActionBuilder.java
"_lcov_merger": attr.label(
default = configuration_field(fragment = "coverage", name = "output_generator"),
executable = True,
cfg = "exec",
),
}

_transition_py_binary = rule(
_transition_py_impl,
attrs = _COMMON_ATTRS,
attrs = _COMMON_ATTRS | _PY_TEST_ATTRS,
cfg = _transition_python_version,
executable = True,
)

_transition_py_test = rule(
_transition_py_impl,
attrs = _COMMON_ATTRS,
attrs = _COMMON_ATTRS | _PY_TEST_ATTRS,
cfg = _transition_python_version,
test = True,
)
Expand Down
4 changes: 4 additions & 0 deletions python/private/common/py_binary_rule_bazel.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ load(
)

_PY_TEST_ATTRS = {
# Magic attribute to help C++ coverage work. There's no
# docs about this; see TestActionBuilder.java
"_collect_cc_coverage": attr.label(
default = "@bazel_tools//tools/test:collect_cc_coverage",
executable = True,
cfg = "exec",
),
# Magic attribute to make coverage work. There's no
# docs about this; see TestActionBuilder.java
"_lcov_merger": attr.label(
default = configuration_field(fragment = "coverage", name = "output_generator"),
executable = True,
Expand Down

0 comments on commit df234d9

Please sign in to comment.