aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
diff options
context:
space:
mode:
authorGravatar plf <plf@google.com>2018-01-12 08:20:57 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-01-12 08:26:39 -0800
commit849cec256c606db47dc179c788f937d7482087ae (patch)
treed18b7131493c353c78103c1f573868216b0d817b /src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
parent38f815c2c8a4bc4d6cf79d366d200e37fa0935f3 (diff)
C++: Only call link() in cc_binary when linkCompileOutputSeparately is true.
Also rename setLinkType() to setStaticLinkType() in CcLibraryHelper to make it clear that we are setting the specific linking type for the static library. This is an improved version of https://github.com/bazelbuild/bazel/commit/a705eaa9225ff8a03975c8cb49faa6b2899e398d which was rolled back due to a previous conflicting CL causing problems in the nightly. RELNOTES:none PiperOrigin-RevId: 181746447
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java25
1 files changed, 14 insertions, 11 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,