Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
andyscott committed Feb 19, 2020
1 parent a6fcf2a commit 99a08a3
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions src/java/io/bazel/rulesscala/worker/Worker.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.lang.SecurityManager;
import java.security.Permission;
import java.util.ArrayList;
Expand All @@ -15,6 +17,7 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.nio.charset.StandardCharsets;

import com.google.devtools.build.lib.worker.WorkerProtocol;

Expand All @@ -24,17 +27,6 @@ public static interface Interface {
public void work(String args[]) throws Exception;
}

final static class ExitTrapped extends RuntimeException {
final int code;
ExitTrapped(int code) {
super();
this.code = code;
}
}

private static final Pattern exitPattern =
Pattern.compile("exitVM\\.(-?\\d+)");

public static void workerMain(String workerArgs[], Interface workerInterface) throws Exception {
if (workerArgs.length > 0 && workerArgs[0].equals("--persistent_worker")) {

Expand Down Expand Up @@ -65,13 +57,7 @@ public void checkPermission(Permission permission) {
int code = 0;

try {
List<String> argList = request.getArgumentsList();
int numArgs = argList.size();
String[] args = new String[numArgs];
for (int i = 0; i < numArgs; i++) {
args[i] = argList.get(i);
}
workerInterface.work(args);
workerInterface.work(stringListToArray(request.getArgumentsList()));
} catch (ExitTrapped e) {
code = e.code;
} catch (Exception e) {
Expand All @@ -96,7 +82,33 @@ public void checkPermission(Permission permission) {
System.setErr(stderr);
}
} else {
String[] args;
if (workerArgs.length == 1 && workerArgs[0].startsWith("@")) {
args = stringListToArray(Files.readAllLines(Paths.get(workerArgs[0].substring(1)), StandardCharsets.UTF_8));
} else {
args = workerArgs;
}
workerInterface.work(workerArgs);
}
}

private static class ExitTrapped extends RuntimeException {
final int code;
ExitTrapped(int code) {
super();
this.code = code;
}
}

private static Pattern exitPattern =
Pattern.compile("exitVM\\.(-?\\d+)");

private static String[] stringListToArray(List<String> argList) {
int numArgs = argList.size();
String[] args = new String[numArgs];
for (int i = 0; i < numArgs; i++) {
args[i] = argList.get(i);
}
return args;
}
}

0 comments on commit 99a08a3

Please sign in to comment.