diff options
author | 2015-07-29 14:49:01 +0000 | |
---|---|---|
committer | 2015-07-29 16:03:41 +0000 | |
commit | 40deeff2fb1a0686be6276c1559ce051fe079a04 (patch) | |
tree | db1ce933aeeecafb401be94741427552659254a7 /src/main/java/com/google/devtools/build/lib/analysis | |
parent | a0345bce94607a7096777d9013eed4c08cf12edc (diff) |
Support coverage in experimental_ios_test.
Coverage depends on quite a few moving parts, several of which were changed for this test:
- BuildConfiguration.getCoverageLabels() used to include gcov support, this is now replaced by the dedicated getGcovLabels() and a separate implicit attribute on TestBaseRule. This new attribute is then overridden in ExperimentalIosTest to use an xcode-compatible gcov.
- Objc's TestSupport now correctly registers instrumented files and sets the necessary runfiles for collecting coverage.
- ios_test's template exports gcda files for coverage computation after the test's execution.
--
MOS_MIGRATED_REVID=99374435
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.java | 15 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java | 20 |
2 files changed, 32 insertions, 3 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 4baf3b3d7e..48887ddf1b 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 @@ -93,7 +93,17 @@ public class BaseRuleClasses { @Override public List<Label> getDefault(Rule rule, BuildConfiguration configuration) { return configuration.isCodeCoverageEnabled() - ? ImmutableList.<Label>copyOf(configuration.getCoverageLabels()) + ? 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> getDefault(Rule rule, BuildConfiguration configuration) { + return configuration.isCodeCoverageEnabled() + ? ImmutableList.copyOf(configuration.getGcovLabels()) : ImmutableList.<Label>of(); } }; @@ -103,7 +113,7 @@ public class BaseRuleClasses { @Override public List<Label> getDefault(Rule rule, BuildConfiguration configuration) { return configuration.isCodeCoverageEnabled() - ? ImmutableList.<Label>copyOf(configuration.getCoverageReportGeneratorLabels()) + ? ImmutableList.copyOf(configuration.getCoverageReportGeneratorLabels()) : ImmutableList.<Label>of(); } }; @@ -158,6 +168,7 @@ public class BaseRuleClasses { // 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)) 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 f8b8199c16..d613f1e37e 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 @@ -173,13 +173,20 @@ public final class BuildConfiguration { } /** - * Returns all the coverage labels for the fragment. + * 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() { @@ -915,6 +922,7 @@ public final class BuildConfiguration { 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; @@ -1048,12 +1056,15 @@ public final class BuildConfiguration { 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.defaultShellEnvironment = setupShellEnvironment(); @@ -1519,6 +1530,13 @@ public final class BuildConfiguration { } /** + * 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() { |