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: 199604462
  • Loading branch information
dbabkin authored and Copybara-Service committed Jun 7, 2018
1 parent 5146ce0 commit 708b957
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
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;
import com.google.devtools.build.lib.packages.Attribute.LateBoundDefault.Resolver;
import com.google.devtools.build.lib.packages.AttributeMap;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
Expand Down Expand Up @@ -81,6 +83,18 @@ public Object getDefault(AttributeMap rule) {
BuildConfiguration.class,
(rule, attributes, configuration) -> configuration.getActionListeners());

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

@AutoCodec
static final Resolver<TestConfiguration, Label> COVERAGE_SUPPORT_CONFIGURATION_RESOLVER =
(rule, attributes, configuration) -> configuration.getCoverageSupport();

public static LabelLateBoundDefault<TestConfiguration> coverageSupportAttribute(
Label defaultValue) {
return LabelLateBoundDefault.fromTargetConfiguration(
TestConfiguration.class, defaultValue, COVERAGE_SUPPORT_CONFIGURATION_RESOLVER);
}

// 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 +165,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 708b957

Please sign in to comment.