Refactor how coverage support files get to test actions.

Previously we used labels in each configuration fragment that then got added to every test action. Instead, we now have a filegroup under //tools/test for coverage files that truly need to be on the inputs of every test action and collect language-specific support files in InstrumentedFilesProvider.

This makes configuration creation simpler and makes it possible to turn --crosstool_top into something else other than a filegroup (previously, it was that filegroup that got added to every test action)

--
MOS_MIGRATED_REVID=126170241
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 031325e..e43c609 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
@@ -51,13 +51,6 @@
  * Rule class definitions used by (almost) every rule.
  */
 public class BaseRuleClasses {
-  /**
-   * Label of the pseudo-filegroup that contains all the targets that are needed
-   * for running tests in coverage mode.
-   */
-  private static final Label COVERAGE_SUPPORT_LABEL =
-      Label.parseAbsoluteUnchecked("//tools/defaults:coverage");
-
   private static final Attribute.ComputedDefault testonlyDefault =
       new Attribute.ComputedDefault() {
         @Override
@@ -91,43 +84,10 @@
     }
   };
 
-  private static final LateBoundLabelList<BuildConfiguration> COVERAGE_SUPPORT =
-      new LateBoundLabelList<BuildConfiguration>(ImmutableList.of(COVERAGE_SUPPORT_LABEL)) {
-        @Override
-        public List<Label> resolve(Rule rule, AttributeMap attributes,
-            BuildConfiguration configuration) {
-          return configuration.isCodeCoverageEnabled()
-              ? ImmutableList.copyOf(configuration.getCoverageLabels())
-              : ImmutableList.<Label>of();
-        }
-      };
-
-  private static final LateBoundLabelList<BuildConfiguration> GCOV =
-      new LateBoundLabelList<BuildConfiguration>(ImmutableList.of(COVERAGE_SUPPORT_LABEL)) {
-        @Override
-        public List<Label> resolve(Rule rule, AttributeMap attributes,
-            BuildConfiguration configuration) {
-          return configuration.isCodeCoverageEnabled()
-              ? ImmutableList.copyOf(configuration.getGcovLabels())
-              : ImmutableList.<Label>of();
-        }
-      };
-
-  private static final LateBoundLabelList<BuildConfiguration> COVERAGE_REPORT_GENERATOR =
-      new LateBoundLabelList<BuildConfiguration>(ImmutableList.of(COVERAGE_SUPPORT_LABEL)) {
-        @Override
-        public List<Label> resolve(Rule rule, AttributeMap attributes,
-            BuildConfiguration configuration) {
-          return configuration.isCodeCoverageEnabled()
-              ? ImmutableList.copyOf(configuration.getCoverageReportGeneratorLabels())
-              : ImmutableList.<Label>of();
-        }
-      };
-
   /**
    * Implementation for the :run_under attribute.
    */
-  private static final LateBoundLabel<BuildConfiguration> RUN_UNDER =
+  public static final LateBoundLabel<BuildConfiguration> RUN_UNDER =
       new LateBoundLabel<BuildConfiguration>() {
         @Override
         public Label resolve(Rule rule, AttributeMap attributes,
@@ -168,17 +128,18 @@
               .nonconfigurable("policy decision: should be consistent across configurations"))
           .add(attr("args", STRING_LIST)
               .nonconfigurable("policy decision: should be consistent across configurations"))
+          // Input files for every test action
           .add(attr("$test_runtime", LABEL_LIST).cfg(HOST).value(ImmutableList.of(
               env.getToolsLabel("//tools/test:runtime"))))
-
-          // TODO(bazel-team): TestActions may need to be run with coverage, so all tests
-          // implicitly depend on crosstool, which provides gcov.  We could add gcov to
-          // InstrumentedFilesProvider.getInstrumentationMetadataFiles() (or a new method) for
-          // all the test rules that have C++ in their transitive closure. Then this could go.
-          .add(attr(":gcov", LABEL_LIST).cfg(HOST).value(GCOV))
-          .add(attr(":coverage_support", LABEL_LIST).cfg(HOST).value(COVERAGE_SUPPORT))
-          .add(attr(":coverage_report_generator", LABEL_LIST).cfg(HOST)
-              .value(COVERAGE_REPORT_GENERATOR))
+          // Input files for test actions collecting code coverage
+          .add(attr("$coverage_support", LABEL)
+              .cfg(HOST)
+              .value(env.getLabel("//tools/defaults:coverage_support")))
+          // Used in the one-per-build coverage report generation action.
+          .add(attr("$coverage_report_generator", LABEL)
+              .cfg(HOST)
+              .value(env.getLabel("//tools/defaults:coverage_report_generator"))
+              .singleArtifact())
 
           // The target itself and run_under both run on the same machine. We use the DATA config
           // here because the run_under acts like a data dependency (e.g. no LIPO optimization).