Skip to content

Commit

Permalink
Add LabelLateBoundDefault to :coverage_support attribute
Browse files Browse the repository at this point in the history
RELNOTES:none
PiperOrigin-RevId: 199256705
  • Loading branch information
dbabkin authored and Copybara-Service committed Jun 5, 2018
1 parent fce20d7 commit 1b041c8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.google.devtools.build.lib.analysis.config.RunUnder;
import com.google.devtools.build.lib.analysis.constraints.EnvironmentRule;
import com.google.devtools.build.lib.analysis.test.TestConfiguration;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.packages.Attribute;
import com.google.devtools.build.lib.packages.Attribute.LabelLateBoundDefault;
import com.google.devtools.build.lib.packages.Attribute.LabelListLateBoundDefault;
Expand Down Expand Up @@ -81,6 +82,16 @@ public Object getDefault(AttributeMap rule) {
BuildConfiguration.class,
(rule, attributes, configuration) -> configuration.getActionListeners());

public static final String DEFAULT_COVERAGE_SUPPORT_VALUE = "//tools/test:coverage_support";

public static LabelLateBoundDefault<TestConfiguration> coverageSupportAttribute(
Label defaultValue) {
return LabelLateBoundDefault.fromTargetConfiguration(
TestConfiguration.class,
defaultValue,
(rule, attributes, configuration) -> configuration.getCoverageSupport());
}

// TODO(b/65746853): provide a way to do this without passing the entire configuration
/** Implementation for the :run_under attribute. */
@AutoCodec
Expand Down Expand Up @@ -151,8 +162,9 @@ public Object getDefault(AttributeMap rule) {
.value(env.getToolsLabel("//tools/test:collect_coverage")))
// Input files for test actions collecting code coverage
.add(
attr("$coverage_support", LABEL)
.value(env.getLabel("//tools/defaults:coverage_support")))
attr(":coverage_support", LABEL)
.value(
coverageSupportAttribute(env.getToolsLabel(DEFAULT_COVERAGE_SUPPORT_VALUE))))
// Used in the one-per-build coverage report generation action.
.add(
attr("$coverage_report_generator", LABEL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,12 @@ public static final RuleClass getTestBaseRule(String toolsRepository,
.value(labelCache.getUnchecked(toolsRepository + "//tools/test:collect_coverage")))
// Input files for test actions collecting code coverage
.add(
attr("$coverage_support", LABEL)
attr(":coverage_support", LABEL)
.cfg(HostTransition.INSTANCE)
.value(labelCache.getUnchecked("//tools/defaults:coverage_support")))
.value(
BaseRuleClasses.coverageSupportAttribute(
labelCache.getUnchecked(
toolsRepository + BaseRuleClasses.DEFAULT_COVERAGE_SUPPORT_VALUE))))
// Used in the one-per-build coverage report generation action.
.add(
attr("$coverage_report_generator", LABEL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ private TestParams createTestAction(int shards) {
// exec paths of all source files that should be included into the code coverage output.
NestedSet<Artifact> metadataFiles = instrumentedFiles.getInstrumentationMetadataFiles();
inputsBuilder.addTransitive(metadataFiles);
inputsBuilder.addTransitive(PrerequisiteArtifacts.nestedSet(
ruleContext, "$coverage_support", Mode.DONT_CHECK));
inputsBuilder.addTransitive(
PrerequisiteArtifacts.nestedSet(ruleContext, ":coverage_support", Mode.DONT_CHECK));
// We don't add this attribute to non-supported test target
if (ruleContext.isAttrDefined("$lcov_merger", LABEL)) {
TransitiveInfoCollection lcovMerger =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ public Map<String, Set<Label>> getDefaultsLabels() {
"coverage_support", ImmutableSet.of(coverageSupport),
"coverage_report_generator", ImmutableSet.of(coverageReportGenerator));
}

@Override
public FragmentOptions getHost() {
TestOptions hostOptions = (TestOptions) getDefault();
hostOptions.coverageSupport = this.coverageSupport;
return hostOptions;
}
}

/** Configuration loader for test options */
Expand Down

0 comments on commit 1b041c8

Please sign in to comment.