aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2016-04-01 16:29:41 +0000
committerGravatar Klaus Aehlig <aehlig@google.com>2016-04-01 18:25:54 +0000
commitb3e5a63bf868d5efe349ef01928b22fb8b6751a4 (patch)
tree9dd4421d71a4b17cd5adb92a6274d30ef13b2000 /src/main
parent6980f84690a3419d1a49016e2a34c783a1064319 (diff)
*_test rules now return an .xctest.dSYM bundle.
-- MOS_MIGRATED_REVID=118786316
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/BinaryLinkingTargetFactory.java21
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java126
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/DsymOutputType.java45
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java37
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java14
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundling.java19
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java54
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingTargetFactory.java4
9 files changed, 184 insertions, 143 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/BinaryLinkingTargetFactory.java b/src/main/java/com/google/devtools/build/lib/rules/objc/BinaryLinkingTargetFactory.java
index 4887a01f0b..c60da2ecaf 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/BinaryLinkingTargetFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/BinaryLinkingTargetFactory.java
@@ -104,7 +104,10 @@ abstract class BinaryLinkingTargetFactory implements RuleConfiguredTargetFactory
.registerCompileAndArchiveActions(common)
.addXcodeSettings(xcodeProviderBuilder, common)
.registerLinkActions(
- objcProvider, getExtraLinkArgs(ruleContext), ImmutableList.<Artifact>of())
+ objcProvider,
+ getExtraLinkArgs(ruleContext),
+ ImmutableList.<Artifact>of(),
+ DsymOutputType.APP)
.validateAttributes();
if (ruleContext.hasErrors()) {
@@ -118,13 +121,17 @@ abstract class BinaryLinkingTargetFactory implements RuleConfiguredTargetFactory
ObjcConfiguration objcConfiguration = ObjcRuleClasses.objcConfiguration(ruleContext);
AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
// TODO(bazel-team): Remove once all bundle users are migrated to ios_application.
- ReleaseBundlingSupport releaseBundlingSupport = new ReleaseBundlingSupport(
- ruleContext, objcProvider, LinkedBinary.LOCAL_AND_DEPENDENCIES,
- ReleaseBundlingSupport.APP_BUNDLE_DIR_FORMAT, objcConfiguration.getMinimumOs());
+ ReleaseBundlingSupport releaseBundlingSupport =
+ new ReleaseBundlingSupport(
+ ruleContext,
+ objcProvider,
+ LinkedBinary.LOCAL_AND_DEPENDENCIES,
+ ReleaseBundlingSupport.APP_BUNDLE_DIR_FORMAT,
+ objcConfiguration.getMinimumOs());
releaseBundlingSupport
- .registerActions()
+ .registerActions(DsymOutputType.APP)
.addXcodeSettings(xcodeProviderBuilder)
- .addFilesToBuild(filesToBuild)
+ .addFilesToBuild(filesToBuild, DsymOutputType.APP)
.validateResources()
.validateAttributes();
@@ -217,7 +224,7 @@ abstract class BinaryLinkingTargetFactory implements RuleConfiguredTargetFactory
builder.addDepObjcProviders(createSkylarkObjcProviders(ruleContext));
if (ObjcRuleClasses.objcConfiguration(ruleContext).generateDebugSymbols()) {
- builder.addDebugArtifacts();
+ builder.addDebugArtifacts(DsymOutputType.APP);
}
if (ObjcRuleClasses.objcConfiguration(ruleContext).generateLinkmap()) {
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 e62b8c3b8e..e18d2dc012 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
@@ -42,7 +42,6 @@ import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.PRECOMPIL
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 com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.SWIFT;
-import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.intermediateArtifacts;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import com.google.common.annotations.VisibleForTesting;
@@ -220,6 +219,7 @@ public final class CompilationSupport {
private final RuleContext ruleContext;
private final CompilationAttributes attributes;
+ private final IntermediateArtifacts intermediateArtifacts;
/**
* Creates a new compilation support for the given rule.
@@ -227,6 +227,7 @@ public final class CompilationSupport {
public CompilationSupport(RuleContext ruleContext) {
this.ruleContext = ruleContext;
this.attributes = new CompilationAttributes(ruleContext);
+ this.intermediateArtifacts = ObjcRuleClasses.intermediateArtifacts(ruleContext);
}
/**
@@ -239,8 +240,6 @@ public final class CompilationSupport {
throws InterruptedException {
if (common.getCompilationArtifacts().isPresent()) {
registerGenerateModuleMapAction(common.getCompilationArtifacts());
- IntermediateArtifacts intermediateArtifacts =
- ObjcRuleClasses.intermediateArtifacts(ruleContext);
Optional<CppModuleMap> moduleMap;
if (ObjcRuleClasses.objcConfiguration(ruleContext).moduleMapsEnabled()) {
moduleMap = Optional.of(intermediateArtifacts.moduleMap());
@@ -249,7 +248,6 @@ public final class CompilationSupport {
}
registerCompileAndArchiveActions(
common.getCompilationArtifacts().get(),
- intermediateArtifacts,
common.getObjcProvider(),
moduleMap,
ruleContext.getConfiguration().isCodeCoverageEnabled(),
@@ -264,7 +262,6 @@ public final class CompilationSupport {
*/
private void registerCompileAndArchiveActions(
CompilationArtifacts compilationArtifacts,
- IntermediateArtifacts intermediateArtifacts,
ObjcProvider objcProvider,
Optional<CppModuleMap> moduleMap,
boolean isCodeCoverageEnabled,
@@ -274,14 +271,13 @@ public final class CompilationSupport {
Artifact objFile = intermediateArtifacts.objFile(sourceFile);
objFiles.add(objFile);
if (ObjcRuleClasses.SWIFT_SOURCES.matches(sourceFile.getFilename())) {
- registerSwiftCompileAction(sourceFile, objFile, intermediateArtifacts, objcProvider);
+ registerSwiftCompileAction(sourceFile, objFile, objcProvider);
} else {
registerCompileAction(
sourceFile,
objFile,
objcProvider,
moduleMap,
- intermediateArtifacts,
compilationArtifacts,
ImmutableList.of("-fobjc-arc"),
isCodeCoverageEnabled);
@@ -295,7 +291,6 @@ public final class CompilationSupport {
objFile,
objcProvider,
moduleMap,
- intermediateArtifacts,
compilationArtifacts,
ImmutableList.of("-fno-objc-arc"),
isCodeCoverageEnabled);
@@ -304,11 +299,11 @@ public final class CompilationSupport {
objFiles.addAll(compilationArtifacts.getPrecompiledSrcs());
if (compilationArtifacts.hasSwiftSources()) {
- registerSwiftModuleMergeAction(intermediateArtifacts, compilationArtifacts, objcProvider);
+ registerSwiftModuleMergeAction(compilationArtifacts, objcProvider);
}
for (Artifact archive : compilationArtifacts.getArchive().asSet()) {
- registerArchiveActions(intermediateArtifacts, objFiles, archive);
+ registerArchiveActions(objFiles, archive);
}
if (isFullyLinkEnabled) {
@@ -341,7 +336,6 @@ public final class CompilationSupport {
Artifact objFile,
ObjcProvider objcProvider,
Optional<CppModuleMap> moduleMap,
- IntermediateArtifacts intermediateArtifacts,
CompilationArtifacts compilationArtifacts,
Iterable<String> otherFlags,
boolean isCodeCoverageEnabled) {
@@ -481,7 +475,6 @@ public final class CompilationSupport {
private void registerSwiftCompileAction(
Artifact sourceFile,
Artifact objFile,
- IntermediateArtifacts intermediateArtifacts,
ObjcProvider objcProvider) {
ObjcConfiguration objcConfiguration = ObjcRuleClasses.objcConfiguration(ruleContext);
AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
@@ -572,7 +565,6 @@ public final class CompilationSupport {
* used by Objective-C code.
*/
private void registerSwiftModuleMergeAction(
- IntermediateArtifacts intermediateArtifacts,
CompilationArtifacts compilationArtifacts,
ObjcProvider objcProvider) {
ObjcConfiguration objcConfiguration = ObjcRuleClasses.objcConfiguration(ruleContext);
@@ -637,8 +629,7 @@ public final class CompilationSupport {
.build(ruleContext));
}
- private void registerArchiveActions(IntermediateArtifacts intermediateArtifacts,
- ImmutableList.Builder<Artifact> objFiles, Artifact archive) {
+ private void registerArchiveActions(ImmutableList.Builder<Artifact> objFiles, Artifact archive) {
for (Action action : archiveActions(ruleContext, objFiles.build(), archive,
ruleContext.getFragment(AppleConfiguration.class),
intermediateArtifacts.objList())) {
@@ -717,7 +708,6 @@ public final class CompilationSupport {
if (common.getCompilationArtifacts().isPresent()) {
CompilationArtifacts artifacts = common.getCompilationArtifacts().get();
- IntermediateArtifacts intermediateArtifacts = intermediateArtifacts(ruleContext);
for (Artifact artifact : Iterables.concat(artifacts.getSrcs(), artifacts.getNonArcSrcs())) {
oFiles.add(intermediateArtifacts.objFile(artifact));
}
@@ -745,20 +735,22 @@ public final class CompilationSupport {
* @param objcProvider common information about this rule's attributes and its dependencies
* @param extraLinkArgs any additional arguments to pass to the linker
* @param extraLinkInputs any additional input artifacts to pass to the link action
+ * @param dsymOutputType the file type of the dSYM bundle to be generated
*
* @return this compilation support
*/
- CompilationSupport registerLinkActions(ObjcProvider objcProvider, ExtraLinkArgs extraLinkArgs,
- Iterable<Artifact> extraLinkInputs) {
- IntermediateArtifacts intermediateArtifacts =
- ObjcRuleClasses.intermediateArtifacts(ruleContext);
- Optional<Artifact> dsymBundle;
+ CompilationSupport registerLinkActions(
+ ObjcProvider objcProvider,
+ ExtraLinkArgs extraLinkArgs,
+ Iterable<Artifact> extraLinkInputs,
+ DsymOutputType dsymOutputType) {
+ Optional<Artifact> dsymBundleZip;
Optional<Artifact> linkmap;
if (ObjcRuleClasses.objcConfiguration(ruleContext).generateDebugSymbols()) {
- registerDsymActions();
- dsymBundle = Optional.of(intermediateArtifacts.dsymBundle());
+ registerDsymActions(dsymOutputType);
+ dsymBundleZip = Optional.of(intermediateArtifacts.tempDsymBundleZip(dsymOutputType));
} else {
- dsymBundle = Optional.absent();
+ dsymBundleZip = Optional.absent();
}
Iterable<Artifact> prunedJ2ObjcArchives = ImmutableList.<Artifact>of();
@@ -778,7 +770,7 @@ public final class CompilationSupport {
objcProvider,
extraLinkArgs,
extraLinkInputs,
- dsymBundle,
+ dsymBundleZip,
prunedJ2ObjcArchives,
linkmap);
return this;
@@ -846,12 +838,14 @@ public final class CompilationSupport {
return Iterables.contains(commandLine.arguments(), "-dynamiclib");
}
- private void registerLinkAction(ObjcProvider objcProvider, ExtraLinkArgs extraLinkArgs,
- Iterable<Artifact> extraLinkInputs, Optional<Artifact> dsymBundle,
- Iterable<Artifact> prunedJ2ObjcArchives, Optional<Artifact> linkmap) {
+ private void registerLinkAction(
+ ObjcProvider objcProvider,
+ ExtraLinkArgs extraLinkArgs,
+ Iterable<Artifact> extraLinkInputs,
+ Optional<Artifact> dsymBundleZip,
+ Iterable<Artifact> prunedJ2ObjcArchives,
+ Optional<Artifact> linkmap) {
ObjcConfiguration objcConfiguration = ObjcRuleClasses.objcConfiguration(ruleContext);
- IntermediateArtifacts intermediateArtifacts =
- ObjcRuleClasses.intermediateArtifacts(ruleContext);
// When compilation_mode=opt and objc_enable_binary_stripping are specified, the unstripped
// binary containing debug symbols is generated by the linker, which also needs the debug
@@ -866,15 +860,22 @@ public final class CompilationSupport {
ImmutableList<Artifact> ccLibraries = ccLibraries(objcProvider);
NestedSet<Artifact> bazelBuiltLibraries = Iterables.isEmpty(prunedJ2ObjcArchives)
? objcProvider.get(LIBRARY) : substituteJ2ObjcPrunedLibraries(objcProvider);
- CommandLine commandLine = linkCommandLine(extraLinkArgs, objcProvider, binaryToLink,
- dsymBundle, ccLibraries, bazelBuiltLibraries, linkmap);
+ CommandLine commandLine =
+ linkCommandLine(
+ extraLinkArgs,
+ objcProvider,
+ binaryToLink,
+ dsymBundleZip,
+ ccLibraries,
+ bazelBuiltLibraries,
+ linkmap);
ruleContext.registerAction(
ObjcRuleClasses.spawnAppleEnvActionBuilder(ruleContext)
.setMnemonic("ObjcLink")
.setShellCommand(ImmutableList.of("/bin/bash", "-c"))
.setCommandLine(new SingleArgCommandLine(commandLine))
.addOutput(binaryToLink)
- .addOutputs(dsymBundle.asSet())
+ .addOutputs(dsymBundleZip.asSet())
.addOutputs(linkmap.asSet())
.addTransitiveInputs(bazelBuiltLibraries)
.addTransitiveInputs(objcProvider.get(IMPORTED_LIBRARY))
@@ -920,8 +921,6 @@ public final class CompilationSupport {
}
private ImmutableList<Artifact> j2objcPrunedLibraries(ObjcProvider objcProvider) {
- IntermediateArtifacts intermediateArtifacts =
- ObjcRuleClasses.intermediateArtifacts(ruleContext);
ImmutableList.Builder<Artifact> j2objcPrunedLibraryBuilder = ImmutableList.builder();
for (Artifact j2objcLibrary : objcProvider.get(ObjcProvider.J2OBJC_LIBRARY)) {
j2objcPrunedLibraryBuilder.add(intermediateArtifacts.j2objcPrunedArchive(j2objcLibrary));
@@ -945,8 +944,6 @@ public final class CompilationSupport {
*/
private NestedSet<Artifact> substituteJ2ObjcPrunedLibraries(ObjcProvider objcProvider) {
ImmutableList.Builder<Artifact> libraries = new ImmutableList.Builder<>();
- IntermediateArtifacts intermediateArtifacts =
- ObjcRuleClasses.intermediateArtifacts(ruleContext);
Set<Artifact> unprunedJ2ObjcLibs = objcProvider.get(ObjcProvider.J2OBJC_LIBRARY).toSet();
for (Artifact library : objcProvider.get(LIBRARY)) {
@@ -961,14 +958,18 @@ public final class CompilationSupport {
return NestedSetBuilder.wrap(Order.NAIVE_LINK_ORDER, libraries.build());
}
- private CommandLine linkCommandLine(ExtraLinkArgs extraLinkArgs,
- ObjcProvider objcProvider, Artifact linkedBinary, Optional<Artifact> dsymBundle,
- Iterable<Artifact> ccLibraries, Iterable<Artifact> bazelBuiltLibraries,
+ private CommandLine linkCommandLine(
+ ExtraLinkArgs extraLinkArgs,
+ ObjcProvider objcProvider,
+ Artifact linkedBinary,
+ Optional<Artifact> dsymBundleZip,
+ Iterable<Artifact> ccLibraries,
+ Iterable<Artifact> bazelBuiltLibraries,
Optional<Artifact> linkmap) {
ObjcConfiguration objcConfiguration = ObjcRuleClasses.objcConfiguration(ruleContext);
AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
Iterable<String> libraryNames = libraryNames(objcProvider);
-
+
CustomCommandLine.Builder commandLine = CustomCommandLine.builder()
.addPath(xcrunwrapper(ruleContext).getExecutable().getExecPath());
if (objcProvider.is(USES_CPP)) {
@@ -1042,20 +1043,20 @@ public final class CompilationSupport {
.add("-Xlinker -map")
.add("-Xlinker " + linkmap.get().getExecPath());
}
-
+
// Call to dsymutil for debug symbol generation must happen in the link action.
// All debug symbol information is encoded in object files inside archive files. To generate
// the debug symbol bundle, dsymutil will look inside the linked binary for the encoded
// absolute paths to archive files, which are only valid in the link action.
- if (dsymBundle.isPresent()) {
- PathFragment dsymPath = FileSystemUtils.removeExtension(dsymBundle.get().getExecPath());
+ if (dsymBundleZip.isPresent()) {
+ PathFragment dsymPath = FileSystemUtils.removeExtension(dsymBundleZip.get().getExecPath());
commandLine
.add("&&")
.addPath(xcrunwrapper(ruleContext).getExecutable().getExecPath())
.add(DSYMUTIL)
.add(linkedBinary.getExecPathString())
.add("-o " + dsymPath)
- .add("&& zipped_bundle=${PWD}/" + dsymBundle.get().getShellEscapedExecPathString())
+ .add("&& zipped_bundle=${PWD}/" + dsymBundleZip.get().getShellEscapedExecPathString())
.add("&& cd " + dsymPath)
.add("&& /usr/bin/zip -q -r \"${zipped_bundle}\" .");
}
@@ -1126,8 +1127,6 @@ public final class CompilationSupport {
NestedSet<Artifact> j2ObjcDependencyMappingFiles = provider.getDependencyMappingFiles();
NestedSet<Artifact> j2ObjcHeaderMappingFiles = provider.getHeaderMappingFiles();
NestedSet<Artifact> j2ObjcArchiveSourceMappingFiles = provider.getArchiveSourceMappingFiles();
- IntermediateArtifacts intermediateArtifacts =
- ObjcRuleClasses.intermediateArtifacts(ruleContext);
for (Artifact j2objcArchive : objcProvider.get(ObjcProvider.J2OBJC_LIBRARY)) {
PathFragment paramFilePath = FileSystemUtils.replaceExtension(
@@ -1255,22 +1254,18 @@ public final class CompilationSupport {
return this;
}
- private CompilationSupport registerDsymActions() {
- IntermediateArtifacts intermediateArtifacts =
- ObjcRuleClasses.intermediateArtifacts(ruleContext);
+ private CompilationSupport registerDsymActions(DsymOutputType dsymOutputType) {
ObjcConfiguration objcConfiguration = ObjcRuleClasses.objcConfiguration(ruleContext);
- Artifact dsymBundle = intermediateArtifacts.dsymBundle();
+ Artifact tempDsymBundleZip = intermediateArtifacts.tempDsymBundleZip(dsymOutputType);
Artifact linkedBinary =
objcConfiguration.shouldStripBinary()
? intermediateArtifacts.unstrippedSingleArchitectureBinary()
: intermediateArtifacts.strippedSingleArchitectureBinary();
- Artifact debugSymbolFile = intermediateArtifacts.dsymSymbol();
- Artifact dsymPlist = intermediateArtifacts.dsymPlist();
+ Artifact debugSymbolFile = intermediateArtifacts.dsymSymbol(dsymOutputType);
+ Artifact dsymPlist = intermediateArtifacts.dsymPlist(dsymOutputType);
- PathFragment dsymOutputDir =
- replaceSuffix(
- dsymBundle.getExecPath(), IntermediateArtifacts.TMP_DSYM_BUNDLE_SUFFIX, ".app.dSYM");
+ PathFragment dsymOutputDir = removeSuffix(tempDsymBundleZip.getExecPath(), ".zip");
PathFragment dsymPlistZipEntry = dsymPlist.getExecPath().relativeTo(dsymOutputDir);
PathFragment debugSymbolFileZipEntry =
debugSymbolFile
@@ -1283,13 +1278,13 @@ public final class CompilationSupport {
.append(
String.format(
"unzip -p %s %s > %s",
- dsymBundle.getExecPathString(),
+ tempDsymBundleZip.getExecPathString(),
dsymPlistZipEntry,
dsymPlist.getExecPathString()))
.append(
String.format(
" && unzip -p %s %s > %s",
- dsymBundle.getExecPathString(),
+ tempDsymBundleZip.getExecPathString(),
debugSymbolFileZipEntry,
debugSymbolFile.getExecPathString()));
@@ -1297,7 +1292,7 @@ public final class CompilationSupport {
new SpawnAction.Builder()
.setMnemonic("UnzipDsym")
.setShellCommand(unzipDsymCommand.toString())
- .addInput(dsymBundle)
+ .addInput(tempDsymBundleZip)
.addOutput(dsymPlist)
.addOutput(debugSymbolFile)
.build(ruleContext));
@@ -1319,14 +1314,11 @@ public final class CompilationSupport {
return this;
}
- private PathFragment replaceSuffix(PathFragment path, String suffix, String newSuffix) {
- // TODO(bazel-team): Throw instead of returning null?
+ private PathFragment removeSuffix(PathFragment path, String suffix) {
String name = path.getBaseName();
- if (name.endsWith(suffix)) {
- return path.replaceName(name.substring(0, name.length() - suffix.length()) + newSuffix);
- } else {
- return null;
- }
+ Preconditions.checkArgument(
+ name.endsWith(suffix), "expect %s to end with %s, but it does not", name, suffix);
+ return path.replaceName(name.substring(0, name.length() - suffix.length()));
}
/**
@@ -1336,7 +1328,7 @@ public final class CompilationSupport {
// If we have module maps support, we need to use the generated module name, this way
// clang can properly load objc part of the module via -import-underlying-module command.
if (ObjcRuleClasses.objcConfiguration(ruleContext).moduleMapsEnabled()) {
- return ObjcRuleClasses.intermediateArtifacts(ruleContext).moduleMap().getName();
+ return intermediateArtifacts.moduleMap().getName();
}
// Otherwise, just use target name, it doesn't matter.
return ruleContext.getLabel().getName();
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/DsymOutputType.java b/src/main/java/com/google/devtools/build/lib/rules/objc/DsymOutputType.java
new file mode 100644
index 0000000000..5ad1502e89
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/DsymOutputType.java
@@ -0,0 +1,45 @@
+// Copyright 2016 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.rules.objc;
+
+/**
+ * Used as a descriptor of the expected type of the dSYM bundle that is output when building a rule.
+ */
+enum DsymOutputType {
+ /**
+ * Specifies that the dSYM bundle should have an 'xctest' suffix, which is the expected type when
+ * Xcode runs the tests.
+ */
+ TEST(".xctest.dSYM"),
+
+ /**
+ * Specifies that the dSYM bundle should have an 'app' suffix, which is the default type when
+ * generating the bundle for debugging or for crash symbolication.
+ */
+ APP(".app.dSYM");
+
+ private final String suffix;
+
+ private DsymOutputType(String suffix) {
+ this.suffix = suffix;
+ }
+
+ /**
+ * Returns the suffix to be used by the dSYM bundle output.
+ */
+ String getSuffix() {
+ return suffix;
+ }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java
index b22c830413..e57187fbc6 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java
@@ -30,13 +30,6 @@ import com.google.devtools.build.lib.vfs.PathFragment;
// TODO(bazel-team): This should really be named DerivedArtifacts as it contains methods for
// final as well as intermediate artifacts.
public final class IntermediateArtifacts {
-
- /**
- * Extension used on the temporary zipped dsym bundle location. Must contain {@code .dSYM} for
- * dsymutil to generate a plist file.
- */
- static final String TMP_DSYM_BUNDLE_SUFFIX = ".temp.app.dSYM.zip";
-
static final String LINKMAP_SUFFIX = ".linkmap";
static final String BREAKPAD_SUFFIX = ".breakpad";
@@ -193,13 +186,6 @@ public final class IntermediateArtifacts {
"lib%s%s.a", basename, archiveFileNameSuffix)));
}
- /**
- * The zipped debug symbol bundle file which contains debug symbols generated by dsymutil.
- */
- public Artifact dsymBundle() {
- return appendExtension(TMP_DSYM_BUNDLE_SUFFIX);
- }
-
private Artifact inUniqueObjsDir(Artifact source, String extension) {
PathFragment uniqueDir =
new PathFragment("_objs").getRelative(ruleContext.getLabel().getName());
@@ -299,27 +285,36 @@ public final class IntermediateArtifacts {
}
/**
+ * The temp zipped debug symbol bundle file which contains debug symbols generated by dsymutil.
+ */
+ public Artifact tempDsymBundleZip(DsymOutputType dsymOutputType) {
+ return appendExtension(dsymOutputType.getSuffix() + ".zip");
+ }
+
+ /**
* Debug symbol plist generated for a linked binary.
*/
- public Artifact dsymPlist() {
- return appendExtension(".app.dSYM/Contents/Info.plist");
+ public Artifact dsymPlist(DsymOutputType dsymOutputType) {
+ return appendExtension(String.format("%s/Contents/Info.plist", dsymOutputType.getSuffix()));
}
/**
* Debug symbol file generated for a linked binary.
*/
- public Artifact dsymSymbol() {
- return appendExtension(String.format(
- ".app.dSYM/Contents/Resources/DWARF/%s_bin", ruleContext.getLabel().getName()));
+ public Artifact dsymSymbol(DsymOutputType dsymOutputType) {
+ return dsymSymbol(dsymOutputType, "bin");
}
/**
* Debug symbol file generated for a linked binary, for a specific architecture.
*/
- public Artifact dsymSymbol(String arch) {
+ public Artifact dsymSymbol(DsymOutputType dsymOutputType, String suffix) {
return appendExtension(
String.format(
- ".app.dSYM/Contents/Resources/DWARF/%s_%s", ruleContext.getLabel().getName(), arch));
+ "%s/Contents/Resources/DWARF/%s_%s",
+ dsymOutputType.getSuffix(),
+ ruleContext.getLabel().getName(),
+ suffix));
}
/**
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java
index 76b72b07ca..06d6d778ef 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java
@@ -131,7 +131,8 @@ public final class IosTest implements RuleConfiguredTargetFactory {
}
new CompilationSupport(ruleContext)
- .registerLinkActions(common.getObjcProvider(), extraLinkArgs, extraLinkInputs)
+ .registerLinkActions(
+ common.getObjcProvider(), extraLinkArgs, extraLinkInputs, DsymOutputType.TEST)
.registerCompileAndArchiveActions(common)
.addXcodeSettings(xcodeProviderBuilder, common)
.validateAttributes();
@@ -143,9 +144,9 @@ public final class IosTest implements RuleConfiguredTargetFactory {
LinkedBinary.LOCAL_AND_DEPENDENCIES,
bundleFormat,
objcConfiguration.getMinimumOs())
- .registerActions()
+ .registerActions(DsymOutputType.TEST)
.addXcodeSettings(xcodeProviderBuilder)
- .addFilesToBuild(filesToBuild)
+ .addFilesToBuild(filesToBuild, DsymOutputType.TEST)
.validateResources()
.validateAttributes();
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java
index 492443e079..f2dd17810a 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java
@@ -307,7 +307,7 @@ public final class ObjcCommon {
private boolean alwayslink;
private boolean hasModuleMap;
private Iterable<Artifact> extraImportLibraries = ImmutableList.of();
- private boolean shouldAddDebugArtifacts;
+ private DsymOutputType dsymOutputType;
private Optional<Artifact> linkedBinary = Optional.absent();
private Optional<Artifact> linkmapFile = Optional.absent();
private Iterable<CppCompilationContext> depCcHeaderProviders = ImmutableList.of();
@@ -427,10 +427,10 @@ public final class ObjcCommon {
}
/**
- * Sets whether the debug artifacts (breakpad, dsym files) should be propagated to dependers.
+ * Sets which type of dsym output this rule generated to be propagated to dependers.
*/
- Builder addDebugArtifacts() {
- this.shouldAddDebugArtifacts = true;
+ Builder addDebugArtifacts(DsymOutputType dsymOutputType) {
+ this.dsymOutputType = dsymOutputType;
return this;
}
@@ -624,11 +624,11 @@ public final class ObjcCommon {
objcProvider.addAll(LINKED_BINARY, linkedBinary.asSet())
.addAll(LINKMAP_FILE, linkmapFile.asSet());
- if (shouldAddDebugArtifacts) {
+ if (dsymOutputType != null) {
objcProvider
.add(BREAKPAD_FILE, intermediateArtifacts.breakpadSym())
- .add(DEBUG_SYMBOLS, intermediateArtifacts.dsymSymbol())
- .add(DEBUG_SYMBOLS_PLIST, intermediateArtifacts.dsymPlist());
+ .add(DEBUG_SYMBOLS, intermediateArtifacts.dsymSymbol(dsymOutputType))
+ .add(DEBUG_SYMBOLS_PLIST, intermediateArtifacts.dsymPlist(dsymOutputType));
}
return new ObjcCommon(objcProvider.build(), compilationArtifacts);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundling.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundling.java
index ebc2e2ec15..4a8e560baf 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundling.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundling.java
@@ -59,7 +59,6 @@ final class ReleaseBundling {
private final NestedSetBuilder<Artifact> infoplistInputs = NestedSetBuilder.stableOrder();
private Iterable<Artifact> infoPlistsFromRule;
private ImmutableSet<TargetDeviceFamily> families;
- private IntermediateArtifacts intermediateArtifacts;
private String artifactPrefix;
public Builder setIpaArtifact(Artifact ipaArtifact) {
@@ -122,11 +121,6 @@ final class ReleaseBundling {
return this;
}
- public Builder setIntermediateArtifacts(IntermediateArtifacts intermediateArtifacts) {
- this.intermediateArtifacts = intermediateArtifacts;
- return this;
- }
-
public Builder setTargetDeviceFamilies(ImmutableSet<TargetDeviceFamily> families) {
this.families = families;
return this;
@@ -138,7 +132,6 @@ final class ReleaseBundling {
}
public ReleaseBundling build() {
- Preconditions.checkNotNull(intermediateArtifacts, "intermediateArtifacts");
Preconditions.checkNotNull(families, FAMILIES_ATTR);
return new ReleaseBundling(
ipaArtifact,
@@ -153,7 +146,6 @@ final class ReleaseBundling {
infoplistInputs.build(),
infoPlistsFromRule,
families,
- intermediateArtifacts,
artifactPrefix);
}
}
@@ -211,7 +203,6 @@ final class ReleaseBundling {
.setProvisioningProfile(provisioningProfile)
.setProvisioningProfileAttributeName(PROVISIONING_PROFILE_ATTR)
.setTargetDeviceFamilies(families)
- .setIntermediateArtifacts(ObjcRuleClasses.intermediateArtifacts(ruleContext))
.build();
}
@@ -229,7 +220,6 @@ final class ReleaseBundling {
private final String provisioningProfileAttributeName;
private final NestedSet<Artifact> infoplistInputs;
private final ImmutableSet<TargetDeviceFamily> families;
- private final IntermediateArtifacts intermediateArtifacts;
private final Iterable<Artifact> infoPlistsFromRule;
private final String artifactPrefix;
@@ -246,7 +236,6 @@ final class ReleaseBundling {
NestedSet<Artifact> infoplistInputs,
Iterable<Artifact> infoPlistsFromRule,
ImmutableSet<TargetDeviceFamily> families,
- IntermediateArtifacts intermediateArtifacts,
String artifactPrefix) {
this.ipaArtifact = Preconditions.checkNotNull(ipaArtifact);
this.bundleId = bundleId;
@@ -261,7 +250,6 @@ final class ReleaseBundling {
this.infoplistInputs = Preconditions.checkNotNull(infoplistInputs);
this.infoPlistsFromRule = infoPlistsFromRule;
this.families = Preconditions.checkNotNull(families);
- this.intermediateArtifacts = Preconditions.checkNotNull(intermediateArtifacts);
this.artifactPrefix = artifactPrefix;
}
@@ -338,13 +326,6 @@ final class ReleaseBundling {
}
/**
- * Returns {@link IntermediateArtifacts} used to create this bundle.
- */
- public IntermediateArtifacts getIntermediateArtifacts() {
- return intermediateArtifacts;
- }
-
- /**
* Returns the name of the attribute which is used to specifiy the provisioning profile.
*/
public String getProvisioningProfileAttrName() {
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java
index 84a817d64c..617300ecab 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java
@@ -172,7 +172,7 @@ public final class ReleaseBundlingSupport {
this.ruleContext = ruleContext;
this.objcProvider = objcProvider;
this.releaseBundling = releaseBundling;
- this.intermediateArtifacts = releaseBundling.getIntermediateArtifacts();
+ this.intermediateArtifacts = ObjcRuleClasses.intermediateArtifacts(ruleContext);
this.bundling = bundling(ruleContext, objcProvider, bundleDirFormat, bundleName,
bundleMinimumOsVersion);
bundleSupport = new BundleSupport(ruleContext, bundling, extraActoolArgs());
@@ -197,8 +197,14 @@ public final class ReleaseBundlingSupport {
String bundleDirFormat,
String bundleName,
DottedVersion bundleMinimumOsVersion) throws InterruptedException {
- this(ruleContext, objcProvider, linkedBinary, bundleDirFormat, bundleName,
- bundleMinimumOsVersion, ReleaseBundling.releaseBundling(ruleContext));
+ this(
+ ruleContext,
+ objcProvider,
+ linkedBinary,
+ bundleDirFormat,
+ bundleName,
+ bundleMinimumOsVersion,
+ ReleaseBundling.releaseBundling(ruleContext));
}
/**
@@ -277,15 +283,18 @@ public final class ReleaseBundlingSupport {
* this application if appropriate and combining several single-architecture binaries into one
* multi-architecture binary.
*
+ * @param dsymOutputType the file type of the dSYM bundle to be generated
+ *
* @return this application support
*/
- ReleaseBundlingSupport registerActions() throws InterruptedException {
+ ReleaseBundlingSupport registerActions(DsymOutputType dsymOutputType)
+ throws InterruptedException {
bundleSupport.registerActions(objcProvider);
registerCombineArchitecturesAction();
registerTransformAndCopyBreakpadFilesAction();
- registerCopyDsymFilesAction();
- registerCopyDsymPlistAction();
+ registerCopyDsymFilesAction(dsymOutputType);
+ registerCopyDsymPlistAction(dsymOutputType);
registerCopyLinkmapFilesAction();
registerSwiftStdlibActionsIfNecessary();
@@ -583,9 +592,14 @@ public final class ReleaseBundlingSupport {
* Adds any files to the given nested set builder that should be built if this application is the
* top level target in a blaze invocation.
*
+ * @param filesToBuild a collection of files to be built, where new artifacts to be built are
+ * going to be placed
+ * @param dsymOutputType the file type of the dSYM bundle to be built
+ *
* @return this application support
*/
- ReleaseBundlingSupport addFilesToBuild(NestedSetBuilder<Artifact> filesToBuild)
+ ReleaseBundlingSupport addFilesToBuild(
+ NestedSetBuilder<Artifact> filesToBuild, DsymOutputType dsymOutputType)
throws InterruptedException {
NestedSetBuilder<Artifact> debugSymbolBuilder = NestedSetBuilder.<Artifact>stableOrder();
@@ -595,7 +609,7 @@ public final class ReleaseBundlingSupport {
if (ObjcRuleClasses.objcConfiguration(ruleContext).generateDebugSymbols()) {
filesToBuild.addAll(getBreakpadFiles().values());
- filesToBuild.addAll(getDsymFiles().values());
+ filesToBuild.addAll(getDsymFiles(dsymOutputType).values());
// TODO(bazel-team): Remove the 'if' when the objc_binary rule does not generate a bundle any
// more. The reason this 'if' is here is because the plist is obtained from the ObjcProvider.
@@ -606,13 +620,13 @@ public final class ReleaseBundlingSupport {
// only get called by *_application rules, with the plist configured in the provider.
Artifact cpuPlist = getAnyCpuSpecificDsymPlist();
if (cpuPlist != null) {
- filesToBuild.add(intermediateArtifacts.dsymPlist());
+ filesToBuild.add(intermediateArtifacts.dsymPlist(dsymOutputType));
}
if (linkedBinary == LinkedBinary.LOCAL_AND_DEPENDENCIES) {
debugSymbolBuilder
- .add(intermediateArtifacts.dsymPlist())
- .add(intermediateArtifacts.dsymSymbol())
+ .add(intermediateArtifacts.dsymPlist(dsymOutputType))
+ .add(intermediateArtifacts.dsymSymbol(dsymOutputType))
.add(intermediateArtifacts.breakpadSym());
}
}
@@ -886,9 +900,11 @@ public final class ReleaseBundlingSupport {
* Registers the actions that copy the debug symbol files from the CPU-specific binaries that are
* part of this application. The only one step executed is that he dsym files have to be renamed
* to include their corresponding CPU architecture as a suffix.
+ *
+ * @param dsymOutputType the file type of the dSYM bundle to be copied
*/
- private void registerCopyDsymFilesAction() {
- for (Entry<Artifact, Artifact> dsymFiles : getDsymFiles().entrySet()) {
+ private void registerCopyDsymFilesAction(DsymOutputType dsymOutputType) {
+ for (Entry<Artifact, Artifact> dsymFiles : getDsymFiles(dsymOutputType).entrySet()) {
ruleContext.registerAction(
new SymlinkAction(
ruleContext.getActionOwner(),
@@ -900,15 +916,17 @@ public final class ReleaseBundlingSupport {
/**
* Registers the action that copies the debug symbol plist from the binary.
+ *
+ * @param dsymOutputType the file type of the dSYM bundle to be copied
*/
- private void registerCopyDsymPlistAction() {
+ private void registerCopyDsymPlistAction(DsymOutputType dsymOutputType) {
Artifact dsymPlist = getAnyCpuSpecificDsymPlist();
if (dsymPlist != null) {
ruleContext.registerAction(
new SymlinkAction(
ruleContext.getActionOwner(),
dsymPlist,
- intermediateArtifacts.dsymPlist(),
+ intermediateArtifacts.dsymPlist(dsymOutputType),
"Symlinking dSYM plist"));
}
}
@@ -929,11 +947,13 @@ public final class ReleaseBundlingSupport {
/**
* Returns a map of input dsym artifacts from the CPU-specific binaries built for this
* ios_application to the new output dsym artifacts.
+ *
+ * @param dsymOutputType the file type of the dSYM bundle to be generated
*/
- private ImmutableMap<Artifact, Artifact> getDsymFiles() {
+ private ImmutableMap<Artifact, Artifact> getDsymFiles(DsymOutputType dsymOutputType) {
ImmutableMap.Builder<Artifact, Artifact> results = ImmutableMap.builder();
for (Entry<String, Artifact> dsymFile : attributes.cpuSpecificDsymFiles().entrySet()) {
- Artifact destDsym = intermediateArtifacts.dsymSymbol(dsymFile.getKey());
+ Artifact destDsym = intermediateArtifacts.dsymSymbol(dsymOutputType, dsymFile.getKey());
results.put(dsymFile.getValue(), destDsym);
}
return results.build();
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingTargetFactory.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingTargetFactory.java
index 20cda22c5c..373271a163 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingTargetFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingTargetFactory.java
@@ -71,9 +71,9 @@ public abstract class ReleaseBundlingTargetFactory implements RuleConfiguredTarg
ruleContext, common.getObjcProvider(), LinkedBinary.DEPENDENCIES_ONLY, bundleDirFormat,
bundleName(ruleContext), bundleMinimumOsVersion(ruleContext));
releaseBundlingSupport
- .registerActions()
+ .registerActions(DsymOutputType.APP)
.addXcodeSettings(xcodeProviderBuilder)
- .addFilesToBuild(filesToBuild)
+ .addFilesToBuild(filesToBuild, DsymOutputType.APP)
.validateResources()
.validateAttributes();