6
6
import java .io .InputStream ;
7
7
import java .io .OutputStream ;
8
8
import java .io .PrintStream ;
9
+ import java .nio .file .Files ;
10
+ import java .nio .file .Paths ;
9
11
import java .lang .SecurityManager ;
10
12
import java .security .Permission ;
11
13
import java .util .ArrayList ;
15
17
import java .util .regex .Pattern ;
16
18
import java .util .stream .Collectors ;
17
19
import java .util .stream .Stream ;
20
+ import java .nio .charset .StandardCharsets ;
18
21
19
22
import com .google .devtools .build .lib .worker .WorkerProtocol ;
20
23
@@ -24,17 +27,6 @@ public static interface Interface {
24
27
public void work (String args []) throws Exception ;
25
28
}
26
29
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
-
38
30
public static void workerMain (String workerArgs [], Interface workerInterface ) throws Exception {
39
31
if (workerArgs .length > 0 && workerArgs [0 ].equals ("--persistent_worker" )) {
40
32
@@ -65,13 +57,7 @@ public void checkPermission(Permission permission) {
65
57
int code = 0 ;
66
58
67
59
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 ()));
75
61
} catch (ExitTrapped e ) {
76
62
code = e .code ;
77
63
} catch (Exception e ) {
@@ -96,7 +82,33 @@ public void checkPermission(Permission permission) {
96
82
System .setErr (stderr );
97
83
}
98
84
} 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
+ }
99
91
workerInterface .work (workerArgs );
100
92
}
101
93
}
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
+ }
102
114
}
0 commit comments