use of com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.ExpansionException in project bazel by bazelbuild.
the class CppModel method getLinkedArtifact.
/**
* Returns the linked artifact resulting from a linking of the given type. Consults the feature
* configuration to obtain an action_config that provides the artifact. If the feature
* configuration provides no artifact, uses a default.
*
* <p>We cannot assume that the feature configuration contains an action_config for the link
* action, because the linux link action depends on hardcoded values in
* LinkCommandLine.getRawLinkArgv(), which are applied on the condition that an action_config is
* not present.
* TODO(b/30393154): Assert that the given link action has an action_config.
*
* @throws RuleErrorException
*/
private Artifact getLinkedArtifact(LinkTargetType linkTargetType) throws RuleErrorException {
Artifact result = null;
Artifact linuxDefault = CppHelper.getLinuxLinkedArtifact(ruleContext, configuration, linkTargetType, linkedArtifactNameSuffix);
try {
String maybePicName = ruleContext.getLabel().getName() + linkedArtifactNameSuffix;
if (linkTargetType.picness() == Picness.PIC) {
maybePicName = CppHelper.getArtifactNameForCategory(ruleContext, ccToolchain, ArtifactCategory.PIC_FILE, maybePicName);
}
String linkedName = CppHelper.getArtifactNameForCategory(ruleContext, ccToolchain, linkTargetType.getLinkerOutput(), maybePicName);
PathFragment artifactFragment = new PathFragment(ruleContext.getLabel().getName()).getParentDirectory().getRelative(linkedName);
result = ruleContext.getPackageRelativeArtifact(artifactFragment, configuration.getBinDirectory(ruleContext.getRule().getRepository()));
} catch (ExpansionException e) {
ruleContext.throwWithRuleError(e.getMessage());
}
// TODO(b/30132703): Remove the implicit outputs of cc_library.
if (!result.equals(linuxDefault)) {
ruleContext.registerAction(new FailAction(ruleContext.getActionOwner(), ImmutableList.of(linuxDefault), String.format("the given toolchain supports creation of %s instead of %s", linuxDefault.getExecPathString(), result.getExecPathString())));
}
return result;
}
Aggregations