aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java
index beee64a4b2..8d671e39f8 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java
@@ -136,17 +136,28 @@ public abstract class CcLibrary implements RuleConfiguredTargetFactory {
helper.addLinkstamps(ruleContext.getPrerequisites("linkstamp", Mode.TARGET));
}
- PathFragment soImplFilename = null;
+ Artifact soImplArtifact = null;
+ boolean createDynamicLibrary =
+ !linkStatic && appearsToHaveObjectFiles(ruleContext.attributes());
if (ruleContext.getRule().isAttrDefined("outs", Type.STRING_LIST)) {
List<String> outs = ruleContext.attributes().get("outs", Type.STRING_LIST);
if (outs.size() > 1) {
ruleContext.attributeError("outs", "must be a singleton list");
} else if (outs.size() == 1) {
- soImplFilename = CppHelper.getLinkedFilename(ruleContext, LinkTargetType.DYNAMIC_LIBRARY);
+ PathFragment soImplFilename = new PathFragment(ruleContext.getLabel().getName());
+ if (LinkTargetType.DYNAMIC_LIBRARY != LinkTargetType.EXECUTABLE) {
+ soImplFilename = soImplFilename.replaceName(
+ "lib" + soImplFilename.getBaseName() + LinkTargetType.DYNAMIC_LIBRARY.getExtension());
+ }
soImplFilename = soImplFilename.replaceName(outs.get(0));
if (!soImplFilename.getPathString().endsWith(".so")) { // Sanity check.
ruleContext.attributeError("outs", "file name must end in '.so'");
}
+
+ if (createDynamicLibrary) {
+ soImplArtifact = ruleContext.getPackageRelativeArtifact(
+ soImplFilename, ruleContext.getConfiguration().getBinDirectory());
+ }
}
}
@@ -166,10 +177,8 @@ public abstract class CcLibrary implements RuleConfiguredTargetFactory {
+ "Did you mean to use 'linkstatic=1' instead?");
}
- boolean createDynamicLibrary =
- !linkStatic && appearsToHaveObjectFiles(ruleContext.attributes());
helper.setCreateDynamicLibrary(createDynamicLibrary);
- helper.setDynamicLibraryPath(soImplFilename);
+ helper.setDynamicLibrary(soImplArtifact);
// If "srcs" is configurable, the .so output is always declared because the logic that
// determines implicit outs doesn't know which value of "srcs" will ultimately get chosen. Here,
@@ -177,9 +186,8 @@ public abstract class CcLibrary implements RuleConfiguredTargetFactory {
// .so with. If that's the case, register a fake generating action to prevent a "no generating
// action for this artifact" error.
if (!createDynamicLibrary && ruleContext.attributes().isConfigurable("srcs", Type.LABEL_LIST)) {
- PathFragment solib = CppHelper.getLinkedFilename(ruleContext, LinkTargetType.DYNAMIC_LIBRARY);
- Artifact solibArtifact = ruleContext.getAnalysisEnvironment()
- .getDerivedArtifact(solib, ruleContext.getBinOrGenfilesDirectory());
+ Artifact solibArtifact = CppHelper.getLinkedArtifact(
+ ruleContext, LinkTargetType.DYNAMIC_LIBRARY);
ruleContext.registerAction(new FailAction(ruleContext.getActionOwner(),
ImmutableList.of(solibArtifact), "configurable \"srcs\" triggers an implicit .so output "
+ "even though there are no sources to compile in this configuration"));