aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/analysis
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/analysis')
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java61
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/OutputFileConfiguredTarget.java6
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java82
3 files changed, 40 insertions, 109 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 031325e121..e43c609149 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 @@ import java.util.List;
* 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 @@ public class BaseRuleClasses {
}
};
- 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 @@ public class BaseRuleClasses {
.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).
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/OutputFileConfiguredTarget.java b/src/main/java/com/google/devtools/build/lib/analysis/OutputFileConfiguredTarget.java
index b24162610d..a7a56a0e6d 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/OutputFileConfiguredTarget.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/OutputFileConfiguredTarget.java
@@ -76,6 +76,12 @@ public class OutputFileConfiguredTarget extends FileConfiguredTarget
.getBaselineCoverageArtifacts();
}
+ @Override
+ public NestedSet<Artifact> getCoverageSupportFiles() {
+ return getProvider(InstrumentedFilesProvider.class, InstrumentedFilesProviderImpl.EMPTY)
+ .getCoverageSupportFiles();
+ }
+
/**
* Returns the corresponding provider from the generating rule, if it is non-null, or {@code
* defaultValue} otherwise.
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java
index 012e72062c..9005801e44 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java
@@ -113,7 +113,6 @@ import javax.annotation.Nullable;
doc = "Data required for the analysis of a target that comes from targets that "
+ "depend on it and not targets that it depends on.")
public final class BuildConfiguration {
-
/**
* An interface for language-specific configurations.
*
@@ -181,27 +180,6 @@ public final class BuildConfiguration {
}
/**
- * Returns the labels required to run coverage for the fragment.
- */
- public ImmutableList<Label> getCoverageLabels() {
- return ImmutableList.of();
- }
-
- /**
- * Returns all labels required to run gcov, if provided by this fragment.
- */
- public ImmutableList<Label> getGcovLabels() {
- return ImmutableList.of();
- }
-
- /**
- * Returns the coverage report generator tool labels.
- */
- public ImmutableList<Label> getCoverageReportGeneratorLabels() {
- return ImmutableList.of();
- }
-
- /**
* Returns a fragment of the output directory name for this configuration. The output
* directory for the whole configuration contains all the short names by all fragments.
*/
@@ -644,6 +622,23 @@ public final class BuildConfiguration {
)
public boolean collectMicroCoverage;
+ @Option(name = "coverage_support",
+ converter = LabelConverter.class,
+ defaultValue = "@bazel_tools//tools/test:coverage_support",
+ category = "testing",
+ help = "Location of support files that are required on the inputs of every test action "
+ + "that collects code coverage. Defaults to '//tools/test:coverage_support'.")
+ public Label coverageSupport;
+
+ @Option(name = "coverage_report_generator",
+ converter = LabelConverter.class,
+ defaultValue = "@bazel_tools//tools/test:coverage_report_generator",
+ category = "testing",
+ help = "Location of the binary that is used to generate coverage reports. This must "
+ + "currently be a filegroup that contains a single file, the binary. Defaults to "
+ + "'//tools/test:coverage_report_generator'.")
+ public Label coverageReportGenerator;
+
@Option(name = "cache_test_results",
defaultValue = "auto",
category = "testing",
@@ -920,6 +915,12 @@ public final class BuildConfiguration {
labelMap.put("RunUnder", runUnder.getLabel());
}
}
+ @Override
+ public Map<String, Set<Label>> getDefaultsLabels(BuildConfiguration.Options commonOptions) {
+ return ImmutableMap.<String, Set<Label>>of(
+ "coverage_support", ImmutableSet.of(coverageSupport),
+ "coverage_report_generator", ImmutableSet.of(coverageReportGenerator));
+ }
}
/**
@@ -1028,10 +1029,6 @@ public final class BuildConfiguration {
/** If false, AnalysisEnviroment doesn't register any actions created by the ConfiguredTarget. */
private final boolean actionsEnabled;
- private final ImmutableSet<Label> coverageLabels;
- private final ImmutableSet<Label> coverageReportGeneratorLabels;
- private final ImmutableSet<Label> gcovLabels;
-
// TODO(bazel-team): Move this to a configuration fragment.
private final PathFragment shExecutable;
@@ -1222,18 +1219,6 @@ public final class BuildConfiguration {
? outputRoots
: new OutputRoots(directories, outputDirName);
- ImmutableSet.Builder<Label> coverageLabelsBuilder = ImmutableSet.builder();
- ImmutableSet.Builder<Label> coverageReportGeneratorLabelsBuilder = ImmutableSet.builder();
- ImmutableSet.Builder<Label> gcovLabelsBuilder = ImmutableSet.builder();
- for (Fragment fragment : fragments.values()) {
- coverageLabelsBuilder.addAll(fragment.getCoverageLabels());
- coverageReportGeneratorLabelsBuilder.addAll(fragment.getCoverageReportGeneratorLabels());
- gcovLabelsBuilder.addAll(fragment.getGcovLabels());
- }
- this.coverageLabels = coverageLabelsBuilder.build();
- this.coverageReportGeneratorLabels = coverageReportGeneratorLabelsBuilder.build();
- this.gcovLabels = gcovLabelsBuilder.build();
-
this.localShellEnvironment = setupShellEnvironment();
this.transitiveOptionsMap = computeOptionsMap(buildOptions, fragments.values());
@@ -2056,27 +2041,6 @@ public final class BuildConfiguration {
}
/**
- * Returns the set of labels for coverage.
- */
- public Set<Label> getCoverageLabels() {
- return coverageLabels;
- }
-
- /**
- * Returns the set of labels for gcov.
- */
- public Set<Label> getGcovLabels() {
- return gcovLabels;
- }
-
- /**
- * Returns the set of labels for the coverage report generator.
- */
- public Set<Label> getCoverageReportGeneratorLabels() {
- return coverageReportGeneratorLabels;
- }
-
- /**
* Returns true if bazel should show analyses results, even if it did not
* re-run the analysis.
*/