aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google
diff options
context:
space:
mode:
authorGravatar Philipp Wollermann <philwo@google.com>2015-11-04 18:13:06 +0000
committerGravatar John Field <jfield@google.com>2015-11-05 16:49:29 +0000
commit53856cb4ae007ac347a3587e90d4c106e49777bc (patch)
tree91f0cf37c502320eec06813689e6389a2be990ff /src/main/java/com/google
parentaf33c67de5015fdfbb92d3ca6d5c99508540cb01 (diff)
workers: Put command-line arguments into the WorkRequest instead of passing the @flagfile.
Note that this does not resolve recursive @flagfile inclusion in the args if they're present. -- MOS_MIGRATED_REVID=107052447
Diffstat (limited to 'src/main/java/com/google')
-rw-r--r--src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnStrategy.java43
1 files changed, 34 insertions, 9 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnStrategy.java b/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnStrategy.java
index f143ab6576..397e08d06b 100644
--- a/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnStrategy.java
+++ b/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnStrategy.java
@@ -13,6 +13,8 @@
// limitations under the License.
package com.google.devtools.build.lib.worker;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@@ -47,6 +49,8 @@ import com.google.devtools.common.options.OptionsClassProvider;
import java.io.IOException;
import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.concurrent.atomic.AtomicBoolean;
/**
@@ -129,7 +133,6 @@ final class WorkerSpawnStrategy implements SpawnActionContext {
return;
}
- String paramFile = Iterables.getLast(spawn.getArguments());
FileOutErr outErr = actionExecutionContext.getFileOutErr();
ImmutableList<String> args = ImmutableList.<String>builder()
@@ -145,13 +148,18 @@ final class WorkerSpawnStrategy implements SpawnActionContext {
spawn.getToolFiles(), actionExecutionContext.getActionInputFileCache());
WorkerKey key = new WorkerKey(args, env, workDir, spawn.getMnemonic(), workerFilesHash);
- WorkResponse response = execInWorker(executor.getEventHandler(), paramFile, key, maxRetries);
+ WorkRequest.Builder requestBuilder = WorkRequest.newBuilder();
+ expandArgument(requestBuilder, Iterables.getLast(spawn.getArguments()));
+
+ WorkResponse response =
+ execInWorker(executor.getEventHandler(), key, requestBuilder.build(), maxRetries);
outErr.getErrorStream().write(response.getOutputBytes().toByteArray());
if (response.getExitCode() != 0) {
throw new UserExecException(
- String.format("Worker process failed with exit code: %d.", response.getExitCode()));
+ String.format(
+ "Worker process sent response with exit code: %d.", response.getExitCode()));
}
} catch (Exception e) {
String message =
@@ -161,6 +169,26 @@ final class WorkerSpawnStrategy implements SpawnActionContext {
}
}
+ /**
+ * Recursively expands arguments by replacing @filename args with the contents of the referenced
+ * files. The @ itself can be escaped with @@.
+ *
+ * @param requestBuilder the WorkRequest.Builder that the arguments should be added to.
+ * @param arg the argument to expand.
+ * @throws java.io.IOException if one of the files containing options cannot be read.
+ */
+ private void expandArgument(WorkRequest.Builder requestBuilder, String arg) throws IOException {
+ if (arg.startsWith("@") && !arg.startsWith("@@")) {
+ for (String line : Files.readAllLines(Paths.get(arg.substring(1)), UTF_8)) {
+ if (line.length() > 0) {
+ expandArgument(requestBuilder, line);
+ }
+ }
+ } else {
+ requestBuilder.addArguments(arg);
+ }
+ }
+
private HashCode combineActionInputHashes(
Iterable<? extends ActionInput> toolFiles, ActionInputFileCache actionInputFileCache)
throws IOException {
@@ -173,17 +201,14 @@ final class WorkerSpawnStrategy implements SpawnActionContext {
}
private WorkResponse execInWorker(
- EventHandler eventHandler, String paramFile, WorkerKey key, int retriesLeft)
+ EventHandler eventHandler, WorkerKey key, WorkRequest request, int retriesLeft)
throws Exception {
Worker worker = null;
WorkResponse response = null;
try {
worker = workers.borrowObject(key);
- WorkRequest.newBuilder()
- .addArguments(paramFile)
- .build()
- .writeDelimitedTo(worker.getOutputStream());
+ request.writeDelimitedTo(worker.getOutputStream());
worker.getOutputStream().flush();
response = WorkResponse.parseDelimitedFrom(worker.getInputStream());
@@ -213,7 +238,7 @@ final class WorkerSpawnStrategy implements SpawnActionContext {
+ " worker failed ("
+ e
+ "), invalidating and retrying with new worker..."));
- return execInWorker(eventHandler, paramFile, key, retriesLeft - 1);
+ return execInWorker(eventHandler, key, request, retriesLeft - 1);
} else {
throw e;
}