Skip to content

Commit 2202109

Browse files
committed
Automated [] rollback of commit feee070.
*** Reason for rollback *** Breaks //src/test/shell/bazel:bazel_sandboxing_test: http://ci.bazel.io/job/bazel-tests/lastCompletedBuild/BAZEL_VERSION=latest-jdk7,PLATFORM_NAME=linux-x86_64/testReport/(root)/(empty)/test_failing_action_with_ioexception_while_copying_outputs_throws_correct_exception/ *** Original change description *** Gives 3 levels of sandbox error message under different flags. 1. no flag: only the direct reason is given (command execution termination status), and also the instruction to use "--verbose_failures" 2. flag "--verbose_failures": gives failed execution command and the instruction to use "--sandbox_debug --strategy" 3. flag "--verbose_failures --sandbox_debug": gives failed execution command, debugging message from sandboxing, and the instruction to use "--strategy" Also removes "cd <sandbox_... *** ROLLBACK_OF=143937589 -- PiperOrigin-RevId: 143951901 MOS_MIGRATED_REVID=143951901
1 parent 28fbf48 commit 2202109

File tree

6 files changed

+20
-48
lines changed

6 files changed

+20
-48
lines changed

src/main/java/com/google/devtools/build/lib/sandbox/DarwinSandboxRunner.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
package com.google.devtools.build.lib.sandbox;
1616

17-
import static java.nio.charset.StandardCharsets.UTF_8;
18-
1917
import com.google.common.collect.ImmutableMap;
2018
import com.google.common.io.ByteStreams;
2119
import com.google.devtools.build.lib.shell.Command;
@@ -24,10 +22,8 @@
2422
import com.google.devtools.build.lib.shell.TimeoutKillableObserver;
2523
import com.google.devtools.build.lib.util.OS;
2624
import com.google.devtools.build.lib.vfs.Path;
27-
import java.io.BufferedWriter;
2825
import java.io.File;
2926
import java.io.IOException;
30-
import java.io.OutputStreamWriter;
3127
import java.io.PrintWriter;
3228
import java.util.ArrayList;
3329
import java.util.List;
@@ -54,7 +50,7 @@ final class DarwinSandboxRunner extends SandboxRunner {
5450
Set<Path> inaccessiblePaths,
5551
Path runUnderPath,
5652
boolean verboseFailures) {
57-
super(verboseFailures);
53+
super(sandboxExecRoot, verboseFailures);
5854
this.sandboxExecRoot = sandboxExecRoot;
5955
this.argumentsFilePath = sandboxPath.getRelative("sandbox.sb");
6056
this.writableDirs = writableDirs;
@@ -121,10 +117,7 @@ protected Command getCommand(
121117
}
122118

123119
private void writeConfig(boolean allowNetwork) throws IOException {
124-
try (PrintWriter out =
125-
new PrintWriter(
126-
new BufferedWriter(
127-
new OutputStreamWriter(argumentsFilePath.getOutputStream(), UTF_8)))) {
120+
try (PrintWriter out = new PrintWriter(argumentsFilePath.getOutputStream())) {
128121
// Note: In Apple's sandbox configuration language, the *last* matching rule wins.
129122
out.println("(version 1)");
130123
out.println("(debug deny)");

src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ final class LinuxSandboxRunner extends SandboxRunner {
6060
Map<Path, Path> bindMounts,
6161
boolean verboseFailures,
6262
boolean sandboxDebug) {
63-
super(verboseFailures);
63+
super(sandboxExecRoot, verboseFailures);
6464
this.execRoot = execRoot;
6565
this.sandboxExecRoot = sandboxExecRoot;
6666
this.sandboxTempDir = sandboxTempDir;

src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private SandboxRunner getSandboxRunner(
167167
verboseFailures,
168168
sandboxOptions.sandboxDebug);
169169
} else {
170-
return new ProcessWrapperRunner(execRoot, sandboxExecRoot, verboseFailures);
170+
return new ProcessWrapperRunner(execRoot, sandboxPath, sandboxExecRoot, verboseFailures);
171171
}
172172
}
173173

src/main/java/com/google/devtools/build/lib/sandbox/ProcessWrapperRunner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ final class ProcessWrapperRunner extends SandboxRunner {
3232
private final Path sandboxExecRoot;
3333

3434
ProcessWrapperRunner(
35-
Path execRoot, Path sandboxExecRoot, boolean verboseFailures) {
36-
super(verboseFailures);
35+
Path execRoot, Path sandboxPath, Path sandboxExecRoot, boolean verboseFailures) {
36+
super(sandboxExecRoot, verboseFailures);
3737
this.execRoot = execRoot;
3838
this.sandboxExecRoot = sandboxExecRoot;
3939
}

src/main/java/com/google/devtools/build/lib/sandbox/SandboxRunner.java

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.google.devtools.build.lib.shell.TerminationStatus;
2424
import com.google.devtools.build.lib.util.CommandFailureUtils;
2525
import com.google.devtools.build.lib.util.io.OutErr;
26+
import com.google.devtools.build.lib.vfs.Path;
2627
import java.io.IOException;
2728
import java.util.Arrays;
2829
import java.util.List;
@@ -31,12 +32,11 @@
3132
/** A common interface of all sandbox runners, no matter which platform they're working on. */
3233
abstract class SandboxRunner {
3334

34-
private static final String SANDBOX_DEBUG_SUGGESTION =
35-
"\n\nUse --sandbox_debug to see verbose messages from the sandbox";
36-
3735
private final boolean verboseFailures;
36+
private final Path sandboxExecRoot;
3837

39-
SandboxRunner(boolean verboseFailures) {
38+
SandboxRunner(Path sandboxExecRoot, boolean verboseFailures) {
39+
this.sandboxExecRoot = sandboxExecRoot;
4040
this.verboseFailures = verboseFailures;
4141
}
4242

@@ -48,15 +48,13 @@ abstract class SandboxRunner {
4848
* @param outErr - error output to capture sandbox's and command's stderr
4949
* @param timeout - after how many seconds should the process be killed
5050
* @param allowNetwork - whether networking should be allowed for the process
51-
* @param sandboxDebug - whether debugging message should be printed
5251
*/
5352
void run(
5453
List<String> arguments,
5554
Map<String, String> environment,
5655
OutErr outErr,
5756
int timeout,
58-
boolean allowNetwork,
59-
boolean sandboxDebug)
57+
boolean allowNetwork)
6058
throws ExecException {
6159
Command cmd;
6260
try {
@@ -65,7 +63,6 @@ void run(
6563
throw new UserExecException("I/O error during sandboxed execution", e);
6664
}
6765

68-
TerminationStatus status = null;
6966
try {
7067
cmd.execute(
7168
/* stdin */ new byte[] {},
@@ -76,28 +73,17 @@ void run(
7673
} catch (CommandException e) {
7774
boolean timedOut = false;
7875
if (e instanceof AbnormalTerminationException) {
79-
status = ((AbnormalTerminationException) e).getResult().getTerminationStatus();
76+
TerminationStatus status =
77+
((AbnormalTerminationException) e).getResult().getTerminationStatus();
8078
timedOut = !status.exited() && (status.getTerminatingSignal() == getSignalOnTimeout());
8179
}
82-
String statusMessage = status + " [sandboxed]";
83-
if (!verboseFailures) {
84-
// simplest error message
85-
throw new UserExecException(statusMessage);
86-
}
87-
List<String> commandList;
88-
if (!sandboxDebug) {
89-
commandList = arguments;
90-
} else {
91-
commandList = Arrays.asList(cmd.getCommandLineElements());
92-
}
93-
String commandFailureMessage =
80+
String message =
9481
CommandFailureUtils.describeCommandFailure(
95-
true,
96-
commandList,
82+
verboseFailures,
83+
Arrays.asList(cmd.getCommandLineElements()),
9784
environment,
98-
null)
99-
+ (sandboxDebug ? "" : SANDBOX_DEBUG_SUGGESTION);
100-
throw new UserExecException(commandFailureMessage, e, timedOut);
85+
sandboxExecRoot.getPathString());
86+
throw new UserExecException(message, e, timedOut);
10187
}
10288
}
10389

src/main/java/com/google/devtools/build/lib/sandbox/SandboxStrategy.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import com.google.devtools.build.lib.buildtool.BuildRequest;
2929
import com.google.devtools.build.lib.events.Event;
3030
import com.google.devtools.build.lib.events.EventHandler;
31-
import com.google.devtools.build.lib.util.io.OutErr;
3231
import com.google.devtools.build.lib.vfs.Path;
3332
import com.google.devtools.build.lib.vfs.PathFragment;
3433
import java.io.IOException;
@@ -70,15 +69,13 @@ protected void runSpawn(
7069
throws ExecException, InterruptedException {
7170
EventHandler eventHandler = actionExecutionContext.getExecutor().getEventHandler();
7271
ExecException execException = null;
73-
OutErr outErr = actionExecutionContext.getFileOutErr();
7472
try {
7573
runner.run(
7674
spawn.getArguments(),
7775
spawnEnvironment,
78-
outErr,
76+
actionExecutionContext.getFileOutErr(),
7977
Spawns.getTimeoutSeconds(spawn),
80-
SandboxHelpers.shouldAllowNetwork(buildRequest, spawn),
81-
sandboxOptions.sandboxDebug);
78+
SandboxHelpers.shouldAllowNetwork(buildRequest, spawn));
8279
} catch (ExecException e) {
8380
execException = e;
8481
}
@@ -105,10 +102,6 @@ protected void runSpawn(
105102
}
106103

107104
if (execException != null) {
108-
outErr.printErr(
109-
"Use --strategy="
110-
+ spawn.getMnemonic()
111-
+ "=standalone to disable sandboxing for the failing actions.\n");
112105
throw execException;
113106
}
114107
}

0 commit comments

Comments
 (0)