aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2017-03-22 15:00:40 +0000
committerGravatar Yue Gan <yueg@google.com>2017-03-22 15:12:45 +0000
commit13862c7c20ed503cc9df3eb80f2eb97f79ecbe14 (patch)
treec35c14385d5f76fe57a5726541acd8d4328e7220
parent79bd2c2bdca3d97063d1a08e6be2ea8f5724fe13 (diff)
Add an optional coverage_files argument to cc_toolchain
Allow toolchains to specify precisely the files required to run code coverage tools (e.g. gcov). If not specifed, default to the existing behaviour of supplying the whole crosstool. RELNOTES[NEW]: Optional coverage_files attribute to cc_toolchain -- PiperOrigin-RevId: 150878146 MOS_MIGRATED_REVID=150878146
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java15
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java11
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainRule.java1
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java6
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/LicensingTests.java9
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java1
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSuiteTest.java4
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainTest.java3
8 files changed, 42 insertions, 8 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java
index ca9cf8c98f..73060ef00f 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java
@@ -199,6 +199,11 @@ public class CcToolchain implements RuleConfiguredTargetFactory {
"FDO_DIR", cppConfiguration.getFdoInstrument().getPathString()));
}
+ NestedSet<Artifact> coverage = getOptionalFiles(ruleContext, "coverage_files");
+ if (coverage.isEmpty()) {
+ coverage = crosstool;
+ }
+
CcToolchainProvider provider =
new CcToolchainProvider(
cppConfiguration,
@@ -210,6 +215,7 @@ public class CcToolchain implements RuleConfiguredTargetFactory {
fullInputsForLink(ruleContext, link),
ruleContext.getPrerequisiteArtifact("$interface_library_builder", Mode.HOST),
dwp,
+ coverage,
libcLink,
staticRuntimeLinkInputs,
staticRuntimeLinkMiddleman,
@@ -241,7 +247,7 @@ public class CcToolchain implements RuleConfiguredTargetFactory {
// :cc_toolchain attribute instead.
final License outputLicense =
ruleContext.getRule().getToolOutputLicense(ruleContext.attributes());
- if (outputLicense != null && outputLicense != License.NO_LICENSE) {
+ if (outputLicense != null && !outputLicense.equals(License.NO_LICENSE)) {
final NestedSet<TargetLicense> license = NestedSetBuilder.create(Order.STABLE_ORDER,
new TargetLicense(ruleContext.getLabel(), outputLicense));
LicensesProvider licensesProvider = new LicensesProvider() {
@@ -340,6 +346,13 @@ public class CcToolchain implements RuleConfiguredTargetFactory {
: dep.getProvider(FileProvider.class).getFilesToBuild();
}
+ private NestedSet<Artifact> getOptionalFiles(RuleContext context, String attribute) {
+ TransitiveInfoCollection dep = context.getPrerequisite(attribute, Mode.HOST);
+ return dep != null
+ ? getFiles(context, attribute)
+ : NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER);
+ }
+
/**
* Returns a map that should be templated into the crosstool as build variables. Is meant to
* be overridden by subclasses of CcToolchain.
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java
index 8f2f7679fa..498822161f 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java
@@ -47,6 +47,7 @@ public final class CcToolchainProvider implements TransitiveInfoProvider {
NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER),
NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER),
NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER),
+ NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER),
null,
NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER),
null,
@@ -69,6 +70,7 @@ public final class CcToolchainProvider implements TransitiveInfoProvider {
private final NestedSet<Artifact> link;
private final Artifact interfaceSoBuilder;
private final NestedSet<Artifact> dwp;
+ private final NestedSet<Artifact> coverage;
private final NestedSet<Artifact> libcLink;
private final NestedSet<Artifact> staticRuntimeLinkInputs;
@Nullable private final Artifact staticRuntimeLinkMiddleman;
@@ -94,6 +96,7 @@ public final class CcToolchainProvider implements TransitiveInfoProvider {
NestedSet<Artifact> link,
Artifact interfaceSoBuilder,
NestedSet<Artifact> dwp,
+ NestedSet<Artifact> coverage,
NestedSet<Artifact> libcLink,
NestedSet<Artifact> staticRuntimeLinkInputs,
@Nullable Artifact staticRuntimeLinkMiddleman,
@@ -117,6 +120,7 @@ public final class CcToolchainProvider implements TransitiveInfoProvider {
this.link = Preconditions.checkNotNull(link);
this.interfaceSoBuilder = interfaceSoBuilder;
this.dwp = Preconditions.checkNotNull(dwp);
+ this.coverage = Preconditions.checkNotNull(coverage);
this.libcLink = Preconditions.checkNotNull(libcLink);
this.staticRuntimeLinkInputs = Preconditions.checkNotNull(staticRuntimeLinkInputs);
this.staticRuntimeLinkMiddleman = staticRuntimeLinkMiddleman;
@@ -179,6 +183,13 @@ public final class CcToolchainProvider implements TransitiveInfoProvider {
return dwp;
}
+ /**
+ * Returns the files necessary for capturing code coverage.
+ */
+ public NestedSet<Artifact> getCoverage() {
+ return coverage;
+ }
+
public NestedSet<Artifact> getLibcLink() {
return libcLink;
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainRule.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainRule.java
index 877865d9f4..a1922b8553 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainRule.java
@@ -70,6 +70,7 @@ public final class CcToolchainRule implements RuleDefinition {
.add(attr("objcopy_files", LABEL).legacyAllowAnyFileType().cfg(HOST).mandatory())
.add(attr("linker_files", LABEL).legacyAllowAnyFileType().cfg(HOST).mandatory())
.add(attr("dwp_files", LABEL).legacyAllowAnyFileType().cfg(HOST).mandatory())
+ .add(attr("coverage_files", LABEL).legacyAllowAnyFileType().cfg(HOST))
.add(attr("static_runtime_libs", LABEL_LIST).legacyAllowAnyFileType().mandatory())
.add(attr("dynamic_runtime_libs", LABEL_LIST).legacyAllowAnyFileType().mandatory())
.add(attr("module_map", LABEL).legacyAllowAnyFileType().cfg(HOST))
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
index 3134aad034..a94d10ea6d 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
@@ -241,7 +241,7 @@ public class CppHelper {
public static NestedSet<Artifact> getGcovFilesIfNeeded(
RuleContext ruleContext, CcToolchainProvider toolchain) {
if (ruleContext.getConfiguration().isCodeCoverageEnabled()) {
- return toolchain.getCrosstool();
+ return toolchain.getCoverage();
} else {
return NestedSetBuilder.emptySet(Order.STABLE_ORDER);
}
@@ -396,8 +396,8 @@ public class CppHelper {
NestedSetBuilder<IncludeScannable> scannableBuilder) {
TransitiveLipoInfoProvider stl = null;
- if (ruleContext.getRule().getAttributeDefinition(":stl") != null &&
- ruleContext.getPrerequisite(":stl", Mode.TARGET) != null) {
+ if (ruleContext.getRule().getAttributeDefinition(":stl") != null
+ && ruleContext.getPrerequisite(":stl", Mode.TARGET) != null) {
// If the attribute is defined, it is never null.
stl = ruleContext.getPrerequisite(":stl", Mode.TARGET)
.getProvider(TransitiveLipoInfoProvider.class);
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/LicensingTests.java b/src/test/java/com/google/devtools/build/lib/analysis/LicensingTests.java
index f991c1262e..679b6dd6bc 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/LicensingTests.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/LicensingTests.java
@@ -215,7 +215,7 @@ public class LicensingTests extends BuildViewTestCase {
License cLicense = getTarget(cTarget.getLabel()).getLicense();
assertFalse(aLicense.equals(bLicense));
assertEquals(License.parseLicense(Arrays.asList("unencumbered")), aLicense);
- assertEquals(License.parseLicense(Arrays.asList("restricted","reciprocal")),
+ assertEquals(License.parseLicense(Arrays.asList("restricted", "reciprocal")),
bLicense);
assertEquals(License.parseLicense(Arrays.asList("unencumbered")), cLicense);
}
@@ -463,6 +463,7 @@ public class LicensingTests extends BuildViewTestCase {
" cpu = 'cherry',",
" compiler_files = 'compile-cherry',",
" dwp_files = 'dwp-cherry',",
+ " coverage_files = 'gcov-cherry',",
" linker_files = 'link-cherry',",
" strip_files = ':every-file',",
" objcopy_files = 'objcopy-cherry',",
@@ -485,7 +486,7 @@ public class LicensingTests extends BuildViewTestCase {
License l3 = License.parseLicense(Arrays.asList("by_exception_only",
"reciprocal", "exception=//a:a", "exception=//b:b"));
assertEquals("[restricted] with exceptions [//a:a]", l1.toString());
- assertEquals("[restricted, reciprocal] with exceptions [//a:a]",l2.toString());
+ assertEquals("[restricted, reciprocal] with exceptions [//a:a]", l2.toString());
assertEquals("[by_exception_only, reciprocal] with exceptions [//a:a, //b:b]", l3.toString());
}
@@ -497,9 +498,9 @@ public class LicensingTests extends BuildViewTestCase {
protected static Map<Label, License> licenses(String... strings)
throws LicenseParsingException, LabelSyntaxException {
Map<Label, License> result = new HashMap<>();
- for (int i=0; i < strings.length; i += 2) {
+ for (int i = 0; i < strings.length; i += 2) {
String labelStr = strings[i];
- String licStr = strings[i+1];
+ String licStr = strings[i + 1];
Label label = Label.parseAbsolute(labelStr);
List<String> splitLicenses =
licStr.isEmpty() ? Arrays.<String>asList() : Arrays.asList(licStr.split(","));
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java
index 7afa95c5f8..b7bd6a874b 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java
@@ -139,6 +139,7 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase {
" cpu = 'k8',",
" compiler_files = ':empty',",
" dwp_files = ':empty',",
+ " coverage_files = ':empty',",
" linker_files = ':empty',",
" strip_files = ':empty',",
" objcopy_files = ':empty',",
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSuiteTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSuiteTest.java
index f53cf578ae..71d0ab37f6 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSuiteTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSuiteTest.java
@@ -157,6 +157,7 @@ public class CcToolchainSuiteTest extends BuildViewTestCase {
" cpu = 'cpu',",
" compiler_files = 'compile',",
" dwp_files = 'dwp',",
+ " coverage_files = 'gcov',",
" linker_files = 'link',",
" strip_files = ':strip',",
" objcopy_files = 'objcopy',",
@@ -173,6 +174,7 @@ public class CcToolchainSuiteTest extends BuildViewTestCase {
" cpu = 'cpu',",
" compiler_files = 'compile',",
" dwp_files = 'dwp',",
+ " coverage_files = 'gcov',",
" linker_files = 'link',",
" strip_files = ':strip',",
" objcopy_files = 'objcopy',",
@@ -188,6 +190,7 @@ public class CcToolchainSuiteTest extends BuildViewTestCase {
" cpu = 'cpu',",
" compiler_files = 'compile',",
" dwp_files = 'dwp',",
+ " coverage_files = 'gcov',",
" linker_files = 'link',",
" strip_files = ':strip',",
" objcopy_files = 'objcopy',",
@@ -203,6 +206,7 @@ public class CcToolchainSuiteTest extends BuildViewTestCase {
" cpu = 'cpu',",
" compiler_files = 'compile',",
" dwp_files = 'dwp',",
+ " coverage_files = 'gcov',",
" linker_files = 'link',",
" strip_files = ':strip',",
" objcopy_files = 'objcopy',",
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainTest.java
index 9a8bf4b1e2..43aa2a4700 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainTest.java
@@ -36,6 +36,7 @@ public class CcToolchainTest extends BuildViewTestCase {
" cpu = 'cherry',",
" compiler_files = 'compile-a',",
" dwp_files = 'dwp-a',",
+ " coverage_files = 'gcov-a',",
" linker_files = 'link-a',",
" strip_files = 'strip-a',",
" objcopy_files = 'objcopy-a',",
@@ -62,6 +63,7 @@ public class CcToolchainTest extends BuildViewTestCase {
" cpu = 'cherry',",
" compiler_files = 'compile-cherry',",
" dwp_files = 'dwp-cherry',",
+ " coverage_files = 'gcov-cherry',",
" linker_files = 'link-cherry',",
" strip_files = ':every-file',",
" objcopy_files = 'objcopy-cherry',",
@@ -96,6 +98,7 @@ public class CcToolchainTest extends BuildViewTestCase {
" cpu = 'cherry',",
" compiler_files = 'compile-cherry',",
" dwp_files = 'dwp-cherry',",
+ " coverage_files = 'gcov-cherry',",
" linker_files = 'link-cherry',",
" strip_files = ':every-file',",
" objcopy_files = 'objcopy-cherry',",