diff options
author | Lukas Rytz <lukas.rytz@epfl.ch> | 2009-01-12 15:43:05 +0000 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@epfl.ch> | 2009-01-12 15:43:05 +0000 |
commit | ee79ccdc9bc921bab1100b2d5a1092c4d3a18db3 (patch) | |
tree | 330108b9f24d2e9219d0cc6b87ed3c2ddad5f2ee /src/compiler | |
parent | 91d92ec83bdfdebc2e97eda5b34fdc4b10cdfecc (diff) | |
download | scala-ee79ccdc9bc921bab1100b2d5a1092c4d3a18db3.tar.gz scala-ee79ccdc9bc921bab1100b2d5a1092c4d3a18db3.tar.bz2 scala-ee79ccdc9bc921bab1100b2d5a1092c4d3a18db3.zip |
fixed #1269.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/CompilerCommand.scala | 10 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/Settings.scala | 1 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/util/ArgumentsExpander.scala | 42 |
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 + } +} |