diff options
author | Kristina Chodorow <kchodorow@google.com> | 2016-07-22 15:18:07 +0000 |
---|---|---|
committer | John Cater <jcater@google.com> | 2016-07-22 20:10:29 +0000 |
commit | 36a6c17629e76872a876cd313623246d4d0aa082 (patch) | |
tree | 0178e6b8487cfd00f7c7864f2c20620da3dbcb9d /src/main/java/com/google/devtools/build/lib/buildtool | |
parent | 4545ef538664563d284ceb7d19d6dc357497b2d0 (diff) |
Create a symlink with the right workspace name under the execroot
The execution root currently uses the basename of the workspace directory for
the workspace name, not the name in the WORKSPACE file. (For example, if our
sources were in /path/to/foo and our WORKSPACE file had workspace(name = "bar"),
our execution root would look like execroot/foo.)
This creates a symlink bar -> foo, so that accessing ../repo_name actually works
for the main repository.
RELNOTES[INC]: The main repository's execution root is under the main
repository's workspace name, not the source directory's basename. This shouldn't
have any effect on most builds, but it's possible it could break someone doing
weird things with paths in actions.
--
MOS_MIGRATED_REVID=128175455
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/buildtool')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java | 16 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/buildtool/SymlinkForest.java | 22 |
2 files changed, 29 insertions, 9 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java b/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java index 1f54bcc0b5..cf838bce49 100644 --- a/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java +++ b/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java @@ -51,7 +51,6 @@ import com.google.devtools.build.lib.actions.SimpleActionContextProvider; import com.google.devtools.build.lib.actions.SpawnActionContext; import com.google.devtools.build.lib.actions.TestExecException; import com.google.devtools.build.lib.actions.cache.ActionCache; -import com.google.devtools.build.lib.analysis.BuildView; import com.google.devtools.build.lib.analysis.BuildView.AnalysisResult; import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.SymlinkTreeActionContext; @@ -94,7 +93,6 @@ import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.ModifiedFileSet; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; - import java.io.IOException; import java.io.OutputStream; import java.io.PrintWriter; @@ -341,7 +339,7 @@ public class ExecutionTool { TopLevelArtifactContext topLevelArtifactContext) throws BuildFailedException, InterruptedException, TestExecException, AbruptExitException { Stopwatch timer = Stopwatch.createStarted(); - prepare(packageRoots); + prepare(packageRoots, analysisResult.getWorkspaceName()); ActionGraph actionGraph = analysisResult.getActionGraph(); @@ -363,9 +361,10 @@ public class ExecutionTool { if (targetConfigurations.size() == 1) { String productName = runtime.getProductName(); OutputDirectoryLinksUtils.createOutputDirectoryLinks( - env.getWorkspaceName(), env.getWorkspace(), getExecRoot(), - env.getOutputPath(), getReporter(), targetConfiguration, - request.getBuildOptions().getSymlinkPrefix(productName), productName); + env.getWorkspaceName(), env.getWorkspace(), + getExecRoot(), env.getOutputPath(), getReporter(), + targetConfiguration, request.getBuildOptions().getSymlinkPrefix(productName), + productName); } ActionCache actionCache = getActionCache(); @@ -499,7 +498,7 @@ public class ExecutionTool { } } - private void prepare(ImmutableMap<PackageIdentifier, Path> packageRoots) + private void prepare(ImmutableMap<PackageIdentifier, Path> packageRoots, String workspaceName) throws ExecutorInitException { // Prepare for build. Profiler.instance().markPhase(ProfilePhase.PREPARE); @@ -510,7 +509,8 @@ public class ExecutionTool { // Plant the symlink forest. try { new SymlinkForest( - packageRoots, getExecRoot(), runtime.getProductName()).plantSymlinkForest(); + packageRoots, getExecRoot(), runtime.getProductName(), workspaceName) + .plantSymlinkForest(); } catch (IOException e) { throw new ExecutorInitException("Source forest creation failed", e); } diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/SymlinkForest.java b/src/main/java/com/google/devtools/build/lib/buildtool/SymlinkForest.java index 5c8ff90565..9d57a44466 100644 --- a/src/main/java/com/google/devtools/build/lib/buildtool/SymlinkForest.java +++ b/src/main/java/com/google/devtools/build/lib/buildtool/SymlinkForest.java @@ -43,13 +43,16 @@ class SymlinkForest { private final ImmutableMap<PackageIdentifier, Path> packageRoots; private final Path workspace; + private final String workspaceName; private final String productName; private final String[] prefixes; SymlinkForest( - ImmutableMap<PackageIdentifier, Path> packageRoots, Path workspace, String productName) { + ImmutableMap<PackageIdentifier, Path> packageRoots, Path workspace, String productName, + String workspaceName) { this.packageRoots = packageRoots; this.workspace = workspace; + this.workspaceName = workspaceName; this.productName = productName; this.prefixes = new String[] { ".", "_", productName + "-"}; } @@ -216,6 +219,23 @@ class SymlinkForest { } } } + + symlinkCorrectWorkspaceName(); + } + + /** + * Right now, the execution root is under the basename of the source directory, not the name + * defined in the WORKSPACE file. Thus, this adds a symlink with the WORKSPACE's workspace name + * to the old-style execution root. + * TODO(kchodorow): get rid of this once exec root is always under the WORKSPACE's workspace + * name. + * @throws IOException + */ + private void symlinkCorrectWorkspaceName() throws IOException { + Path correctDirectory = workspace.getParentDirectory().getRelative(workspaceName); + if (!correctDirectory.exists()) { + correctDirectory.createSymbolicLink(workspace); + } } private static PackageIdentifier getParent(PackageIdentifier packageIdentifier) { |