aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Matthew DeVore <matvore@google.com>2015-03-20 17:40:36 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2015-03-23 11:55:39 +0000
commit84ec4bfb479abea111acd2343c2602a44c09b3e5 (patch)
treebfe86b293a0bd6b803128ec147ee8a5d8933cd08
parent4aa1364794b7eef692f694aba7988169cfc3a946 (diff)
Pass pre-processed label to Xcodegen so it can be used as an Xcode target name without any extra work in Xcodegen. Use this label to determ
ine the *correct* built library. -- MOS_MIGRATED_REVID=89135635
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java5
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/XcodeProvider.java24
-rw-r--r--src/main/protobuf/xcodegen.proto7
-rw-r--r--src/objc_tools/xcodegen/java/com/google/devtools/build/xcode/xcodegen/XcodeprojGeneration.java2
4 files changed, 29 insertions, 9 deletions
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 398efa0b15..915fc80f14 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
@@ -410,8 +410,9 @@ public final class ObjcCommon {
for (CompilationArtifacts artifacts : compilationArtifacts.asSet()) {
for (Artifact archive : artifacts.getArchive().asSet()) {
objcProvider.add(FORCE_LOAD_LIBRARY, archive);
- objcProvider.add(FORCE_LOAD_FOR_XCODEGEN,
- "$(BUILT_PRODUCTS_DIR)/" + archive.getExecPath().getBaseName());
+ objcProvider.add(FORCE_LOAD_FOR_XCODEGEN, String.format(
+ "$(BUILT_PRODUCTS_DIR)/lib%s.a",
+ XcodeProvider.xcodeTargetName(context.getLabel())));
}
}
for (Artifact archive : extraImportLibraries) {
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/XcodeProvider.java b/src/main/java/com/google/devtools/build/lib/rules/objc/XcodeProvider.java
index 1ef52104cb..5597eefe83 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/XcodeProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/XcodeProvider.java
@@ -28,10 +28,13 @@ import static com.google.devtools.build.lib.rules.objc.ObjcProvider.XCDATAMODEL;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
+import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
+import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
@@ -399,12 +402,25 @@ public final class XcodeProvider implements TransitiveInfoProvider {
XcodeProductType.APPLICATION, XcodeProductType.BUNDLE, XcodeProductType.UNIT_TEST,
XcodeProductType.EXTENSION);
+ /**
+ * Returns the name of the Xcode target that corresponds to a build target with the given name.
+ * This changes the label to make it a legal Xcode target name (which means removing slashes and
+ * the colon). It also makes the label more readable in the Xcode UI by putting the target name
+ * first and the package elements in reverse. This means the "important" part is visible even if
+ * the project navigator is too narrow to show the entire name.
+ */
+ static String xcodeTargetName(Label label) {
+ String pathFromWorkspaceRoot = label.toString().replace("//", "").replace(':', '/');
+ List<String> components = Splitter.on('/').splitToList(pathFromWorkspaceRoot);
+ return Joiner.on('_').join(Lists.reverse(components));
+ }
+
private TargetControl targetControl() {
String buildFilePath = label.getPackageFragment().getSafePathString() + "/BUILD";
// TODO(bazel-team): Add provisioning profile information when Xcodegen supports it.
TargetControl.Builder targetControl = TargetControl.newBuilder()
.setName(label.getName())
- .setLabel(label.toString())
+ .setLabel(xcodeTargetName(label))
.setProductType(productType.getIdentifier())
.addAllImportedLibrary(Artifact.toExecPaths(objcProvider.get(IMPORTED_LIBRARY)))
.addAllUserHeaderSearchPath(userHeaderSearchPaths)
@@ -447,20 +463,20 @@ public final class XcodeProvider implements TransitiveInfoProvider {
&& dependency.compilationArtifacts.get().getArchive().isPresent();
if (hasSources || (dependency.productType == XcodeProductType.BUNDLE)) {
targetControl.addDependency(DependencyControl.newBuilder()
- .setTargetLabel(dependency.label.toString())
+ .setTargetLabel(xcodeTargetName(dependency.label))
.build());
}
}
}
for (XcodeProvider justTestHost : testHost.asSet()) {
targetControl.addDependency(DependencyControl.newBuilder()
- .setTargetLabel(justTestHost.label.toString())
+ .setTargetLabel(xcodeTargetName(justTestHost.label))
.setTestHost(true)
.build());
}
for (XcodeProvider extension : extensions) {
targetControl.addDependency(DependencyControl.newBuilder()
- .setTargetLabel(extension.label.toString())
+ .setTargetLabel(xcodeTargetName(extension.label))
.build());
}
diff --git a/src/main/protobuf/xcodegen.proto b/src/main/protobuf/xcodegen.proto
index 1d00fbc234..648022d140 100644
--- a/src/main/protobuf/xcodegen.proto
+++ b/src/main/protobuf/xcodegen.proto
@@ -36,8 +36,8 @@ message DependencyControl {
// Contains information specific to a single target in the project file.
// Next ID: 23
message TargetControl {
- // 'Name' of the target in the project file. This corresponds to the product
- // name, and does not have to be unique.
+ // A short name for the target that need not be unique. For instance, for
+ // binary targets this corresponds to the product name.
optional string name = 1;
// Relative paths to source files to compile. Each source file is added to
@@ -62,7 +62,8 @@ message TargetControl {
optional string infoplist = 5;
// Label corresponding to the target. This is needed to determine a
- // unique name for the target in the project.
+ // unique name for the target in the project. This is similar to the name
+ // field, but is globally unique and may be long.
optional string label = 7;
// Additional flags to pass to the [objective] c[++] compiler.
diff --git a/src/objc_tools/xcodegen/java/com/google/devtools/build/xcode/xcodegen/XcodeprojGeneration.java b/src/objc_tools/xcodegen/java/com/google/devtools/build/xcode/xcodegen/XcodeprojGeneration.java
index 8f7c9f9365..8d68e2ed55 100644
--- a/src/objc_tools/xcodegen/java/com/google/devtools/build/xcode/xcodegen/XcodeprojGeneration.java
+++ b/src/objc_tools/xcodegen/java/com/google/devtools/build/xcode/xcodegen/XcodeprojGeneration.java
@@ -273,6 +273,8 @@ public class XcodeprojGeneration {
}
}
+ // TODO(bazel-team): Make this a no-op once the released version of Bazel sends the label to
+ // xcodegen pre-processed.
private static String labelToXcodeTargetName(String label) {
String pathFromWorkspaceRoot = label.replace("//", "").replace(':', '/');
List<String> components = Splitter.on('/').splitToList(pathFromWorkspaceRoot);