From 1b041c86147098451bffc94d2602aea26ee16e06 Mon Sep 17 00:00:00 2001 From: dbabkin Date: Tue, 5 Jun 2018 01:03:14 -0700 Subject: [PATCH] Add LabelLateBoundDefault to :coverage_support attribute RELNOTES:none PiperOrigin-RevId: 199256705 --- .../build/lib/analysis/BaseRuleClasses.java | 16 ++++++++++++++-- .../skylark/SkylarkRuleClassFunctions.java | 7 +++++-- .../lib/analysis/test/TestActionBuilder.java | 4 ++-- .../lib/analysis/test/TestConfiguration.java | 7 +++++++ 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java b/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java index a1454b23d2cb93..2e5c1d56c9e723 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java @@ -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; @@ -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 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 @@ -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) diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java index b93f3579392092..73236d45da2e07 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java @@ -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) diff --git a/src/main/java/com/google/devtools/build/lib/analysis/test/TestActionBuilder.java b/src/main/java/com/google/devtools/build/lib/analysis/test/TestActionBuilder.java index 936ebd77f2ac43..b6b59414f68b92 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/test/TestActionBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/test/TestActionBuilder.java @@ -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 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 = diff --git a/src/main/java/com/google/devtools/build/lib/analysis/test/TestConfiguration.java b/src/main/java/com/google/devtools/build/lib/analysis/test/TestConfiguration.java index 6247fde3cc6181..174952890493e0 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/test/TestConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/test/TestConfiguration.java @@ -176,6 +176,13 @@ public Map> 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 */