aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java
index 11fcd4777a..f29682238e 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java
@@ -298,6 +298,7 @@ public final class CcLibraryHelper {
private final FeatureConfiguration featureConfiguration;
private CcToolchainProvider ccToolchain;
private final FdoSupportProvider fdoSupport;
+ private String linkedArtifactNameSuffix = "";
/**
* Creates a CcLibraryHelper.
@@ -817,6 +818,18 @@ public final class CcLibraryHelper {
return this;
}
+ /*
+ * Adds a suffix for paths of linked artifacts. Normally their paths are derived solely from rule
+ * labels. In the case of multiple callers (e.g., aspects) acting on a single rule, they may
+ * generate the same linked artifact and therefore lead to artifact conflicts. This method
+ * provides a way to avoid this artifact conflict by allowing different callers acting on the same
+ * rule to provide a suffix that will be used to scope their own linked artifacts.
+ */
+ public CcLibraryHelper setLinkedArtifactNameSuffix(String suffix) {
+ this.linkedArtifactNameSuffix = Preconditions.checkNotNull(suffix);
+ return this;
+ }
+
/**
* This adds the {@link CcNativeLibraryProvider} to the providers created by this class.
*/
@@ -1086,16 +1099,20 @@ public final class CcLibraryHelper {
if (ruleContext.attributes().get("alwayslink", Type.BOOLEAN)) {
archiveFile.add(
CppHelper.getLinuxLinkedArtifact(
- ruleContext, Link.LinkTargetType.ALWAYS_LINK_STATIC_LIBRARY));
+ ruleContext,
+ Link.LinkTargetType.ALWAYS_LINK_STATIC_LIBRARY,
+ linkedArtifactNameSuffix));
} else {
archiveFile.add(
- CppHelper.getLinuxLinkedArtifact(ruleContext, Link.LinkTargetType.STATIC_LIBRARY));
+ CppHelper.getLinuxLinkedArtifact(
+ ruleContext, Link.LinkTargetType.STATIC_LIBRARY, linkedArtifactNameSuffix));
}
if (!ruleContext.attributes().get("linkstatic", Type.BOOLEAN)
&& !ccOutputs.isEmpty()) {
dynamicLibrary.add(
- CppHelper.getLinuxLinkedArtifact(ruleContext, Link.LinkTargetType.DYNAMIC_LIBRARY));
+ CppHelper.getLinuxLinkedArtifact(
+ ruleContext, Link.LinkTargetType.DYNAMIC_LIBRARY, linkedArtifactNameSuffix));
}
outputGroups.put("archive", archiveFile.build());
@@ -1122,7 +1139,8 @@ public final class CcLibraryHelper {
.setDynamicLibrary(dynamicLibrary)
.addLinkopts(linkopts)
.setFeatureConfiguration(featureConfiguration)
- .addVariablesExtension(variablesExtensions);
+ .addVariablesExtension(variablesExtensions)
+ .setLinkedArtifactNameSuffix(linkedArtifactNameSuffix);
}
@Immutable