Skip to content

Commit 74a0737

Browse files
Dino Olivacopybara-github
authored andcommitted
Add support for @file arg.
PiperOrigin-RevId: 365858734
1 parent 5151005 commit 74a0737

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

  • tree_shaker/src/main/java/com/google/devtools/treeshaker

tree_shaker/src/main/java/com/google/devtools/treeshaker/Options.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@
1818
import com.google.common.base.Preconditions;
1919
import com.google.common.base.Strings;
2020
import com.google.common.collect.Lists;
21+
import com.google.common.io.Files;
2122
import com.google.common.io.Resources;
2223
import com.google.devtools.j2objc.util.SourceVersion;
2324
import com.google.devtools.j2objc.util.Version;
24-
2525
import java.io.BufferedReader;
2626
import java.io.File;
2727
import java.io.FileReader;
2828
import java.io.IOException;
2929
import java.net.URL;
30+
import java.nio.charset.Charset;
3031
import java.util.List;
3132
import java.util.Properties;
3233

@@ -153,12 +154,29 @@ public static void version() {
153154

154155
public static Options parse(String[] args) throws IOException {
155156
Options options = new Options();
157+
processArgs(args, options);
158+
return options;
159+
}
160+
161+
private static void processArgsFile(String filename, Options options) throws IOException {
162+
if (filename.isEmpty()) {
163+
usage("no @ file specified");
164+
}
165+
File f = new File(filename);
166+
String fileArgs = Files.asCharSource(f, Charset.forName(options.fileEncoding())).read();
167+
// Simple split on any whitespace, quoted values aren't supported.
168+
processArgs(fileArgs.split("\\s+"), options);
169+
}
170+
171+
private static void processArgs(String[] args, Options options) throws IOException {
156172
boolean printArgs = false;
157173

158174
int nArg = 0;
159175
while (nArg < args.length) {
160176
String arg = args[nArg];
161-
if (arg.equals("-sourcepath")) {
177+
if (arg.startsWith("@")) {
178+
processArgsFile(arg.substring(1), options);
179+
} else if (arg.equals("-sourcepath")) {
162180
if (++nArg == args.length) {
163181
usage("-sourcepath requires an argument");
164182
}
@@ -227,7 +245,5 @@ public static Options parse(String[] args) throws IOException {
227245
System.err.print("tree_shaker ");
228246
System.err.println(String.join(" ", args));
229247
}
230-
231-
return options;
232248
}
233249
}

0 commit comments

Comments
 (0)