From dba36c8bec353943fa91d60b5819642deaa53ead Mon Sep 17 00:00:00 2001 From: mstaib Date: Tue, 12 Jun 2018 14:14:35 -0700 Subject: Add --print_workspace_in_output_paths_if_needed flag. When this flag is turned on, and the user's working directory is beneath the workspace (but is not the workspace itself), the workspace's absolute path is printed as a prefix to the convenience symlink. With this flag off, the displayed convenience symlink path is always relative to the user's workspace, even if that isn't the current working directory. (This is the current behavior.) The new (flag-on) behavior will become default soon, and then this flag will be removed. RELNOTES: None. PiperOrigin-RevId: 200278355 --- .../devtools/build/lib/runtime/CommandEnvironment.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java') diff --git a/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java b/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java index 32d31a2979..3870931203 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.runtime; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.eventbus.EventBus; import com.google.devtools.build.lib.actions.PackageRootResolver; @@ -146,7 +147,7 @@ public final class CommandEnvironment { // TODO(ulfjack): We don't call beforeCommand() in tests, but rely on workingDirectory being set // in setupPackageCache(). This leads to NPE if we don't set it here. - this.workingDirectory = directories.getWorkspace(); + this.setWorkingDirectory(directories.getWorkspace()); this.workspaceName = null; workspace.getSkyframeExecutor().setEventBus(eventBus); @@ -554,8 +555,16 @@ public final class CommandEnvironment { return commandStartTime; } - void setWorkingDirectory(Path workingDirectory) { + @VisibleForTesting + public void setWorkingDirectoryForTesting(Path workingDirectory) { + setWorkingDirectory(workingDirectory); + } + + private void setWorkingDirectory(Path workingDirectory) { this.workingDirectory = workingDirectory; + if (getWorkspace() != null) { + this.relativeWorkingDirectory = workingDirectory.relativeTo(getWorkspace()); + } } /** @@ -608,8 +617,7 @@ public final class CommandEnvironment { workspace = FileSystemUtils.getWorkingDirectory(getRuntime().getFileSystem()); workingDirectory = workspace; } - this.relativeWorkingDirectory = workingDirectory.relativeTo(workspace); - this.workingDirectory = workingDirectory; + this.setWorkingDirectory(workingDirectory); // Fail fast in the case where a Blaze command forgets to install the package path correctly. skyframeExecutor.setActive(false); -- cgit v1.2.3