aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar Cal Peyser <cpeyser@google.com>2017-02-24 15:20:56 +0000
committerGravatar Yue Gan <yueg@google.com>2017-02-27 15:04:49 +0000
commitdacc16dde31498f35d124ff632f2d710a0de1111 (patch)
tree3c825bb5f0a02b5d3ca3e4081501a5c0e49f767c /src/main/java/com/google/devtools/build
parentc87cffae61e4e39f58a2109f32a06ed0924438b3 (diff)
CrosstoolCompilationSupport registers a binary strip action when binary
stripping is enabled. -- PiperOrigin-RevId: 148458258 MOS_MIGRATED_REVID=148458258
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java47
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/CrosstoolCompilationSupport.java6
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/LegacyCompilationSupport.java41
3 files changed, 57 insertions, 37 deletions
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 df7dc609f4..9911481ca3 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
@@ -30,6 +30,7 @@ import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.HEADERS;
import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.NON_ARC_SRCS_TYPE;
import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.PRECOMPILED_SRCS_TYPE;
import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.SRCS_TYPE;
+import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.STRIP;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import com.google.common.annotations.VisibleForTesting;
@@ -53,6 +54,7 @@ import com.google.devtools.build.lib.analysis.FilesToRunProvider;
import com.google.devtools.build.lib.analysis.PrerequisiteArtifacts;
import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
import com.google.devtools.build.lib.analysis.RuleContext;
+import com.google.devtools.build.lib.analysis.actions.CommandLine;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
import com.google.devtools.build.lib.analysis.actions.ParameterFileWriteAction;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
@@ -995,6 +997,51 @@ public abstract class CompilationSupport {
: intermediateArtifacts.strippedSingleArchitectureBinary();
}
+ private static CommandLine symbolStripCommandLine(
+ Iterable<String> extraFlags, Artifact unstrippedArtifact, Artifact strippedArtifact) {
+ return CustomCommandLine.builder()
+ .add(STRIP)
+ .add(extraFlags)
+ .addExecPath("-o", strippedArtifact)
+ .addPath(unstrippedArtifact.getExecPath())
+ .build();
+ }
+
+ /** Signals if stripping should include options for dynamic libraries. */
+ protected enum StrippingType {
+ DEFAULT, DYNAMIC_LIB
+ }
+
+ /**
+ * Registers an action that uses the 'strip' tool to perform binary stripping on the given binary
+ * subject to the given {@link StrippingType}.
+ */
+ protected void registerBinaryStripAction(Artifact binaryToLink, StrippingType strippingType) {
+ final Iterable<String> stripArgs;
+ if (TargetUtils.isTestRule(ruleContext.getRule())) {
+ // For test targets, only debug symbols are stripped off, since /usr/bin/strip is not able
+ // to strip off all symbols in XCTest bundle.
+ stripArgs = ImmutableList.of("-S");
+ } else if (strippingType == StrippingType.DYNAMIC_LIB) {
+ // For dynamic libs must pass "-x" to strip only local symbols.
+ stripArgs = ImmutableList.of("-x");
+ } else {
+ stripArgs = ImmutableList.<String>of();
+ }
+
+ Artifact strippedBinary = intermediateArtifacts.strippedSingleArchitectureBinary();
+
+ ruleContext.registerAction(
+ ObjcRuleClasses.spawnAppleEnvActionBuilder(
+ appleConfiguration, appleConfiguration.getSingleArchPlatform())
+ .setMnemonic("ObjcBinarySymbolStrip")
+ .setExecutable(xcrunwrapper(ruleContext))
+ .setCommandLine(symbolStripCommandLine(stripArgs, binaryToLink, strippedBinary))
+ .addOutput(strippedBinary)
+ .addInput(binaryToLink)
+ .build(ruleContext));
+ }
+
private NestedSet<Artifact> getGcovForObjectiveCIfNeeded() {
if (ruleContext.getConfiguration().isCodeCoverageEnabled()
&& ruleContext.attributes().has(IosTest.OBJC_GCOV_ATTR, BuildType.LABEL)) {
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/CrosstoolCompilationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/CrosstoolCompilationSupport.java
index edaeb543c5..b4c693a92d 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/CrosstoolCompilationSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/CrosstoolCompilationSupport.java
@@ -254,7 +254,11 @@ public class CrosstoolCompilationSupport extends CompilationSupport {
.setFeatureConfiguration(getFeatureConfiguration(ruleContext, buildConfiguration))
.build();
ruleContext.registerAction(executableLinkAction);
-
+
+ if (objcConfiguration.shouldStripBinary()) {
+ registerBinaryStripAction(binaryToLink, StrippingType.DEFAULT);
+ }
+
return this;
}
private CcLibraryHelper createCcLibraryHelper(ObjcProvider objcProvider,
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/LegacyCompilationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/LegacyCompilationSupport.java
index 8a1c5778dd..3af3a1fe2b 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/LegacyCompilationSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/LegacyCompilationSupport.java
@@ -34,7 +34,6 @@ import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.HEADERS;
import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.NON_ARC_SRCS_TYPE;
import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.PRECOMPILED_SRCS_TYPE;
import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.SRCS_TYPE;
-import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.STRIP;
import com.google.common.base.Joiner;
import com.google.common.base.Optional;
@@ -590,8 +589,10 @@ public class LegacyCompilationSupport extends CompilationSupport {
return this;
}
- private boolean isDynamicLib(CommandLine commandLine) {
- return Iterables.contains(commandLine.arguments(), "-dynamiclib");
+ private StrippingType getStrippingType(CommandLine commandLine) {
+ return Iterables.contains(commandLine.arguments(), "-dynamiclib")
+ ? StrippingType.DYNAMIC_LIB
+ : StrippingType.DEFAULT;
}
private void registerLinkAction(
@@ -641,42 +642,10 @@ public class LegacyCompilationSupport extends CompilationSupport {
.build(ruleContext));
if (objcConfiguration.shouldStripBinary()) {
- final Iterable<String> stripArgs;
- if (TargetUtils.isTestRule(ruleContext.getRule())) {
- // For test targets, only debug symbols are stripped off, since /usr/bin/strip is not able
- // to strip off all symbols in XCTest bundle.
- stripArgs = ImmutableList.of("-S");
- } else if (isDynamicLib(commandLine)) {
- // For dynamic libs must pass "-x" to strip only local symbols.
- stripArgs = ImmutableList.of("-x");
- } else {
- stripArgs = ImmutableList.<String>of();
- }
-
- Artifact strippedBinary = intermediateArtifacts.strippedSingleArchitectureBinary();
-
- ruleContext.registerAction(
- ObjcRuleClasses.spawnAppleEnvActionBuilder(
- appleConfiguration, appleConfiguration.getSingleArchPlatform())
- .setMnemonic("ObjcBinarySymbolStrip")
- .setExecutable(xcrunwrapper(ruleContext))
- .setCommandLine(symbolStripCommandLine(stripArgs, binaryToLink, strippedBinary))
- .addOutput(strippedBinary)
- .addInput(binaryToLink)
- .build(ruleContext));
+ registerBinaryStripAction(binaryToLink, getStrippingType(commandLine));
}
}
- private static CommandLine symbolStripCommandLine(
- Iterable<String> extraFlags, Artifact unstrippedArtifact, Artifact strippedArtifact) {
- return CustomCommandLine.builder()
- .add(STRIP)
- .add(extraFlags)
- .addExecPath("-o", strippedArtifact)
- .addPath(unstrippedArtifact.getExecPath())
- .build();
- }
-
private CommandLine linkCommandLine(
ExtraLinkArgs extraLinkArgs,
ObjcProvider objcProvider,