aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc_tools
diff options
context:
space:
mode:
authorGravatar Rumou Duan <rduan@google.com>2015-05-21 21:23:18 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2015-05-22 19:59:32 +0000
commit53c074822d3d4275528b7dbd8cb634deb7817580 (patch)
treecedb6ed0d15bacd869f52348a60a0eea24504553 /src/objc_tools
parent512e91f288ca15197474adcc3dfe1a7a2a28203c (diff)
*** 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
Diffstat (limited to 'src/objc_tools')
-rw-r--r--src/objc_tools/xcodegen/java/com/google/devtools/build/xcode/xcodegen/XcodeGen.java38
-rw-r--r--src/objc_tools/xcodegen/java/com/google/devtools/build/xcode/xcodegen/XcodeprojGeneration.java43
2 files changed, 37 insertions, 44 deletions
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 b50ea30aa4..31d18d4f3c 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.FileSystem;
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 @@ public class XcodeGen {
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 @@ public class XcodeGen {
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 6c3176adb7..4534459371 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.checkArgument;
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.nio.file.Paths;
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 @@ public class XcodeprojGeneration {
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();
- }
- }));
- }
}