diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/sandbox/SandboxRunner.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/sandbox/SandboxRunner.java | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/SandboxRunner.java b/src/main/java/com/google/devtools/build/lib/sandbox/SandboxRunner.java index b20da1bd0c..aa9334cbb2 100644 --- a/src/main/java/com/google/devtools/build/lib/sandbox/SandboxRunner.java +++ b/src/main/java/com/google/devtools/build/lib/sandbox/SandboxRunner.java @@ -23,7 +23,6 @@ import com.google.devtools.build.lib.shell.KillableObserver; import com.google.devtools.build.lib.shell.TerminationStatus; import com.google.devtools.build.lib.util.CommandFailureUtils; import com.google.devtools.build.lib.util.io.OutErr; -import com.google.devtools.build.lib.vfs.Path; import java.io.IOException; import java.util.Arrays; import java.util.List; @@ -32,11 +31,12 @@ import java.util.Map; /** A common interface of all sandbox runners, no matter which platform they're working on. */ abstract class SandboxRunner { + private static final String SANDBOX_DEBUG_SUGGESTION = + "\n\nUse --sandbox_debug to see verbose messages from the sandbox"; + private final boolean verboseFailures; - private final Path sandboxExecRoot; - SandboxRunner(Path sandboxExecRoot, boolean verboseFailures) { - this.sandboxExecRoot = sandboxExecRoot; + SandboxRunner(boolean verboseFailures) { this.verboseFailures = verboseFailures; } @@ -48,13 +48,15 @@ abstract class SandboxRunner { * @param outErr - error output to capture sandbox's and command's stderr * @param timeout - after how many seconds should the process be killed * @param allowNetwork - whether networking should be allowed for the process + * @param sandboxDebug - whether debugging message should be printed */ void run( List<String> arguments, Map<String, String> environment, OutErr outErr, int timeout, - boolean allowNetwork) + boolean allowNetwork, + boolean sandboxDebug) throws ExecException { Command cmd; try { @@ -63,6 +65,7 @@ abstract class SandboxRunner { throw new UserExecException("I/O error during sandboxed execution", e); } + TerminationStatus status = null; try { cmd.execute( /* stdin */ new byte[] {}, @@ -73,17 +76,28 @@ abstract class SandboxRunner { } catch (CommandException e) { boolean timedOut = false; if (e instanceof AbnormalTerminationException) { - TerminationStatus status = - ((AbnormalTerminationException) e).getResult().getTerminationStatus(); + status = ((AbnormalTerminationException) e).getResult().getTerminationStatus(); timedOut = !status.exited() && (status.getTerminatingSignal() == getSignalOnTimeout()); } - String message = + String statusMessage = status + " [sandboxed]"; + if (!verboseFailures) { + // simplest error message + throw new UserExecException(statusMessage); + } + List<String> commandList; + if (!sandboxDebug) { + commandList = arguments; + } else { + commandList = Arrays.asList(cmd.getCommandLineElements()); + } + String commandFailureMessage = CommandFailureUtils.describeCommandFailure( - verboseFailures, - Arrays.asList(cmd.getCommandLineElements()), + true, + commandList, environment, - sandboxExecRoot.getPathString()); - throw new UserExecException(message, e, timedOut); + null) + + (sandboxDebug ? "" : SANDBOX_DEBUG_SUGGESTION); + throw new UserExecException(commandFailureMessage, e, timedOut); } } |