Skip to content

Commit

Permalink
Finish implementing binary stripping for --experimental_objc_crosstoo…
Browse files Browse the repository at this point in the history
…l=all.

This involves:

(1) Adding the -g compiler flag
(2) If the target is a test, do not add linker flags.
(3) Move relevant tests to crosstool case.

--
PiperOrigin-RevId: 151055080
MOS_MIGRATED_REVID=151055080
  • Loading branch information
calpeyser authored and hermione521 committed Mar 24, 2017
1 parent d6052e3 commit ea862ba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.packages.BuildType;
import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
import com.google.devtools.build.lib.packages.TargetUtils;
import com.google.devtools.build.lib.rules.apple.AppleConfiguration;
import com.google.devtools.build.lib.rules.cpp.CcLibraryHelper;
import com.google.devtools.build.lib.rules.cpp.CcLibraryHelper.Info;
Expand Down Expand Up @@ -79,6 +80,15 @@ public class CrosstoolCompilationSupport extends CompilationSupport {
private static final String LLVM_COVERAGE_MAP_FORMAT = "llvm_coverage_map_format";
/** Produce artifacts for coverage in gcc coverage mapping format. */
private static final String GCC_COVERAGE_MAP_FORMAT = "gcc_coverage_map_format";
/**
* Enabled if this target's rule is not a test rule. Binary stripping should not be applied in
* the link step. TODO(b/36562173): Replace this behavior with a condition on bundle creation.
*
* <p>Note that the crosstool does not support feature negation in FlagSet.with_feature, which
* is the mechanism used to condition linker arguments here. Therefore, we expose
* "is_not_test_target" instead of the more intuitive "is_test_target".
*/
private static final String IS_NOT_TEST_TARGET_FEATURE_NAME = "is_not_test_target";

private static final Iterable<String> ACTIVATED_ACTIONS =
ImmutableList.of(
Expand Down Expand Up @@ -200,6 +210,12 @@ protected CompilationSupport registerFullyLinkAction(
return this;
}

private StrippingType getStrippingType(ExtraLinkArgs extraLinkArgs) {
return Iterables.contains(extraLinkArgs, "-dynamiclib")
? StrippingType.DYNAMIC_LIB
: StrippingType.DEFAULT;
}

@Override
CompilationSupport registerLinkActions(
ObjcProvider objcProvider,
Expand Down Expand Up @@ -267,7 +283,7 @@ CompilationSupport registerLinkActions(
ruleContext.registerAction(executableLinkAction);

if (objcConfiguration.shouldStripBinary()) {
registerBinaryStripAction(binaryToLink, StrippingType.DEFAULT);
registerBinaryStripAction(binaryToLink, getStrippingType(extraLinkArgs));
}

return this;
Expand Down Expand Up @@ -393,8 +409,11 @@ private static FeatureConfiguration getFeatureConfiguration(RuleContext ruleCont
} else {
activatedCrosstoolSelectables.add(GCC_COVERAGE_MAP_FORMAT);
}
activatedCrosstoolSelectables.addAll(ruleContext.getFeatures());
if (!TargetUtils.isTestRule(ruleContext.getRule())) {
activatedCrosstoolSelectables.add(IS_NOT_TEST_TARGET_FEATURE_NAME);
}

activatedCrosstoolSelectables.addAll(ruleContext.getFeatures());
return configuration
.getFragment(CppConfiguration.class)
.getFeatures()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,8 @@ private CommandLine linkCommandLine(
// Do not perform code stripping on tests because XCTest binary is linked not as an executable
// but as a bundle without any entry point.
boolean isTestTarget = TargetUtils.isTestRule(ruleContext.getRule());
// TODO(b/36562173): Replace the "!isTestTarget" condition with the presence of "-bundle" in
// the command line.
if (objcConfiguration.shouldStripBinary() && !isTestTarget) {
commandLine.add("-dead_strip").add("-no_dead_strip_inits_and_terms");
}
Expand Down

0 comments on commit ea862ba

Please sign in to comment.