Skip to content

Commit

Permalink
Add --apple_enable_auto_dsym_dbg flag
Browse files Browse the repository at this point in the history
This new flag can be used to forcibly enable dSYM generation for dbg
apple builds, which is especially useful for debugging in remote
builds, which may require the use of dSYMs.

RELNOTES: Added --apple_enable_auto_dsym_dbg flag.
PiperOrigin-RevId: 198577541
  • Loading branch information
Googler authored and Copybara-Service committed May 30, 2018
1 parent ab259ee commit 547b43e
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ public class ObjcCommandLineOptions extends FragmentOptions {
)
public boolean appleGenerateDsym;

@Option(
name = "apple_enable_auto_dsym_dbg",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.OUTPUT_SELECTION,
effectTags = {OptionEffectTag.AFFECTS_OUTPUTS, OptionEffectTag.ACTION_COMMAND_LINES},
help = "Whether to force enable generating debug symbol(.dSYM) file(s) for dbg builds.")
public boolean appleEnableAutoDsymDbg;

@Option(
name = "ios_signing_cert_name",
defaultValue = "null",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ public class ObjcConfiguration extends BuildConfiguration.Fragment {
Preconditions.checkNotNull(objcOptions.tvosSimulatorDevice, "tvosSimulatorDevice");
this.tvosSimulatorVersion =
Preconditions.checkNotNull(objcOptions.tvosSimulatorVersion, "tvosSimulatorVersion");
this.generateDsym = objcOptions.appleGenerateDsym;
this.generateLinkmap = objcOptions.generateLinkmap;
this.runMemleaks = objcOptions.runMemleaks;
this.copts = ImmutableList.copyOf(objcOptions.copts);
this.compilationMode = Preconditions.checkNotNull(options.compilationMode, "compilationMode");
this.generateDsym =
objcOptions.appleGenerateDsym
|| (objcOptions.appleEnableAutoDsymDbg && this.compilationMode == CompilationMode.DBG);
this.fastbuildOptions = ImmutableList.copyOf(objcOptions.fastbuildOptions);
this.enableBinaryStripping = objcOptions.enableBinaryStripping;
this.moduleMapsEnabled = objcOptions.enableModuleMaps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
import com.google.devtools.build.lib.analysis.actions.SymlinkAction;
import com.google.devtools.build.lib.analysis.config.CompilationMode;
import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider;
import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.rules.apple.AppleConfiguration.ConfigurationDistinguisher;
Expand Down Expand Up @@ -596,21 +597,21 @@ public void testBundleLoaderCantBeSetWithoutBundleBinaryType() throws Exception
")");
}

/** Returns the bcsymbolmap artifact for given architecture. */
protected Artifact bitcodeSymbol(String arch) throws Exception {
/** Returns the bcsymbolmap artifact for given architecture and compilation mode. */
protected Artifact bitcodeSymbol(String arch, CompilationMode mode) throws Exception {
SpawnAction lipoAction = (SpawnAction) lipoBinAction("//examples/apple_skylark:bin");

String bin =
configurationBin(arch, ConfigurationDistinguisher.APPLEBIN_IOS)
configurationBin(arch, ConfigurationDistinguisher.APPLEBIN_IOS, null, mode)
+ "examples/apple_skylark/bin_bin";
Artifact binArtifact = getFirstArtifactEndingWith(lipoAction.getInputs(), bin);
CommandAction linkAction = (CommandAction) getGeneratingAction(binArtifact);
return getFirstArtifactEndingWith(linkAction.getOutputs(), "bcsymbolmap");
}

/** Returns the path to the dSYM binary artifact for given architecture. */
protected String dsymBinaryPath(String arch) throws Exception {
return configurationBin(arch, ConfigurationDistinguisher.APPLEBIN_IOS)
/** Returns the path to the dSYM binary artifact for given architecture and compilation mode. */
protected String dsymBinaryPath(String arch, CompilationMode mode) throws Exception {
return configurationBin(arch, ConfigurationDistinguisher.APPLEBIN_IOS, null, mode)
+ "examples/apple_skylark/bin.app.dSYM/Contents/Resources/DWARF/bin_bin";
}

Expand Down Expand Up @@ -1192,22 +1193,26 @@ public void testPlatformTypeIsConfigurable() throws Exception {
}

private void checkAppleDebugSymbolProvider_DsymEntries(
SkylarkDict<String, SkylarkDict<String, Artifact>> outputMap) throws Exception {
SkylarkDict<String, SkylarkDict<String, Artifact>> outputMap, CompilationMode compilationMode)
throws Exception {
assertThat(outputMap).containsKey("arm64");
assertThat(outputMap).containsKey("armv7");

Map<String, Artifact> arm64 = outputMap.get("arm64");
assertThat(arm64).containsEntry("bitcode_symbols", bitcodeSymbol("arm64"));
assertThat(arm64.get("dsym_binary").getExecPathString()).isEqualTo(dsymBinaryPath("arm64"));
assertThat(arm64).containsEntry("bitcode_symbols", bitcodeSymbol("arm64", compilationMode));
String expectedArm64Path = dsymBinaryPath("arm64", compilationMode);
assertThat(arm64.get("dsym_binary").getExecPathString()).isEqualTo(expectedArm64Path);

Map<String, Artifact> armv7 = outputMap.get("armv7");
assertThat(armv7).containsEntry("bitcode_symbols", bitcodeSymbol("armv7"));
assertThat(armv7.get("dsym_binary").getExecPathString()).isEqualTo(dsymBinaryPath("armv7"));
assertThat(armv7).containsEntry("bitcode_symbols", bitcodeSymbol("armv7", compilationMode));
String expectedArmv7Path = dsymBinaryPath("armv7", compilationMode);
assertThat(armv7.get("dsym_binary").getExecPathString()).isEqualTo(expectedArmv7Path);

Map<String, Artifact> x8664 = outputMap.get("x86_64");
// Simulator build has bitcode disabled.
assertThat(x8664).doesNotContainKey("bitcode_symbols");
assertThat(x8664.get("dsym_binary").getExecPathString()).isEqualTo(dsymBinaryPath("x86_64"));
String expectedx8664Path = dsymBinaryPath("x86_64", compilationMode);
assertThat(x8664.get("dsym_binary").getExecPathString()).isEqualTo(expectedx8664Path);
}

private void checkAppleDebugSymbolProvider_LinkMapEntries(
Expand All @@ -1229,7 +1234,20 @@ private void checkAppleDebugSymbolProvider_LinkMapEntries(
public void testAppleDebugSymbolProviderWithDsymsExposedToSkylark() throws Exception {
useConfiguration(
"--apple_bitcode=embedded", "--apple_generate_dsym", "--ios_multi_cpus=armv7,arm64,x86_64");
checkAppleDebugSymbolProvider_DsymEntries(generateAppleDebugOutputsSkylarkProviderMap());
checkAppleDebugSymbolProvider_DsymEntries(
generateAppleDebugOutputsSkylarkProviderMap(), CompilationMode.FASTBUILD);
}

@Test
public void testAppleDebugSymbolProviderWithAutoDsymDbgAndDsymsExposedToSkylark()
throws Exception {
useConfiguration(
"--apple_bitcode=embedded",
"--compilation_mode=dbg",
"--apple_enable_auto_dsym_dbg",
"--ios_multi_cpus=armv7,arm64,x86_64");
checkAppleDebugSymbolProvider_DsymEntries(
generateAppleDebugOutputsSkylarkProviderMap(), CompilationMode.DBG);
}

@Test
Expand All @@ -1251,7 +1269,7 @@ public void testAppleDebugSymbolProviderWithDsymsAndLinkMapsExposedToSkylark() t

SkylarkDict<String, SkylarkDict<String, Artifact>> outputMap =
generateAppleDebugOutputsSkylarkProviderMap();
checkAppleDebugSymbolProvider_DsymEntries(outputMap);
checkAppleDebugSymbolProvider_DsymEntries(outputMap, CompilationMode.FASTBUILD);
checkAppleDebugSymbolProvider_LinkMapEntries(outputMap);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ public void testMultiarchCcDep() throws Exception {
"--crosstool_top=//tools/osx/crosstool:crosstool");

CommandAction action = (CommandAction) lipoLibAction("//package:test");
String i386Prefix = configurationBin("i386", ConfigurationDistinguisher.APPLEBIN_IOS, null);
String x8664Prefix = configurationBin("x86_64", ConfigurationDistinguisher.APPLEBIN_IOS, null);
String i386Prefix = configurationBin("i386", ConfigurationDistinguisher.APPLEBIN_IOS);
String x8664Prefix = configurationBin("x86_64", ConfigurationDistinguisher.APPLEBIN_IOS);

CommandAction i386BinAction =
(CommandAction)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void testToolchainSelectionCcDepDefault() throws Exception {

Action lipoAction = actionProducingArtifact("//a:bin", "_lipobin");
String x8664Bin =
configurationBin("x86_64", ConfigurationDistinguisher.APPLEBIN_IOS, null) + "a/bin_bin";
configurationBin("x86_64", ConfigurationDistinguisher.APPLEBIN_IOS) + "a/bin_bin";
Artifact binArtifact = getFirstArtifactEndingWith(lipoAction.getInputs(), x8664Bin);
CppLinkAction linkAction = (CppLinkAction) getGeneratingAction(binArtifact);
CppLinkAction ccArchiveAction =
Expand All @@ -93,7 +93,7 @@ public void testToolchainSelectionCcDepDevice() throws Exception {
.write();
Action lipoAction = actionProducingArtifact("//a:bin", "_lipobin");
String armv7Bin =
configurationBin("armv7", ConfigurationDistinguisher.APPLEBIN_IOS, null) + "a/bin_bin";
configurationBin("armv7", ConfigurationDistinguisher.APPLEBIN_IOS) + "a/bin_bin";
Artifact binArtifact = getFirstArtifactEndingWith(lipoAction.getInputs(), armv7Bin);
CppLinkAction linkAction = (CppLinkAction) getGeneratingAction(binArtifact);
CppLinkAction ccArchiveAction =
Expand All @@ -118,8 +118,7 @@ public void testToolchainSelectionMultiArchIos() throws Exception {
.write();
Action lipoAction = actionProducingArtifact("//a:bin", "_lipobin");
String armv64Bin =
configurationBin("arm64", ConfigurationDistinguisher.APPLEBIN_IOS, null)
+ "a/bin_bin";
configurationBin("arm64", ConfigurationDistinguisher.APPLEBIN_IOS) + "a/bin_bin";
Artifact binArtifact = getFirstArtifactEndingWith(lipoAction.getInputs(), armv64Bin);
CppLinkAction linkAction = (CppLinkAction) getGeneratingAction(binArtifact);
CppLinkAction objcLibArchiveAction = (CppLinkAction) getGeneratingAction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,25 +129,28 @@ public enum CodeCoverageMode {
*/
protected String configurationBin(
String arch, ConfigurationDistinguisher configurationDistinguisher) {
return configurationBin(arch, configurationDistinguisher, null);
return configurationBin(arch, configurationDistinguisher, null, CompilationMode.FASTBUILD);
}

/**
* Returns the bin dir for artifacts built for a given Apple architecture and minimum OS
* version (as set by a configuration transition) and configuration distinguisher but the global
* default for {@code --cpu}.
* Returns the bin dir for artifacts built for a given Apple architecture and minimum OS version
* (as set by a configuration transition) and configuration distinguisher but the global default
* for {@code --cpu}.
*
* @param arch the given Apple architecture which artifacts are built under this configuration.
* Note this will likely be different than the value of {@code --cpu}.
* @param configurationDistinguisher the configuration distinguisher used to describe the
* a configuration transition
* @param minOsVersion the minimum os version for which to compile artifacts in the
* configuration
* @param configurationDistinguisher the configuration distinguisher used to describe the a
* configuration transition
* @param minOsVersion the minimum os version for which to compile artifacts in the configuration
* @param compilationMode the compilation mode used during the build
*/
protected String configurationBin(
String arch, ConfigurationDistinguisher configurationDistinguisher,
DottedVersion minOsVersion) {
return configurationDir(arch, configurationDistinguisher, minOsVersion) + "bin/";
String arch,
ConfigurationDistinguisher configurationDistinguisher,
DottedVersion minOsVersion,
CompilationMode compilationMode) {
return configurationDir(arch, configurationDistinguisher, minOsVersion, compilationMode)
+ "bin/";
}

/**
Expand All @@ -165,10 +168,12 @@ protected String configurationBin(
protected String configurationGenfiles(
String arch, ConfigurationDistinguisher configurationDistinguisher,
DottedVersion minOsVersion) {
return configurationDir(arch, configurationDistinguisher, minOsVersion)
+ getTargetConfiguration().getGenfilesDirectory(RepositoryName.MAIN)
.getExecPath().getBaseName();

return configurationDir(
arch, configurationDistinguisher, minOsVersion, CompilationMode.FASTBUILD)
+ getTargetConfiguration()
.getGenfilesDirectory(RepositoryName.MAIN)
.getExecPath()
.getBaseName();
}

private static String toolExecutable(String toolSrcPath) {
Expand All @@ -177,26 +182,31 @@ private static String toolExecutable(String toolSrcPath) {
}

private String configurationDir(
String arch, ConfigurationDistinguisher configurationDistinguisher,
DottedVersion minOsVersion) {
String arch,
ConfigurationDistinguisher configurationDistinguisher,
DottedVersion minOsVersion,
CompilationMode compilationMode) {
String minOsSegment = minOsVersion == null ? "" : "-min" + minOsVersion;
String modeSegment = compilationModeFlag(compilationMode);
switch (configurationDistinguisher) {
case UNKNOWN:
return String.format("%s-out/ios_%s-fastbuild/", TestConstants.PRODUCT_NAME, arch);
return String.format("%s-out/ios_%s-%s/", TestConstants.PRODUCT_NAME, arch, modeSegment);
case APPLEBIN_IOS:
return String.format(
"%1$s-out/ios-%2$s%4$s-%3$s-ios_%2$s-fastbuild/",
"%1$s-out/ios-%2$s%4$s-%3$s-ios_%2$s-%5$s/",
TestConstants.PRODUCT_NAME,
arch,
configurationDistinguisher.toString().toLowerCase(Locale.US),
minOsSegment);
minOsSegment,
modeSegment);
case APPLEBIN_WATCHOS:
return String.format(
"%1$s-out/watchos-%2$s%4$s-%3$s-watchos_%2$s-fastbuild/",
"%1$s-out/watchos-%2$s%4$s-%3$s-watchos_%2$s-%5$s/",
TestConstants.PRODUCT_NAME,
arch,
configurationDistinguisher.toString().toLowerCase(Locale.US),
minOsSegment);
minOsSegment,
modeSegment);
default:
throw new AssertionError();
}
Expand Down

0 comments on commit 547b43e

Please sign in to comment.