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 | |
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')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java | 16 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java | 18 |
2 files changed, 24 insertions, 10 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); diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java index 25fd5f2432..7acf1c7304 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java @@ -186,13 +186,19 @@ public class RunCommand implements BlazeCommand { String productName = env.getRuntime().getProductName(); Artifact executable = targetToRun.getProvider(FilesToRunProvider.class).getExecutable(); + BuildRequestOptions requestOptions = env.getOptions().getOptions(BuildRequestOptions.class); + PathFragment executablePath = executable.getPath().asFragment(); - PathFragment prettyExecutablePath = OutputDirectoryLinksUtils.getPrettyPath( - executable.getPath(), - env.getWorkspaceName(), - env.getWorkspace(), - env.getOptions().getOptions(BuildRequestOptions.class).getSymlinkPrefix(productName), - productName); + PathFragment prettyExecutablePath = + OutputDirectoryLinksUtils.getPrettyPath( + executable.getPath(), + env.getWorkspaceName(), + env.getWorkspace(), + requestOptions.printWorkspaceInOutputPathsIfNeeded + ? env.getWorkingDirectory() + : env.getWorkspace(), + requestOptions.getSymlinkPrefix(productName), + productName); RunUnder runUnder = env.getOptions().getOptions(BuildConfiguration.Options.class).runUnder; // Insert the command prefix specified by the "--run_under=<command-prefix>" option |