From f0235e890cd2dc3eb56a7afc29fee5b2e2c4da50 Mon Sep 17 00:00:00 2001 From: rytz Date: Mon, 12 Jan 2009 15:43:05 +0000 Subject: [PATCH] fixed #1269. scalac can now be called with arguments stored in a file using the syntax "scalac @argfile". git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@16890 5e8d7ff9-d8ef-0310-90f0-a4852d11357a --- .../scala/tools/nsc/CompilerCommand.scala | 10 ++++- src/compiler/scala/tools/nsc/Settings.scala | 3 +- .../tools/nsc/util/ArgumentsExpander.scala | 42 +++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 src/compiler/scala/tools/nsc/util/ArgumentsExpander.scala diff --git a/src/compiler/scala/tools/nsc/CompilerCommand.scala b/src/compiler/scala/tools/nsc/CompilerCommand.scala index 95e86a6e7..15040b4e3 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 9d6859aba..368b2098a 100644 --- a/src/compiler/scala/tools/nsc/Settings.scala +++ b/src/compiler/scala/tools/nsc/Settings.scala @@ -98,7 +98,8 @@ 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 ("@", "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 val Xchecknull = BooleanSetting ("-Xcheck-null", "Emit warning on selection of nullable reference") 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 000000000..68aa3479d --- /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 + } +}