Skip to content

Commit ebafe03

Browse files
committed
Automatically add _lcov_merger and _collect_cc_coverage attributes
This makes it easier for test rules to support coverage as they no longer need to get the (undocumented) implicit attribute definitions right. In fact, the exec transition used in starlarkified native rules incorrectly used the default rather than the test exec group - the new default definitions of these attributes get this right. Custom rules can continue to override the attributes as demonstrated by the existing `test_starlark_rule_with_custom_lcov_merger` test.
1 parent 90f9bb1 commit ebafe03

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public static LabelLateBoundDefault<CoverageConfiguration> coverageReportGenerat
151151
COVERAGE_REPORT_GENERATOR_CONFIGURATION_RESOLVER);
152152
}
153153

154-
public static LabelLateBoundDefault<CoverageConfiguration> getCoverageOutputGeneratorLabel() {
154+
public static LabelLateBoundDefault<CoverageConfiguration> coverageOutputGeneratorAttribute() {
155155
return LabelLateBoundDefault.fromTargetConfiguration(
156156
CoverageConfiguration.class, null, COVERAGE_OUTPUT_GENERATOR_RESOLVER);
157157
}

src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleClassFunctions.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,19 @@ public static RuleClass getTestBaseRule(RuleDefinitionEnvironment env) {
294294
.cfg(ExecutionTransitionFactory.createFactory())
295295
.singleArtifact()
296296
.value(labelCache.get(toolsRepository + "//tools/test:collect_coverage")))
297+
.add(
298+
attr(":lcov_merger", LABEL)
299+
.cfg(
300+
ExecutionTransitionFactory.createFactory(
301+
DEFAULT_TEST_RUNNER_EXEC_GROUP_NAME))
302+
.value(BaseRuleClasses.coverageOutputGeneratorAttribute()))
303+
.add(
304+
attr("$collect_cc_coverage", LABEL)
305+
.cfg(
306+
ExecutionTransitionFactory.createFactory(
307+
DEFAULT_TEST_RUNNER_EXEC_GROUP_NAME))
308+
.singleArtifact()
309+
.value(labelCache.get(toolsRepository + "//tools/test:collect_cc_coverage")))
297310
// Input files for test actions collecting code coverage
298311
.add(
299312
attr(":coverage_support", LABEL)

src/main/starlark/builtins_bzl/common/cc/semantics.bzl

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,7 @@ def _get_test_malloc_attr():
7171
return {}
7272

7373
def _get_coverage_attrs():
74-
return {
75-
"_lcov_merger": attr.label(
76-
default = configuration_field(fragment = "coverage", name = "output_generator"),
77-
executable = True,
78-
cfg = "exec",
79-
),
80-
"_collect_cc_coverage": attr.label(
81-
default = "@bazel_tools//tools/test:collect_cc_coverage",
82-
executable = True,
83-
cfg = "exec",
84-
),
85-
}
74+
return {}
8675

8776
def _get_coverage_env(ctx):
8877
return ctx.runfiles(), {}

src/test/shell/bazel/bazel_coverage_starlark_test.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,6 @@ _COMMON_ATTRS = {
252252
allow_files = True,
253253
),
254254
"deps": attr.label_list(),
255-
"_lcov_merger": attr.label(
256-
default = configuration_field(fragment = "coverage", name = "output_generator"),
257-
cfg = "exec",
258-
),
259255
}
260256
261257
def _my_library_impl(ctx):

0 commit comments

Comments
 (0)