summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/CompilerCommand.scala10
-rw-r--r--src/compiler/scala/tools/nsc/Settings.scala1
-rw-r--r--src/compiler/scala/tools/nsc/util/ArgumentsExpander.scala42
3 files changed, 52 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/CompilerCommand.scala b/src/compiler/scala/tools/nsc/CompilerCommand.scala
index 6f22fb8612..bf2c0b9240 100644
--- a/src/compiler/scala/tools/nsc/CompilerCommand.scala
+++ b/src/compiler/scala/tools/nsc/CompilerCommand.scala
@@ -107,7 +107,15 @@ class CompilerCommand(arguments: List[String], val settings: Settings,
var args = arguments
while (!args.isEmpty && ok) {
- if (args.head startsWith "-") {
+ if (args.head startsWith "@") {
+ try {
+ args = util.ArgumentsExpander.expandArg(args.head) ::: args.tail
+ } catch {
+ case ex: java.io.IOException =>
+ error(ex.getMessage())
+ ok = false
+ }
+ } else if (args.head startsWith "-") {
if (interactive) {
error("no options can be given in interactive mode")
ok = false
diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala
index 35921b37d6..9673ed07d4 100644
--- a/src/compiler/scala/tools/nsc/Settings.scala
+++ b/src/compiler/scala/tools/nsc/Settings.scala
@@ -98,6 +98,7 @@ class Settings(error: String => Unit) {
val version = BooleanSetting ("-version", "Print product version and exit").hideToIDE
val help = BooleanSetting ("-help", "Print a synopsis of standard options").hideToIDE
val Xhelp = BooleanSetting ("-X", "Print a synopsis of advanced options").hideToIDE
+ val argfiles = BooleanSetting ("@<file>", "A text file containing compiler arguments (options and source files)") // only for the help message
val assemname = StringSetting ("-Xassem", "file", "Name of the output assembly (only relevant with -target:msil)", "").dependsOn(target, "msil").hideToIDE
val assemrefs = StringSetting ("-Xassem-path", "path", "List of assemblies referenced by the program (only relevant with -target:msil)", ".").dependsOn(target, "msil").hideToIDE
diff --git a/src/compiler/scala/tools/nsc/util/ArgumentsExpander.scala b/src/compiler/scala/tools/nsc/util/ArgumentsExpander.scala
new file mode 100644
index 0000000000..68aa3479d2
--- /dev/null
+++ b/src/compiler/scala/tools/nsc/util/ArgumentsExpander.scala
@@ -0,0 +1,42 @@
+package scala.tools.nsc.util
+
+import java.io.{FileReader, BufferedReader, StreamTokenizer, FileNotFoundException}
+import scala.tools.nsc.io.AbstractFile
+import scala.collection.mutable.ListBuffer
+
+/**
+ * Expands all arguments starting with @ to the contents of the
+ * file named like each argument.
+ */
+object ArgumentsExpander {
+
+ def expandArg(arg: String): List[String] =
+ expandFromFile(arg.substring(1))
+
+ /*
+ * Extracts all the arguments in a specified file.
+ * Throws FileNotFoundException if the file does not exist.
+ */
+ private def expandFromFile(fileName: String): List[String] = {
+ val f = AbstractFile.getFile(fileName)
+ if (f eq null) throw new FileNotFoundException(
+ "argument file "+ fileName +" could not be found")
+
+ val in = new BufferedReader(new FileReader(f.file))
+
+ val tokenizer = new StreamTokenizer( in )
+ tokenizer.resetSyntax
+ tokenizer.wordChars(' ', 255)
+ tokenizer.whitespaceChars(0, ' ')
+ tokenizer.commentChar('#')
+ tokenizer.quoteChar('"')
+ tokenizer.quoteChar('\'')
+
+ val ts = new ListBuffer[String]
+ while (tokenizer.nextToken() != StreamTokenizer.TT_EOF) {
+ ts += tokenizer.sval
+ }
+ in.close()
+ ts.toList
+ }
+}