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
This commit is contained in:
rytz 2009-01-12 15:43:05 +00:00
parent 4806ffb39d
commit f0235e890c
3 changed files with 53 additions and 2 deletions

View File

@ -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

View File

@ -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 ("@<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
val Xchecknull = BooleanSetting ("-Xcheck-null", "Emit warning on selection of nullable reference")

View File

@ -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
}
}