Simplify Target Names in generated Xcode projects.

Compare:
https://screenshot.googleplex.com/hzmgwbpUeuf

RELNOTES:Target names in Xcode projects have been simplified. This may require recreating any schemes that you have defined.

--
MOS_MIGRATED_REVID=98664733
diff --git a/src/main/protobuf/xcodegen.proto b/src/main/protobuf/xcodegen.proto
index 9e12a1d..23d3362 100644
--- a/src/main/protobuf/xcodegen.proto
+++ b/src/main/protobuf/xcodegen.proto
@@ -82,8 +82,7 @@
   // -Info.plist file for the application.
   optional string infoplist = 5;
 
-  // Label corresponding to the target. This is needed to determine a
-  // unique name for the target in the project. This is similar to the name
+  // A 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;
 
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 c2d1457..496d50d 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
@@ -21,7 +21,6 @@
 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.ImmutableSet;
 import com.google.common.collect.Iterables;
@@ -67,6 +66,7 @@
 import java.nio.file.FileSystem;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.EnumSet;
 import java.util.HashMap;
@@ -166,7 +166,7 @@
       // Unlike other product types, a full application may have dozens of static libraries,
       // so rather than just use the target name, we use the full label to generate the product
       // name.
-      return labelToXcodeTargetName(targetControl.getLabel());
+      return targetControl.getLabel();
     } else {
       return targetControl.getName();
     }
@@ -275,14 +275,6 @@
     }
   }
 
-  // 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);
-    return Joiner.on('_').join(Lists.reverse(components));
-  }
-
   private static NSDictionary nonArcCompileSettings() {
     NSDictionary result = new NSDictionary();
     result.put("COMPILER_FLAGS", "-fno-objc-arc");
@@ -414,7 +406,7 @@
     }
 
     Map<String, TargetInfo> targetInfoByLabel = new HashMap<>();
-
+    List<String> usedTargetNames = new ArrayList<>();
     PBXFileReferences fileReferences = new PBXFileReferences();
     LibraryObjects libraryObjects = new LibraryObjects(fileReferences);
     PBXBuildFiles pbxBuildFiles = new PBXBuildFiles(fileReferences);
@@ -497,8 +489,16 @@
         targetBuildConfigMap.put(name, value);
       }
 
-      PBXNativeTarget target = new PBXNativeTarget(
-          labelToXcodeTargetName(targetControl.getLabel()), productType);
+      String targetName = targetControl.getName();
+      if (usedTargetNames.contains(targetName)) {
+        // Use the label in the odd case where we have two targets with the same name.
+        targetName = targetControl.getLabel();
+      }
+      checkState(!usedTargetNames.contains(targetName),
+          "Name already exists for target with label/name %s/%s in list: %s",
+          targetControl.getLabel(), targetControl.getName(), usedTargetNames);
+      usedTargetNames.add(targetName);
+      PBXNativeTarget target = new PBXNativeTarget(targetName, productType);
       try {
         target
             .getBuildConfigurationList()