diff --git a/CHANGELOG.md b/CHANGELOG.md index 31e8d2561f..c9baef7a07 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 1b1a5e82ef..cd54b21956 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 026638137a..9ce0726c5e 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,