aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/buildtool
diff options
context:
space:
mode:
authorGravatar mstaib <mstaib@google.com>2018-06-12 14:14:35 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-06-12 14:16:19 -0700
commitdba36c8bec353943fa91d60b5819642deaa53ead (patch)
tree0e939e1fb7d38f6db8b2fe445da3e85b55e903d7 /src/main/java/com/google/devtools/build/lib/buildtool
parent048405374ad2dd3e0b5deedeb4fdee897fa9ad88 (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/buildtool')
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildtool/BuildRequestOptions.java15
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildtool/BuildResultPrinter.java16
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildtool/OutputDirectoryLinksUtils.java33
3 files changed, 52 insertions, 12 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/BuildRequestOptions.java b/src/main/java/com/google/devtools/build/lib/buildtool/BuildRequestOptions.java
index f5701cb5d0..858930ae20 100644
--- a/src/main/java/com/google/devtools/build/lib/buildtool/BuildRequestOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/buildtool/BuildRequestOptions.java
@@ -367,6 +367,21 @@ public class BuildRequestOptions extends OptionsBase {
}
@Option(
+ name = "print_workspace_in_output_paths_if_needed",
+ defaultValue = "false",
+ documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
+ effectTags = {OptionEffectTag.TERMINAL_OUTPUT},
+ help =
+ "If enabled, when the current working directory is deeper than the workspace (for example, "
+ + "when running from <workspace>/foo instead of <workspace>), printed output paths "
+ + "include the absolute path to the workspace (for example, "
+ + "<workspace>/<symlink_prefix>-bin/foo/binary instead of "
+ + "<symlink_prefix>-bin/foo/binary)."
+ )
+ public boolean printWorkspaceInOutputPathsIfNeeded;
+
+
+ @Option(
name = "use_action_cache",
defaultValue = "true",
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/BuildResultPrinter.java b/src/main/java/com/google/devtools/build/lib/buildtool/BuildResultPrinter.java
index 005b1858a3..133588792e 100644
--- a/src/main/java/com/google/devtools/build/lib/buildtool/BuildResultPrinter.java
+++ b/src/main/java/com/google/devtools/build/lib/buildtool/BuildResultPrinter.java
@@ -123,6 +123,9 @@ class BuildResultPrinter {
temp.getPath(),
env.getWorkspaceName(),
env.getWorkspace(),
+ request.getBuildOptions().printWorkspaceInOutputPathsIfNeeded
+ ? env.getWorkingDirectory()
+ : env.getWorkspace(),
request.getBuildOptions().getSymlinkPrefix(productName),
productName));
}
@@ -181,9 +184,16 @@ class BuildResultPrinter {
private String formatArtifactForShowResults(Artifact artifact, BuildRequest request) {
String productName = env.getRuntime().getProductName();
- return " " + OutputDirectoryLinksUtils.getPrettyPath(artifact.getPath(),
- env.getWorkspaceName(), env.getWorkspace(),
- request.getBuildOptions().getSymlinkPrefix(productName), productName);
+ return " "
+ + OutputDirectoryLinksUtils.getPrettyPath(
+ artifact.getPath(),
+ env.getWorkspaceName(),
+ env.getWorkspace(),
+ request.getBuildOptions().printWorkspaceInOutputPathsIfNeeded
+ ? env.getWorkingDirectory()
+ : env.getWorkspace(),
+ request.getBuildOptions().getSymlinkPrefix(productName),
+ productName);
}
/**
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/OutputDirectoryLinksUtils.java b/src/main/java/com/google/devtools/build/lib/buildtool/OutputDirectoryLinksUtils.java
index 2cfd532b8a..7917087735 100644
--- a/src/main/java/com/google/devtools/build/lib/buildtool/OutputDirectoryLinksUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/buildtool/OutputDirectoryLinksUtils.java
@@ -150,34 +150,44 @@ public class OutputDirectoryLinksUtils {
/**
* Returns a convenient path to the specified file, relativizing it and using output-dir symlinks
- * if possible. Otherwise, return a path relative to the workspace directory if possible.
+ * if possible. Otherwise, return a path relative to the workspace directory if possible.
* Otherwise, return the absolute path.
*
* <p>This method must be called after the symlinks are created at the end of a build. If called
* before, the pretty path may be incorrect if the symlinks end up pointing somewhere new.
*/
- public static PathFragment getPrettyPath(Path file, String workspaceName,
- Path workspaceDirectory, String symlinkPrefix, String productName) {
+ public static PathFragment getPrettyPath(
+ Path file,
+ String workspaceName,
+ Path workspaceDirectory,
+ Path workingDirectory,
+ String symlinkPrefix,
+ String productName) {
if (NO_CREATE_SYMLINKS_PREFIX.equals(symlinkPrefix)) {
return file.asFragment();
}
for (String link : LINKS) {
- PathFragment result = relativize(file, workspaceDirectory, symlinkPrefix + link);
+ PathFragment result =
+ relativize(file, workspaceDirectory, workingDirectory, symlinkPrefix + link);
if (result != null) {
return result;
}
}
- PathFragment result = relativize(file, workspaceDirectory,
- execRootSymlink(symlinkPrefix, workspaceName));
+ PathFragment result =
+ relativize(
+ file,
+ workspaceDirectory,
+ workingDirectory,
+ execRootSymlink(symlinkPrefix, workspaceName));
if (result != null) {
return result;
}
ImmutableList<String> outputSymlinkNames = getOutputSymlinkNames(productName, symlinkPrefix);
checkArgument(!outputSymlinkNames.isEmpty());
- result = relativize(file, workspaceDirectory, outputSymlinkNames.get(0));
+ result = relativize(file, workspaceDirectory, workingDirectory, outputSymlinkNames.get(0));
if (result != null) {
return result;
}
@@ -187,14 +197,19 @@ public class OutputDirectoryLinksUtils {
// Helper to getPrettyPath. Returns file, relativized w.r.t. the referent of
// "linkname", or null if it was a not a child.
- private static PathFragment relativize(Path file, Path workspaceDirectory, String linkname) {
+ private static PathFragment relativize(
+ Path file, Path workspaceDirectory, Path workingDirectory, String linkname) {
PathFragment link = PathFragment.create(linkname);
try {
Path dir = workspaceDirectory.getRelative(link);
PathFragment levelOneLinkTarget = dir.readSymbolicLink();
if (levelOneLinkTarget.isAbsolute() &&
file.startsWith(dir = file.getRelative(levelOneLinkTarget))) {
- return link.getRelative(file.relativeTo(dir));
+ PathFragment outputLink =
+ workingDirectory.equals(workspaceDirectory)
+ ? link
+ : workspaceDirectory.getRelative(link).asFragment();
+ return outputLink.getRelative(file.relativeTo(dir));
}
} catch (IOException e) {
/* ignore */