diff options
author | 2018-06-12 14:14:35 -0700 | |
---|---|---|
committer | 2018-06-12 14:16:19 -0700 | |
commit | dba36c8bec353943fa91d60b5819642deaa53ead (patch) | |
tree | 0e939e1fb7d38f6db8b2fe445da3e85b55e903d7 /src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java | |
parent | 048405374ad2dd3e0b5deedeb4fdee897fa9ad88 (diff) |
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
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java | 16 |
1 files changed, 12 insertions, 4 deletions
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); |