Skip to content

Commit 99a08a3

Browse files
committed
fix
1 parent a6fcf2a commit 99a08a3

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

src/java/io/bazel/rulesscala/worker/Worker.java

+30-18
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java.io.InputStream;
77
import java.io.OutputStream;
88
import java.io.PrintStream;
9+
import java.nio.file.Files;
10+
import java.nio.file.Paths;
911
import java.lang.SecurityManager;
1012
import java.security.Permission;
1113
import java.util.ArrayList;
@@ -15,6 +17,7 @@
1517
import java.util.regex.Pattern;
1618
import java.util.stream.Collectors;
1719
import java.util.stream.Stream;
20+
import java.nio.charset.StandardCharsets;
1821

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

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

27-
final static class ExitTrapped extends RuntimeException {
28-
final int code;
29-
ExitTrapped(int code) {
30-
super();
31-
this.code = code;
32-
}
33-
}
34-
35-
private static final Pattern exitPattern =
36-
Pattern.compile("exitVM\\.(-?\\d+)");
37-
3830
public static void workerMain(String workerArgs[], Interface workerInterface) throws Exception {
3931
if (workerArgs.length > 0 && workerArgs[0].equals("--persistent_worker")) {
4032

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

6759
try {
68-
List<String> argList = request.getArgumentsList();
69-
int numArgs = argList.size();
70-
String[] args = new String[numArgs];
71-
for (int i = 0; i < numArgs; i++) {
72-
args[i] = argList.get(i);
73-
}
74-
workerInterface.work(args);
60+
workerInterface.work(stringListToArray(request.getArgumentsList()));
7561
} catch (ExitTrapped e) {
7662
code = e.code;
7763
} catch (Exception e) {
@@ -96,7 +82,33 @@ public void checkPermission(Permission permission) {
9682
System.setErr(stderr);
9783
}
9884
} else {
85+
String[] args;
86+
if (workerArgs.length == 1 && workerArgs[0].startsWith("@")) {
87+
args = stringListToArray(Files.readAllLines(Paths.get(workerArgs[0].substring(1)), StandardCharsets.UTF_8));
88+
} else {
89+
args = workerArgs;
90+
}
9991
workerInterface.work(workerArgs);
10092
}
10193
}
94+
95+
private static class ExitTrapped extends RuntimeException {
96+
final int code;
97+
ExitTrapped(int code) {
98+
super();
99+
this.code = code;
100+
}
101+
}
102+
103+
private static Pattern exitPattern =
104+
Pattern.compile("exitVM\\.(-?\\d+)");
105+
106+
private static String[] stringListToArray(List<String> argList) {
107+
int numArgs = argList.size();
108+
String[] args = new String[numArgs];
109+
for (int i = 0; i < numArgs; i++) {
110+
args[i] = argList.get(i);
111+
}
112+
return args;
113+
}
102114
}

0 commit comments

Comments
 (0)