diff options
17 files changed, 52 insertions, 68 deletions
diff --git a/src/compiler/scala/tools/ant/Scalac.scala b/src/compiler/scala/tools/ant/Scalac.scala index 92a61ad70c..4ecfc3dc85 100644 --- a/src/compiler/scala/tools/ant/Scalac.scala +++ b/src/compiler/scala/tools/ant/Scalac.scala @@ -563,7 +563,7 @@ class Scalac extends MatchingTask with ScalacShared { log("Scalac params = '" + addParams + "'", Project.MSG_DEBUG) // let CompilerCommand processes all params - val command = new CompilerCommand(settings.splitParams(addParams), settings, error, false) + val command = new CompilerCommand(settings.splitParams(addParams), settings) // resolve dependenciesFile path from project's basedir, so <ant antfile ...> call from other project works. // the dependenciesFile may be relative path to basedir or absolute path, in either case, the following code diff --git a/src/compiler/scala/tools/ant/sabbus/ForeignCompiler.scala b/src/compiler/scala/tools/ant/sabbus/ForeignCompiler.scala index 543ea10cc7..2263196af4 100644 --- a/src/compiler/scala/tools/ant/sabbus/ForeignCompiler.scala +++ b/src/compiler/scala/tools/ant/sabbus/ForeignCompiler.scala @@ -32,7 +32,7 @@ class ForeignCompiler { private lazy val nsc: Global = { try { - val command = new CompilerCommand(args.toList, settings, error, false) + val command = new CompilerCommand(args.toList, settings) new Global(command.settings, reporter) } catch { @@ -42,7 +42,7 @@ class ForeignCompiler { } def compile(files: Array[File]): Int = { - val command = new CompilerCommand(files.toList.map(_.toString), settings, error, true) + val command = new CompilerCommand(files.toList map (_.toString), settings) (new nsc.Run) compile command.files reporter.ERROR.count << 16 | reporter.WARNING.count } diff --git a/src/compiler/scala/tools/nsc/CompileServer.scala b/src/compiler/scala/tools/nsc/CompileServer.scala index 36af000937..c4f9b1d9f1 100644 --- a/src/compiler/scala/tools/nsc/CompileServer.scala +++ b/src/compiler/scala/tools/nsc/CompileServer.scala @@ -70,12 +70,8 @@ class StandardCompileServer extends SocketServer (totalMemory - freeMemory).toDouble / maxMemory.toDouble > MaxCharge } - protected def newOfflineCompilerCommand( - arguments: List[String], - settings: Settings, - error: String => Unit, - interactive: Boolean - ) = new OfflineCompilerCommand(arguments, settings, error, interactive) + protected def newOfflineCompilerCommand(arguments: List[String], settings: Settings) = + new OfflineCompilerCommand(arguments, settings) def session() { printMemoryStats() @@ -102,7 +98,7 @@ class StandardCompileServer extends SocketServer out.println(FakePos("fsc"), msg + "\n fsc -help gives more information") } - val command = newOfflineCompilerCommand(args, new Settings(error), error, false) + val command = newOfflineCompilerCommand(args, new Settings(error)) reporter = new ConsoleReporter(command.settings, in, out) { // disable prompts, so that compile server cannot block diff --git a/src/compiler/scala/tools/nsc/CompilerCommand.scala b/src/compiler/scala/tools/nsc/CompilerCommand.scala index 0ef2bcb85d..c8c7482811 100644 --- a/src/compiler/scala/tools/nsc/CompilerCommand.scala +++ b/src/compiler/scala/tools/nsc/CompilerCommand.scala @@ -11,16 +11,8 @@ import scala.collection.mutable.ListBuffer import io.File /** A class representing command line info for scalac */ -class CompilerCommand( - arguments: List[String], - val settings: Settings, - error: String => Unit, - interactive: Boolean, - shouldProcessArguments: Boolean) -{ - def this(arguments: List[String], settings: Settings, error: String => Unit, interactive: Boolean) = - this(arguments, settings, error, interactive, true) - +class CompilerCommand(arguments: List[String], val settings: Settings) { + def this(arguments: List[String], error: String => Unit) = this(arguments, new Settings(error)) type Setting = Settings#Setting /** file extensions of files that the compiler can process */ @@ -83,19 +75,20 @@ class CompilerCommand( settings splitParams (file.lines() map stripComment mkString " ") } - // CompilerCommand needs processArguments called at the end of its constructor, - // as does its subclass GenericRunnerCommand, but it cannot be called twice as it - // accumulates arguments. The fact that it's called from within the constructors - // makes initialization order an obstacle to simplicity. - val (ok: Boolean, files: List[String]) = - if (shouldProcessArguments) { - // expand out @filename to the contents of that filename - val expandedArguments = arguments flatMap { - case x if x startsWith "@" => expandArg(x) - case x => List(x) - } - - settings.processArguments(expandedArguments, true) + // override this if you don't want arguments processed here + def shouldProcessArguments: Boolean = true + + def processArguments: (Boolean, List[String]) = { + // expand out @filename to the contents of that filename + val expandedArguments = arguments flatMap { + case x if x startsWith "@" => expandArg(x) + case x => List(x) } + + settings.processArguments(expandedArguments, true) + } + + val (ok, files) = + if (shouldProcessArguments) processArguments else (true, Nil) } diff --git a/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala b/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala index a0c70ef72a..f3ac556d4f 100644 --- a/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala +++ b/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala @@ -9,27 +9,27 @@ package scala.tools.nsc /** A command for ScriptRunner */ class GenericRunnerCommand( - val allargs: List[String], - override val settings: GenericRunnerSettings, - error: String => Unit) -extends CompilerCommand(allargs, settings, error, false, false) -{ - def this(allargs: List[String], error: String=>Unit) = - this(allargs, new GenericRunnerSettings(error), error) + args: List[String], + override val settings: GenericRunnerSettings) +extends CompilerCommand(args, settings) { - def this(allargs: List[String]) = - this(allargs, str => Console.println("Error: " + str)) + def this(args: List[String], error: String => Unit) = + this(args, new GenericRunnerSettings(error)) + + def this(args: List[String]) = + this(args, str => Console.println("Error: " + str)) /** name of the associated compiler command */ override val cmdName = "scala" val compCmdName = "scalac" + // change CompilerCommand behavior + override def shouldProcessArguments: Boolean = false + /** thingToRun: What to run. If it is None, then the interpreter should be started * arguments: Arguments to pass to the object or script to run - * - * we can safely process arguments since we passed the superclass shouldProcessArguments=false */ - val (thingToRun, arguments) = (settings.processArguments(allargs, false))._2 match { + val (thingToRun, arguments) = settings.processArguments(args, false)._2 match { case Nil => (None, Nil) case hd :: tl => (Some(hd), tl) } diff --git a/src/compiler/scala/tools/nsc/InterpreterCommand.scala b/src/compiler/scala/tools/nsc/InterpreterCommand.scala index a204edc70a..45e139194e 100644 --- a/src/compiler/scala/tools/nsc/InterpreterCommand.scala +++ b/src/compiler/scala/tools/nsc/InterpreterCommand.scala @@ -11,8 +11,7 @@ package scala.tools.nsc * @author Lex Spoon * @version 1.0 */ -class InterpreterCommand(arguments: List[String], error: String => Unit) -extends CompilerCommand(arguments, new Settings(error), error, false) { +class InterpreterCommand(arguments: List[String], error: String => Unit) extends CompilerCommand(arguments, error) { override val cmdName = "scala" override lazy val fileEndings = List(".scalaint") } diff --git a/src/compiler/scala/tools/nsc/Main.scala b/src/compiler/scala/tools/nsc/Main.scala index 4f945733fd..eaa2970dda 100644 --- a/src/compiler/scala/tools/nsc/Main.scala +++ b/src/compiler/scala/tools/nsc/Main.scala @@ -41,7 +41,7 @@ object Main extends AnyRef with EvalLoop { def resident(compiler: Global) { loop { line => val args = line.split(' ').toList - val command = new CompilerCommand(args, new Settings(error), error, true) + val command = new CompilerCommand(args, new Settings(error)) compiler.reporter.reset new compiler.Run() compile command.files } @@ -50,7 +50,7 @@ object Main extends AnyRef with EvalLoop { def process(args: Array[String]) { val settings = new Settings(error) reporter = new ConsoleReporter(settings) - val command = new CompilerCommand(args.toList, settings, error, false) + val command = new CompilerCommand(args.toList, settings) if (command.settings.version.value) reporter.info(null, versionMsg, true) else if (command.settings.Yidedebug.value) { @@ -80,7 +80,7 @@ object Main extends AnyRef with EvalLoop { // enter resident mode loop { line => val args = line.split(' ').toList - val command = new CompilerCommand(args.toList, settings, error, true) + val command = new CompilerCommand(args.toList, settings) buildManager.update(fileSet(command.files), Set.empty) } } else { diff --git a/src/compiler/scala/tools/nsc/MainGenericRunner.scala b/src/compiler/scala/tools/nsc/MainGenericRunner.scala index bb373c69e4..fdc5fe82dd 100644 --- a/src/compiler/scala/tools/nsc/MainGenericRunner.scala +++ b/src/compiler/scala/tools/nsc/MainGenericRunner.scala @@ -31,7 +31,7 @@ object MainGenericRunner { } def exitCond(b: Boolean): Nothing = if (b) exitSuccess else exitFailure(null) - val command = new GenericRunnerCommand(args.toList, errorFn) + val command = new GenericRunnerCommand(args.toList, errorFn _) import command.settings def sampleCompiler = new Global(settings) // def so its not created unless needed diff --git a/src/compiler/scala/tools/nsc/MainTokenMetric.scala b/src/compiler/scala/tools/nsc/MainTokenMetric.scala index 0ee7ee1fe1..9c123922d6 100644 --- a/src/compiler/scala/tools/nsc/MainTokenMetric.scala +++ b/src/compiler/scala/tools/nsc/MainTokenMetric.scala @@ -37,7 +37,7 @@ object MainTokenMetric { def process(args: Array[String]) { val settings = new Settings(error) reporter = new ConsoleReporter(settings) - val command = new CompilerCommand(args.toList, settings, error, false) + val command = new CompilerCommand(args.toList, settings) try { val compiler = new Global(command.settings, reporter) tokenMetric(compiler, command.files) diff --git a/src/compiler/scala/tools/nsc/OfflineCompilerCommand.scala b/src/compiler/scala/tools/nsc/OfflineCompilerCommand.scala index 2233ec269c..b011f88f2b 100644 --- a/src/compiler/scala/tools/nsc/OfflineCompilerCommand.scala +++ b/src/compiler/scala/tools/nsc/OfflineCompilerCommand.scala @@ -12,11 +12,8 @@ package scala.tools.nsc */ class OfflineCompilerCommand( arguments: List[String], - settings: Settings, - error: String => Unit, - interactive: Boolean) -extends CompilerCommand(arguments, new Settings(error), error, false) -{ + settings: Settings) +extends CompilerCommand(arguments, settings) { override val cmdName = "fsc" import settings._ diff --git a/src/compiler/scala/tools/nsc/ScalaDoc.scala b/src/compiler/scala/tools/nsc/ScalaDoc.scala index 4a9bbe8fd3..b7e416e121 100644 --- a/src/compiler/scala/tools/nsc/ScalaDoc.scala +++ b/src/compiler/scala/tools/nsc/ScalaDoc.scala @@ -38,7 +38,7 @@ object ScalaDoc { reporter = new ConsoleReporter(docSettings) val command = - new CompilerCommand(args.toList, docSettings, error, false) + new CompilerCommand(args.toList, docSettings) if (!reporter.hasErrors) { // No need to continue if reading the command generated errors diff --git a/src/compiler/scala/tools/nsc/interactive/BuildManager.scala b/src/compiler/scala/tools/nsc/interactive/BuildManager.scala index 46930d398f..302bba0e07 100644 --- a/src/compiler/scala/tools/nsc/interactive/BuildManager.scala +++ b/src/compiler/scala/tools/nsc/interactive/BuildManager.scala @@ -69,7 +69,7 @@ object BuildManagerTest extends EvalLoop { val settings = new Settings(error) settings.Ybuildmanagerdebug.value = true - val command = new CompilerCommand(args.toList, settings, error, false) + val command = new CompilerCommand(args.toList, settings) // settings.make.value = "off" // val buildManager: BuildManager = new SimpleBuildManager(settings) val buildManager: BuildManager = new RefinedBuildManager(settings) @@ -79,7 +79,7 @@ object BuildManagerTest extends EvalLoop { // enter resident mode loop { line => val args = line.split(' ').toList - val command = new CompilerCommand(args, settings, error, true) + val command = new CompilerCommand(args, settings) buildManager.update(command.files, Set.empty) } diff --git a/src/compiler/scala/tools/nsc/interactive/REPL.scala b/src/compiler/scala/tools/nsc/interactive/REPL.scala index f3b1900ef2..5589ddb9b1 100644 --- a/src/compiler/scala/tools/nsc/interactive/REPL.scala +++ b/src/compiler/scala/tools/nsc/interactive/REPL.scala @@ -28,7 +28,7 @@ object REPL { def process(args: Array[String]) { val settings = new Settings(error) reporter = new ConsoleReporter(settings) - val command = new CompilerCommand(args.toList, settings, error, false) + val command = new CompilerCommand(args.toList, settings) if (command.settings.version.value) reporter.info(null, versionMsg, true) else { diff --git a/src/partest/scala/tools/partest/nest/CompileManager.scala b/src/partest/scala/tools/partest/nest/CompileManager.scala index b030d14622..22568ad2d0 100644 --- a/src/partest/scala/tools/partest/nest/CompileManager.scala +++ b/src/partest/scala/tools/partest/nest/CompileManager.scala @@ -81,7 +81,7 @@ class DirectCompiler(val fileManager: FileManager) extends SimpleCompiler { NestUI.verbose("scalac options: "+allOpts) - val command = new CompilerCommand(args, testSettings, _ => (), false) + val command = new CompilerCommand(args, testSettings) val global = newGlobal(command.settings, logWriter) val testRep: ExtConsoleReporter = global.reporter.asInstanceOf[ExtConsoleReporter] diff --git a/src/partest/scala/tools/partest/nest/Worker.scala b/src/partest/scala/tools/partest/nest/Worker.scala index cf4a8238e9..2f81dfd0f7 100644 --- a/src/partest/scala/tools/partest/nest/Worker.scala +++ b/src/partest/scala/tools/partest/nest/Worker.scala @@ -554,7 +554,7 @@ class Worker(val fileManager: FileManager) extends Actor { val testCompile = (line: String) => { NestUI.verbose("compiling " + line) val args = (line split ' ').toList - val command = new CompilerCommand(args, settings, error, true) + val command = new CompilerCommand(args, settings) bM.update(filesToSet(settings.sourcepath.value, command.files), Set.empty) !reporter.hasErrors } @@ -675,7 +675,7 @@ class Worker(val fileManager: FileManager) extends Actor { settings.sourcepath.value = sourcepath settings.classpath.value = fileManager.CLASSPATH reporter = new ConsoleReporter(settings, scala.Console.in, logConsoleWriter) - val command = new CompilerCommand(argList, settings, error, false) + val command = new CompilerCommand(argList, settings) object compiler extends Global(command.settings, reporter) // simulate resident compiler loop @@ -687,7 +687,7 @@ class Worker(val fileManager: FileManager) extends Actor { NestUI.verbose("cmdArgs: "+cmdArgs) val sett = new Settings(error) sett.sourcepath.value = sourcepath - val command = new CompilerCommand(cmdArgs, sett, error, true) + val command = new CompilerCommand(cmdArgs, sett) (new compiler.Run) compile command.files } diff --git a/test/disabled/run/docgenerator.scala b/test/disabled/run/docgenerator.scala index 247ad17b45..8e0c7589ad 100644 --- a/test/disabled/run/docgenerator.scala +++ b/test/disabled/run/docgenerator.scala @@ -116,7 +116,7 @@ object Foo2 { // when running that compiler, give it a scala-library to the classpath docSettings.classpath.value = System.getProperty("java.class.path") reporter = new ConsoleReporter(docSettings) - val command = new CompilerCommand(args.toList, docSettings, error, false) + val command = new CompilerCommand(args.toList, docSettings) try { object compiler extends Global(command.settings, reporter) { override protected def computeInternalPhases() : Unit = { diff --git a/test/files/run/programmatic-main.scala b/test/files/run/programmatic-main.scala index 7c5b016f52..9c7d0b7095 100644 --- a/test/files/run/programmatic-main.scala +++ b/test/files/run/programmatic-main.scala @@ -1,8 +1,7 @@ import scala.tools.nsc._ import io.Path -object Test -{ +object Test { val cwd = Option(System.getProperty("partest.cwd")) getOrElse "." val basedir = Path(cwd).parent / "lib" path val baseargs = Array("-usejavacp", "-bootclasspath", basedir + "/scala-library.jar", "-cp", basedir + "/scala-compiler.jar") |