Skip to content

Commit

Permalink
Move print_workspace_in_output_paths_if_needed to the graveyard.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 545423583
Change-Id: Id98baf7e962c17538a3bfef529f257fdec4bae29
  • Loading branch information
meisterT authored and copybara-github committed Jul 4, 2023
1 parent 67b71cd commit 228f1bf
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,14 @@ public static class BuildGraveyardOptions extends OptionsBase {
help = "Deprecated. No-op.",
deprecationWarning = "This option is now deprecated and is a no-op")
public boolean announce;

@Option(
name = "print_workspace_in_output_paths_if_needed",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
effectTags = {OptionEffectTag.TERMINAL_OUTPUT},
help = "Deprecated no-op.")
public boolean printWorkspaceInOutputPathsIfNeeded;
}

/** This is where deprecated Bazel-specific options only used by the build command go to die. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,19 +374,6 @@ public boolean useTopLevelTargetsForSymlinks() {
+ " This flag is not planned to be enabled by default, and should not be relied on.")
public boolean experimentalCreatePySymlinks;

@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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ private boolean outputTargets(
runtime.getRuleClassProvider().getSymlinkDefinitions(),
request.getBuildOptions().getSymlinkPrefix(productName),
productName,
env.getWorkspace(),
request.getBuildOptions().printWorkspaceInOutputPathsIfNeeded
? env.getWorkingDirectory()
: env.getWorkspace());
env.getWorkspace());
OutErr outErr = request.getOutErr();

// Splits aspects based on whether they are validation aspects.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,9 @@ public static PathPrettyPrinter getPathPrettyPrinter(
Iterable<SymlinkDefinition> symlinkDefinitions,
String symlinkPrefix,
String productName,
Path workspaceDirectory,
Path workingDirectory) {
Path workspaceDirectory) {
return new PathPrettyPrinter(
getAllLinkDefinitions(symlinkDefinitions),
symlinkPrefix,
productName,
workspaceDirectory,
workingDirectory);
getAllLinkDefinitions(symlinkDefinitions), symlinkPrefix, productName, workspaceDirectory);
}

private static void removeAllSymlinks(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public final class PathPrettyPrinter {
private final String symlinkPrefix;
private final String productName;
private final Path workspaceDirectory;
private final Path workingDirectory;

/**
* Creates a path pretty printer, immediately resolving the symlink definitions by reading the
Expand All @@ -39,12 +38,10 @@ public final class PathPrettyPrinter {
ImmutableList<SymlinkDefinition> symlinkDefinitions,
String symlinkPrefix,
String productName,
Path workspaceDirectory,
Path workingDirectory) {
Path workspaceDirectory) {
this.symlinkPrefix = symlinkPrefix;
this.productName = productName;
this.workspaceDirectory = workspaceDirectory;
this.workingDirectory = workingDirectory;
this.resolvedSymlinks = resolve(symlinkDefinitions);
}

Expand Down Expand Up @@ -87,11 +84,7 @@ public PathFragment getPrettyPath(PathFragment file) {
PathFragment linkFragment = e.getKey();
PathFragment linkTarget = e.getValue();
if (file.startsWith(linkTarget)) {
PathFragment outputLink =
workingDirectory.equals(workspaceDirectory)
? linkFragment
: workspaceDirectory.getRelative(linkFragment).asFragment();
return outputLink.getRelative(file.relativeTo(linkTarget));
return linkFragment.getRelative(file.relativeTo(linkTarget));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,10 +622,7 @@ private static void constructCommandLine(
runtime.getRuleClassProvider().getSymlinkDefinitions(),
requestOptions.getSymlinkPrefix(productName),
productName,
env.getWorkspace(),
requestOptions.printWorkspaceInOutputPathsIfNeeded
? env.getWorkingDirectory()
: env.getWorkspace());
env.getWorkspace());
PathFragment prettyExecutablePath =
prettyPrinter.getPrettyPath(executable.getPath().asFragment());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ private static TestLogPathFormatter makeTestLogPathFormatter(
runtime.getRuleClassProvider().getSymlinkDefinitions(),
requestOptions.getSymlinkPrefix(productName),
productName,
env.getWorkspace(),
env.getWorkspace());
return path -> pathPrettyPrinter.getPrettyPath(path.asFragment()).getPathString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,156 +202,6 @@ public void testFailedTargetWithSaveTemps() throws Exception {
assertThat(stderr).contains("See temp at blaze-bin/bad_clib/_objs/bad_clib/badlib.pic.ii\n");
}

@Test
public void testSymlinkOutputAtCwdUnderWorkspace_withFlagOn() throws Exception {
write("my_clib/BUILD", "cc_library(name='my_clib', srcs=['myclib.cc'])\n");
write("my_clib/myclib.cc", "void f() {}");

addOptions(
"--print_workspace_in_output_paths_if_needed",
"--client_cwd=" + getWorkspace().getChild("my_clib").getPathString());
build(false, "no-error", "//my_clib");

String stderr = recOutErr.errAsLatin1();
assertThat(stderr).contains("Target //my_clib:my_clib up-to-date:\n");
assertThat(stderr)
.contains(getWorkspace().getRelative("blaze-bin/my_clib/libmy_clib.so") + "\n");
assertThat(stderr)
.contains(getWorkspace().getRelative("blaze-bin/my_clib/libmy_clib.a") + "\n");
}

@Test
public void testSymlinkOutputAtCwdUnderWorkspace_withFlagOff() throws Exception {
write("my_clib/BUILD", "cc_library(name='my_clib', srcs=['myclib.cc'])\n");
write("my_clib/myclib.cc", "void f() {}");

addOptions(
"--noprint_workspace_in_output_paths_if_needed",
"--client_cwd=" + getWorkspace().getChild("my_clib").getPathString());
build(false, "no-error", "//my_clib");

String stderr = recOutErr.errAsLatin1();
assertThat(stderr).contains("Target //my_clib:my_clib up-to-date:\n");
assertThat(stderr)
.doesNotContain(getWorkspace().getRelative("blaze-bin/my_clib/libmy_clib.so") + "\n");
assertThat(stderr)
.doesNotContain(getWorkspace().getRelative("blaze-bin/my_clib/libmy_clib.a") + "\n");
assertThat(stderr).contains("blaze-bin/my_clib/libmy_clib.so\n");
assertThat(stderr).contains("blaze-bin/my_clib/libmy_clib.a\n");
}

@Test
public void testSymlinkOutputAtCwdEqualWorkspace_withFlagOn() throws Exception {
write("my_clib/BUILD", "cc_library(name='my_clib', srcs=['myclib.cc'])\n");
write("my_clib/myclib.cc", "void f() {}");

addOptions("--print_workspace_in_output_paths_if_needed");
build(false, "no-error", "//my_clib");

String stderr = recOutErr.errAsLatin1();
assertThat(stderr).contains("Target //my_clib:my_clib up-to-date:\n");
assertThat(stderr)
.doesNotContain(getWorkspace().getRelative("blaze-bin/my_clib/libmy_clib.so") + "\n");
assertThat(stderr)
.doesNotContain(getWorkspace().getRelative("blaze-bin/my_clib/libmy_clib.a") + "\n");
assertThat(stderr).contains("blaze-bin/my_clib/libmy_clib.so\n");
assertThat(stderr).contains("blaze-bin/my_clib/libmy_clib.a\n");
}

@Test
public void testSymlinkPrefixAtCwdEqualWorkspace_withFlagOff() throws Exception {
write("my_clib/BUILD", "cc_library(name='my_clib', srcs=['myclib.cc'])\n");
write("my_clib/myclib.cc", "void f() {}");

addOptions("--noprint_workspace_in_output_paths_if_needed");
build(false, "no-error", "//my_clib");

String stderr = recOutErr.errAsLatin1();
assertThat(stderr).contains("Target //my_clib:my_clib up-to-date:\n");
assertThat(stderr)
.doesNotContain(getWorkspace().getRelative("blaze-bin/my_clib/libmy_clib.so") + "\n");
assertThat(stderr)
.doesNotContain(getWorkspace().getRelative("blaze-bin/my_clib/libmy_clib.a") + "\n");
assertThat(stderr).contains("blaze-bin/my_clib/libmy_clib.so\n");
assertThat(stderr).contains("blaze-bin/my_clib/libmy_clib.a\n");
}

@Test
public void testSeeTempAtCwdUnderWorkspace_withFlagOn() throws Exception {
write("bad_clib/BUILD", "cc_library(name='bad_clib', srcs=['badlib.cc'])\n");
// trigger a warning to make the build fail:
// "control reaches end of non-void function [-Werror,-Wreturn-type]"
write("bad_clib/badlib.cc", "int f() { }");

// We need to set --keep_going so that the temps get built even though the compilation fails.
addOptions(
"--save_temps",
"--keep_going",
"--print_workspace_in_output_paths_if_needed",
"--client_cwd=" + getWorkspace().getChild("bad_clib").getPathString());
build(true, "compilation of rule '//bad_clib:bad_clib' failed", "//bad_clib");

String stderr = recOutErr.errAsLatin1();
assertThat(stderr).contains("Target //bad_clib:bad_clib failed to build");
assertThat(stderr)
.contains(
"See temp at "
+ getWorkspace().getRelative("blaze-bin/bad_clib/_objs/bad_clib/badlib.pic.ii")
+ "\n");
}

@Test
public void testSeeTempAtCwdUnderWorkspace_withFlagOff() throws Exception {
write("bad_clib/BUILD", "cc_library(name='bad_clib', srcs=['badlib.cc'])\n");
// trigger a warning to make the build fail:
// "control reaches end of non-void function [-Werror,-Wreturn-type]"
write("bad_clib/badlib.cc", "int f() { }");

// We need to set --keep_going so that the temps get built even though the compilation fails.
addOptions(
"--save_temps",
"--keep_going",
"--noprint_workspace_in_output_paths_if_needed",
"--client_cwd=" + getWorkspace().getChild("bad_clib").getPathString());
build(true, "compilation of rule '//bad_clib:bad_clib' failed", "//bad_clib");

String stderr = recOutErr.errAsLatin1();
assertThat(stderr).contains("Target //bad_clib:bad_clib failed to build");
assertThat(stderr).contains("See temp at blaze-bin/bad_clib/_objs/bad_clib/badlib.pic.ii\n");
}

@Test
public void testSeeTempAtCwdEqualWorkspace_withFlagOn() throws Exception {
write("bad_clib/BUILD", "cc_library(name='bad_clib', srcs=['badlib.cc'])\n");
// trigger a warning to make the build fail:
// "control reaches end of non-void function [-Werror,-Wreturn-type]"
write("bad_clib/badlib.cc", "int f() { }");

// We need to set --keep_going so that the temps get built even though the compilation fails.
addOptions("--save_temps", "--keep_going", "--print_workspace_in_output_paths_if_needed");
build(true, "compilation of rule '//bad_clib:bad_clib' failed", "//bad_clib");

String stderr = recOutErr.errAsLatin1();
assertThat(stderr).contains("Target //bad_clib:bad_clib failed to build");
assertThat(stderr).contains("See temp at blaze-bin/bad_clib/_objs/bad_clib/badlib.pic.ii\n");
}

@Test
public void testSeeTempAtCwdEqualWorkspace_withFlagOff() throws Exception {
write("bad_clib/BUILD", "cc_library(name='bad_clib', srcs=['badlib.cc'])\n");
// trigger a warning to make the build fail:
// "control reaches end of non-void function [-Werror,-Wreturn-type]"
write("bad_clib/badlib.cc", "int f() { }");

// We need to set --keep_going so that the temps get built even though the compilation fails.
addOptions("--save_temps", "--keep_going", "--noprint_workspace_in_output_paths_if_needed");
build(true, "compilation of rule '//bad_clib:bad_clib' failed", "//bad_clib");

String stderr = recOutErr.errAsLatin1();
assertThat(stderr).contains("Target //bad_clib:bad_clib failed to build");
assertThat(stderr).contains("See temp at blaze-bin/bad_clib/_objs/bad_clib/badlib.pic.ii\n");
}

// Concrete implementations of this abstract test:

/** Tests with 1 job. */
Expand Down

0 comments on commit 228f1bf

Please sign in to comment.