aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToshifumi Anan <toshifumi.anan@gmail.com>2023-12-22 00:47:19 +0900
committerGitHub <noreply@github.com>2023-12-21 15:47:19 +0000
commitdf234d9a696cb1d23a5612e759602465fa6aef71 (patch)
tree0e79162d39abb8f1310ea966269221aa6d6c6fb4
parentfbeb06090796d6f79b0617108fcf7b595d10ebbf (diff)
downloadbazelbuild-rules_python-df234d9a696cb1d23a5612e759602465fa6aef71.tar.gz
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 https://github.com/bazelbuild/rules_python/issues/1600
-rw-r--r--CHANGELOG.md3
-rw-r--r--python/config_settings/transition.bzl21
-rw-r--r--python/private/common/py_binary_rule_bazel.bzl4
3 files changed, 26 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 31e8d25..c9baef7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/python/config_settings/transition.bzl b/python/config_settings/transition.bzl
index 1b1a5e8..cd54b21 100644
--- a/python/config_settings/transition.bzl
+++ b/python/config_settings/transition.bzl
@@ -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,
)
diff --git a/python/private/common/py_binary_rule_bazel.bzl b/python/private/common/py_binary_rule_bazel.bzl
index 0266381..9ce0726 100644
--- a/python/private/common/py_binary_rule_bazel.bzl
+++ b/python/private/common/py_binary_rule_bazel.bzl
@@ -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,