Fix a path name error in cc_common.link.
Currently, if cc_common.link is called for a library "foo/bar/libbaz.so", the output is "foo/bar/foo/bar/libbaz.so". This is because Blaze mishandles the subpath of the file during linking.
This change fixes this issue with doubled subdirectories, while preserving the intended effect of that path-handling code.
@@ -900,13 +900,16 @@ public final class CcLinkingHelper {
CppHelper.getArtifactNameForCategory(
ruleErrorConsumer, ccToolchain, ArtifactCategory.PIC_FILE, maybePicName);
}
- String linkedName =
- maybePicName
- + (linkTargetType == LinkTargetType.NODEPS_DYNAMIC_LIBRARY ? linkedDLLNameSuffix : "");
+
+ String linkedName = maybePicName;
+ if (linkTargetType.equals(LinkTargetType.NODEPS_DYNAMIC_LIBRARY)) {
+ linkedName += linkedDLLNameSuffix;
+ }
linkedName =
CppHelper.getArtifactNameForCategory(
ruleErrorConsumer, ccToolchain, linkTargetType.getLinkerOutput(), linkedName);
+ PathFragment artifactFragment = PathFragment.create(linkedName);
ArtifactRoot artifactRoot = configuration.getBinDirectory(label.getRepository());
if (linkTargetType.equals(LinkTargetType.OBJC_FULLY_LINKED_ARCHIVE)) {
// TODO(blaze-team): This unfortunate editing of the name is here bedcause Objective-C rules
@@ -914,15 +917,13 @@ public final class CcLinkingHelper {
// toolchain says with getArtifactNameForCategory.
// This can be fixed either when implicit outputs are removed from objc_library by keeping the
// lib prefix, or by editing the toolchain not to add it.
- Preconditions.checkState(linkedName.startsWith("lib"));
- linkedName = linkedName.substring(3);
+ Preconditions.checkState(artifactFragment.getBaseName().startsWith("lib"));
+ artifactFragment = artifactFragment.replaceName(artifactFragment.getBaseName().substring(3));
artifactRoot =
((RuleContext) actionConstructionContext).getRule().outputsToBindir()
? configuration.getBinDirectory(label.getRepository())
: configuration.getGenfilesDirectory(label.getRepository());
}
- PathFragment artifactFragment =
- PathFragment.create(label.getName()).getParentDirectory().getRelative(linkedName);
return CppHelper.getLinkedArtifact(
label,
