aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java25
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java10
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java2
5 files changed, 23 insertions, 18 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
index d5fb13f241..d72d44d015 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
@@ -223,12 +223,6 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory {
CppCompilationContext cppCompilationContext = compilationInfo.getCppCompilationContext();
CcCompilationOutputs ccCompilationOutputs = compilationInfo.getCcCompilationOutputs();
- CcLibraryHelper linkingHelper =
- new CcLibraryHelper(ruleContext, semantics, featureConfiguration, ccToolchain, fdoSupport)
- .fromCommon(common)
- .addDeps(ImmutableList.of(CppHelper.mallocForTarget(ruleContext)))
- .setFake(fake)
- .enableInterfaceSharedObjects();
List<String> linkopts = common.getLinkopts();
LinkStaticness linkStaticness =
getLinkStaticness(ruleContext, linkopts, cppConfiguration, ccToolchain);
@@ -249,9 +243,18 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory {
// [*] The only library link type is STATIC_LIBRARY. EXECUTABLE specifies a normal
// cc_binary output, while DYNAMIC_LIBRARY is a cc_binary rules that produces an
// output matching a shared object, for example cc_binary(name="foo.so", ...) on linux.
- linkingHelper.setLinkType(
- linkCompileOutputSeparately ? LinkTargetType.STATIC_LIBRARY : linkType);
- Info.LinkingInfo linkingInfo = linkingHelper.link(ccCompilationOutputs, cppCompilationContext);
+ CcLinkingOutputs ccLinkingOutputs = CcLinkingOutputs.EMPTY;
+ if (linkCompileOutputSeparately) {
+ CcLibraryHelper linkingHelper =
+ new CcLibraryHelper(ruleContext, semantics, featureConfiguration, ccToolchain, fdoSupport)
+ .fromCommon(common)
+ .addDeps(ImmutableList.of(CppHelper.mallocForTarget(ruleContext)))
+ .setFake(fake)
+ .enableInterfaceSharedObjects();
+ linkingHelper.setStaticLinkType(LinkTargetType.STATIC_LIBRARY);
+ ccLinkingOutputs =
+ linkingHelper.link(ccCompilationOutputs, cppCompilationContext).getCcLinkingOutputs();
+ }
CcLinkParams linkParams =
collectCcLinkParams(
@@ -268,7 +271,7 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory {
common,
precompiledFiles,
ccCompilationOutputs,
- linkingInfo.getCcLinkingOutputs(),
+ ccLinkingOutputs,
cppCompilationContext.getTransitiveCompilationPrerequisites(),
fake,
binary,
@@ -448,7 +451,7 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory {
ruleContext,
ccToolchain,
linkingOutputs,
- linkingInfo.getCcLinkingOutputs(),
+ ccLinkingOutputs,
cppCompilationContext,
linkStaticness,
filesToBuild,
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 3457fedfd0..963414ae86 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
@@ -151,7 +151,7 @@ public abstract class CcLibrary implements RuleConfiguredTargetFactory {
// between Bazel and Blaze.
.setGenerateLinkActionsIfEmpty(
ruleContext.getRule().getImplicitOutputsFunction() != ImplicitOutputsFunction.NONE)
- .setLinkType(staticLinkType)
+ .setStaticLinkType(staticLinkType)
.setNeverLink(neverLink)
.addLinkstamps(ruleContext.getPrerequisites("linkstamp", Mode.TARGET));
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java
index b67b6e1330..103a083024 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java
@@ -838,8 +838,8 @@ public final class CcLibraryHelper {
* by the linker even if they are not otherwise used. This is useful for libraries that register
* themselves somewhere during initialization.
*
- * <p>This only sets the link type (see {@link #setLinkType}), either to a static library or to
- * an alwayslink static library (blaze uses a different file extension to signal alwayslink to
+ * <p>This only sets the link type (see {@link #setStaticLinkType}), either to a static library or
+ * to an alwayslink static library (blaze uses a different file extension to signal alwayslink to
* downstream code).
*/
public CcLibraryHelper setAlwayslink(boolean alwayslink) {
@@ -853,8 +853,10 @@ public final class CcLibraryHelper {
* Directly set the link type. This can be used instead of {@link #setAlwayslink}. Setting
* anything other than a static link causes this class to skip the link action creation.
*/
- public CcLibraryHelper setLinkType(LinkTargetType linkType) {
- this.linkType = Preconditions.checkNotNull(linkType);
+ public CcLibraryHelper setStaticLinkType(LinkTargetType linkType) {
+ Preconditions.checkNotNull(linkType);
+ Preconditions.checkState(linkType.staticness() == Staticness.STATIC);
+ this.linkType = linkType;
return this;
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java
index 234b8fdf6f..ced5525ebb 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java
@@ -1298,7 +1298,7 @@ public final class CppModel {
CcCompilationOutputs ccOutputs, Iterable<Artifact> nonCodeLinkerInputs)
throws RuleErrorException, InterruptedException {
// For now only handle static links. Note that the dynamic library link below ignores linkType.
- // TODO(bazel-team): Either support non-static links or move this check to setLinkType().
+ // TODO(bazel-team): Either support non-static links or move this check to setStaticLinkType().
Preconditions.checkState(
linkType.staticness() == Staticness.STATIC, "can only handle static links");
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
index 80c8ddce93..d29a6b4b74 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
@@ -454,7 +454,7 @@ public class CompilationSupport {
.addVariableExtension(extensionBuilder.build());
if (linkType != null) {
- resultLink.setLinkType(linkType);
+ resultLink.setStaticLinkType(linkType);
}
if (linkActionInput != null) {