From 8fa4a21f72092d282d4a24a66ff6db158ea90b76 Mon Sep 17 00:00:00 2001 From: tanan Date: Thu, 21 Dec 2023 15:16:58 +0900 Subject: [PATCH 1/4] fix(coverage): add test attr in transition module --- CHANGELOG.md | 2 ++ python/config_settings/transition.bzl | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b524536b8c..08b5546b58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,8 @@ A brief description of the categories of changes: specifying a local system interpreter. * (bzlmod pip.parse) Requirements files with duplicate entries for the same package (e.g. one for the package, one for an extra) now work. +* (coverage): `_lcov_merger` attr added in `_transition_py_test` and + coverage reports are now created when using the transition module. ### Added diff --git a/python/config_settings/transition.bzl b/python/config_settings/transition.bzl index 1b1a5e82ef..23738c3d59 100644 --- a/python/config_settings/transition.bzl +++ b/python/config_settings/transition.bzl @@ -142,16 +142,29 @@ _COMMON_ATTRS = { ), } +_PY_TEST_ATTRS = { + "_collect_cc_coverage": attr.label( + default = "@bazel_tools//tools/test:collect_cc_coverage", + executable = True, + cfg = "exec", + ), + "_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, ) From 12a6072f076bcfa10a62b94783d4d511984b96a3 Mon Sep 17 00:00:00 2001 From: tanan Date: Thu, 21 Dec 2023 15:40:38 +0900 Subject: [PATCH 2/4] fix(docs): change attributes --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08b5546b58..8c72d675b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,8 +46,8 @@ A brief description of the categories of changes: specifying a local system interpreter. * (bzlmod pip.parse) Requirements files with duplicate entries for the same package (e.g. one for the package, one for an extra) now work. -* (coverage): `_lcov_merger` attr added in `_transition_py_test` and - coverage reports are now created when using the transition module. +* (coverage): Test attributes added in transition module and coverage + reports are now created when using the transition module. ### Added From 6b467107b784db40428b7fe201df41e7ef5546ca Mon Sep 17 00:00:00 2001 From: tanan Date: Thu, 21 Dec 2023 17:41:40 +0900 Subject: [PATCH 3/4] fix(docs): add an issue reference --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c72d675b8..5f947a7769 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,8 +46,9 @@ A brief description of the categories of changes: specifying a local system interpreter. * (bzlmod pip.parse) Requirements files with duplicate entries for the same package (e.g. one for the package, one for an extra) now work. -* (coverage): Test attributes added in transition module and coverage - reports are now created when using the transition module. +* (coverage): coverage reports are now created when the version-aware + rules are used. + ([#1600](https://github.com/bazelbuild/rules_python/issues/1600)) ### Added From 4e93b7bc43c2f624be17538382e05d2be173131e Mon Sep 17 00:00:00 2001 From: tanan Date: Thu, 21 Dec 2023 17:44:06 +0900 Subject: [PATCH 4/4] fix(docs): add comments for coverage attributes --- python/config_settings/transition.bzl | 4 ++++ python/private/common/py_binary_rule_bazel.bzl | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/python/config_settings/transition.bzl b/python/config_settings/transition.bzl index 23738c3d59..cd54b21956 100644 --- a/python/config_settings/transition.bzl +++ b/python/config_settings/transition.bzl @@ -143,11 +143,15 @@ _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, 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,