Skip to content

Commit

Permalink
Make sure default Linux artifacts have an associated action, even whe…
Browse files Browse the repository at this point in the history
…n artifact names are altered.

This is a FailAction with a message giving the corresponding file actually produced by the toolchain, and ensures that any implicit Linux-oriented outputs have a corresponding action.

RELNOTES: None.
PiperOrigin-RevId: 251297537
  • Loading branch information
Googler authored and copybara-github committed Jun 3, 2019
1 parent 4ca768e commit aff189a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.actions.ActionRegistry;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.FailAction;
import com.google.devtools.build.lib.analysis.FileProvider;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
Expand Down Expand Up @@ -871,32 +870,13 @@ private Artifact getLinkedArtifact(LinkTargetType linkTargetType) throws RuleErr
PathFragment artifactFragment =
PathFragment.create(label.getName()).getParentDirectory().getRelative(linkedName);

Artifact result =
actionConstructionContext.getPackageRelativeArtifact(
artifactFragment,
configuration.getBinDirectory(label.getPackageIdentifier().getRepository()));

// If the linked artifact is not the linux default, then a FailAction is generated for the
// linux default to satisfy the requirement of the implicit output.
// TODO(b/30132703): Remove the implicit outputs of cc_library.
Artifact linuxDefault =
CppHelper.getLinuxLinkedArtifact(
label,
actionConstructionContext,
configuration,
linkTargetType,
linkedArtifactNameSuffix);
if (!result.equals(linuxDefault)) {
actionConstructionContext.registerAction(
new FailAction(
actionConstructionContext.getActionOwner(),
ImmutableList.of(linuxDefault),
String.format(
"the given toolchain supports creation of %s instead of %s",
linuxDefault.getExecPathString(), result.getExecPathString())));
}

return result;
return CppHelper.getLinkedArtifact(
label,
actionConstructionContext,
configuration,
linkTargetType,
linkedArtifactNameSuffix,
artifactFragment);
}

private static List<LinkerInputs.LibraryToLink> convertLibraryToLinkListToLinkerInputList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.google.devtools.build.lib.actions.ActionOwner;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.Artifact.SpecialArtifact;
import com.google.devtools.build.lib.actions.FailAction;
import com.google.devtools.build.lib.actions.MiddlemanFactory;
import com.google.devtools.build.lib.actions.ParamFileInfo;
import com.google.devtools.build.lib.actions.ParameterFile;
Expand Down Expand Up @@ -441,8 +442,38 @@ public static Artifact getLinkedArtifact(
ruleContext.throwWithRuleError("Cannot get linked artifact name: " + e.getMessage());
}

return ruleContext.getPackageRelativeArtifact(
name, config.getBinDirectory(ruleContext.getRule().getRepository()));
return getLinkedArtifact(
ruleContext.getLabel(), ruleContext, config, linkType, linkedArtifactNameSuffix, name);
}

public static Artifact getLinkedArtifact(
Label label,
ActionConstructionContext actionConstructionContext,
BuildConfiguration config,
LinkTargetType linkType,
String linkedArtifactNameSuffix,
PathFragment name) {
Artifact result =
actionConstructionContext.getPackageRelativeArtifact(
name, config.getBinDirectory(label.getPackageIdentifier().getRepository()));

// If the linked artifact is not the linux default, then a FailAction is generated for said
// linux default to satisfy the requirements of any implicit outputs.
// TODO(b/30132703): Remove the implicit outputs of cc_library.
Artifact linuxDefault =
getLinuxLinkedArtifact(
label, actionConstructionContext, config, linkType, linkedArtifactNameSuffix);
if (!result.equals(linuxDefault)) {
actionConstructionContext.registerAction(
new FailAction(
actionConstructionContext.getActionOwner(),
ImmutableList.of(linuxDefault),
String.format(
"the given toolchain supports creation of %s instead of %s",
result.getExecPathString(), linuxDefault.getExecPathString())));
}

return result;
}

public static Artifact getLinuxLinkedArtifact(
Expand Down

0 comments on commit aff189a

Please sign in to comment.