Rollback of commit 6d98f6c633ec4a12737544a149bc18c41a3c442a.

*** Reason for rollback ***

Revert source file symlink resolution in XcodeGen. Since source files are not inputs for the XcodeGen action, this does not work if the action is sandboxed.

*** Original change description ***

RELNOTES: Resolve symlinks when calculating the workspace root in XcodeGen.

--
MOS_MIGRATED_REVID=94223656
diff --git a/src/objc_tools/xcodegen/java/com/google/devtools/build/xcode/xcodegen/XcodeGen.java b/src/objc_tools/xcodegen/java/com/google/devtools/build/xcode/xcodegen/XcodeGen.java
index b50ea30..31d18d4 100644
--- a/src/objc_tools/xcodegen/java/com/google/devtools/build/xcode/xcodegen/XcodeGen.java
+++ b/src/objc_tools/xcodegen/java/com/google/devtools/build/xcode/xcodegen/XcodeGen.java
@@ -14,8 +14,11 @@
 
 package com.google.devtools.build.xcode.xcodegen;
 
+import com.google.common.base.Function;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
 import com.google.devtools.build.xcode.xcodegen.proto.XcodeGenProtos.Control;
+import com.google.devtools.build.xcode.xcodegen.proto.XcodeGenProtos.TargetControl;
 import com.google.devtools.common.options.Option;
 import com.google.devtools.common.options.Options;
 import com.google.devtools.common.options.OptionsBase;
@@ -31,6 +34,8 @@
 import java.nio.file.FileSystems;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.util.Iterator;
+import java.util.List;
 
 /**
  * Entry-point for the command-line Xcode project generator.
@@ -63,7 +68,28 @@
       controlPb = Control.parseFrom(in);
     }
     Path pbxprojPath = fileSystem.getPath(controlPb.getPbxproj());
-    Path workspaceRoot = XcodeprojGeneration.workspaceRoot(controlPb, fileSystem);
+
+    Iterator<String> srcList = allSourceFilePaths(controlPb).iterator();
+    Path workspaceRoot;
+    if (!srcList.hasNext()) {
+      workspaceRoot = XcodeprojGeneration.relativeWorkspaceRoot(pbxprojPath);
+    } else {
+      // Get the absolute path to the workspace root.
+
+      // TODO(bazel-team): Remove this hack, possibly by converting Xcodegen to be run with
+      // "bazel run" and using RUNFILES to get the workspace root. For now, this is needed to work
+      // around Xcode's handling of symlinks not playing nicely with how Bazel stores output
+      // artifacts in /private/var/tmp. This means a relative path from .xcodeproj in bazel-out to
+      // the workspace root in .xcodeproj will not work properly at certain times during
+      // Xcode/xcodebuild execution. Walking up the path of a known source file prevents having
+      // to reason about a file that might only be accessible through a symlink, like a tools jar.
+      Path relSourceFilePath = fileSystem.getPath(srcList.next());
+      Path absSourceFilePath = relSourceFilePath.toAbsolutePath();
+      workspaceRoot = absSourceFilePath;
+      for (int i = 0; i < relSourceFilePath.getNameCount(); i++) {
+        workspaceRoot = workspaceRoot.getParent();
+      }
+    }
 
     try (OutputStream out = Files.newOutputStream(pbxprojPath)) {
       // This workspace root here is relative to the PWD, so that the .xccurrentversion
@@ -78,4 +104,14 @@
       XcodeprojGeneration.write(out, project);
     }
   }
+
+  private static Iterable<String> allSourceFilePaths(Control control) {
+    return Iterables.concat(
+        Iterables.transform(control.getTargetList(),
+                            new Function<TargetControl, List<String>>() {
+                              public List<String> apply(TargetControl tc) {
+                                return tc.getSourceFileList();
+                              }
+                            }));
+  }
 }
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 6c3176a..4534459 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
@@ -18,7 +18,6 @@
 import static com.google.common.base.Preconditions.checkState;
 
 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;
@@ -71,7 +70,6 @@
 import java.util.Collections;
 import java.util.EnumSet;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
@@ -544,45 +542,4 @@
 
     return project;
   }
-
-  /**
-   * Returns the workspace root for the project file.
-   */
-  public static Path workspaceRoot(Control control, FileSystem fileSystem) throws IOException {
-    Iterator<String> srcList = allSourceFilePaths(control).iterator();
-    Path workspaceRoot;
-    if (!srcList.hasNext()) {
-      Path pbxprojPath = fileSystem.getPath(control.getPbxproj());
-      return XcodeprojGeneration.relativeWorkspaceRoot(pbxprojPath);
-    } else {
-      // Get the absolute path to the workspace root.
-
-      // TODO(bazel-team): Remove this hack, possibly by converting Xcodegen to be run with
-      // "bazel run" and using RUNFILES to get the workspace root. For now, this is needed to work
-      // around Xcode's handling of symlinks not playing nicely with how Bazel stores output
-      // artifacts in /private/var/tmp. This means a relative path from .xcodeproj in bazel-out to
-      // the workspace root in .xcodeproj will not work properly at certain times during
-      // Xcode/xcodebuild execution. Walking up the path of a known source file prevents having
-      // to reason about a file that might only be accessible through a symlink, like a tools jar.
-      Path relSourceFilePath = fileSystem.getPath(srcList.next());
-
-      // Symlinks need to be resolved because XCode does not play well with symlinked sources.
-      Path absSourceFilePath = relSourceFilePath.toRealPath();
-      workspaceRoot = absSourceFilePath;
-      for (int i = 0; i < relSourceFilePath.getNameCount(); i++) {
-        workspaceRoot = workspaceRoot.getParent();
-      }
-      return workspaceRoot;
-    }
-  }
-
-  private static Iterable<String> allSourceFilePaths(Control control) {
-    return Iterables.concat(
-        Iterables.transform(control.getTargetList(),
-                            new Function<TargetControl, List<String>>() {
-                              public List<String> apply(TargetControl tc) {
-                                return tc.getSourceFileList();
-                              }
-                            }));
-  }
 }