Skip to content

Commit

Permalink
Fix a path name error in cc_common.link.
Browse files Browse the repository at this point in the history
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.

PiperOrigin-RevId: 386909211
  • Loading branch information
Googler authored and copybara-github committed Jul 26, 2021
1 parent 0cf5366 commit b4cc44c
Showing 1 changed file with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -894,35 +894,36 @@ private CppLinkActionBuilder newLinkActionBuilder(
* not present. TODO(b/30393154): Assert that the given link action has an action_config.
*/
private Artifact getLinkedArtifact(LinkTargetType linkTargetType) throws RuleErrorException {
String maybePicName = label.getName() + linkedArtifactNameSuffix;
if (linkTargetType.picness() == Picness.PIC) {
maybePicName =
CppHelper.getArtifactNameForCategory(
ruleErrorConsumer, ccToolchain, ArtifactCategory.PIC_FILE, maybePicName);
}
String linkedName =
maybePicName
+ (linkTargetType == LinkTargetType.NODEPS_DYNAMIC_LIBRARY ? linkedDLLNameSuffix : "");
String maybePicName = label.getName() + linkedArtifactNameSuffix;
if (linkTargetType.picness() == Picness.PIC) {
maybePicName =
CppHelper.getArtifactNameForCategory(
ruleErrorConsumer, ccToolchain, ArtifactCategory.PIC_FILE, maybePicName);
}

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
// were creating this type of archive without the lib prefix, unlike what the objective-c
// 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,
Expand Down

0 comments on commit b4cc44c

Please sign in to comment.