Print interactive sandboxed shell command with `--sandbox_debug`
The `--sandbox_debug` output for the Linux sandbox now also contains a copyable command that drops the user into an interactive shell in an identical sandboxed environment. This is in particular meant to address the increased complexity of the bind mount structure incurred by the flip of `--incompatible_sandbox_hermetic_tmp`.
Closes #20708.
PiperOrigin-RevId: 595457357
Change-Id: I6dfd410895b93fce67b9666c76c5f7757e77dc3a
diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxCommandLineBuilder.java b/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxCommandLineBuilder.java
index cf80265..967c08b 100644
--- a/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxCommandLineBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxCommandLineBuilder.java
@@ -51,7 +51,6 @@
}
private final Path linuxSandboxPath;
- private final List<String> commandArguments;
private Path hermeticSandboxPath;
private Path workingDirectory;
private Duration timeout;
@@ -72,15 +71,13 @@
private boolean sigintSendsSigterm = false;
private String cgroupsDir;
- private LinuxSandboxCommandLineBuilder(Path linuxSandboxPath, List<String> commandArguments) {
+ private LinuxSandboxCommandLineBuilder(Path linuxSandboxPath) {
this.linuxSandboxPath = linuxSandboxPath;
- this.commandArguments = commandArguments;
}
/** Returns a new command line builder for the {@code linux-sandbox} tool. */
- public static LinuxSandboxCommandLineBuilder commandLineBuilder(
- Path linuxSandboxPath, List<String> commandArguments) {
- return new LinuxSandboxCommandLineBuilder(linuxSandboxPath, commandArguments);
+ public static LinuxSandboxCommandLineBuilder commandLineBuilder(Path linuxSandboxPath) {
+ return new LinuxSandboxCommandLineBuilder(linuxSandboxPath);
}
/**
@@ -247,7 +244,7 @@
}
/** Builds the command line to invoke a specific command using the {@code linux-sandbox} tool. */
- public ImmutableList<String> build() {
+ public ImmutableList<String> buildForCommand(List<String> commandArguments) {
Preconditions.checkState(
!(this.useFakeUsername && this.useFakeRoot),
"useFakeUsername and useFakeRoot are exclusive");