From ee4e09235afa578a7a33267061179ca338e396c0 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Tue, 1 Feb 2011 08:27:18 +0000 Subject: Eliminating duplication and trying to outrun ob... Eliminating duplication and trying to outrun obsolescence in the exciting world of fsc. No review. --- src/compiler/scala/tools/nsc/CompileServer.scala | 47 ++++++++++++------------ 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'src/compiler/scala/tools/nsc/CompileServer.scala') diff --git a/src/compiler/scala/tools/nsc/CompileServer.scala b/src/compiler/scala/tools/nsc/CompileServer.scala index 8998b8065e..5296432519 100644 --- a/src/compiler/scala/tools/nsc/CompileServer.scala +++ b/src/compiler/scala/tools/nsc/CompileServer.scala @@ -21,7 +21,7 @@ import scala.tools.util.SocketServer * @version 1.0 */ class StandardCompileServer extends SocketServer { - def compileSocket: CompileSocket = CompileSocket // todo: make this a lazy val + lazy val compileSocket: CompileSocket = CompileSocket val versionMsg = "Fast Scala compiler " + Properties.versionString + " -- " + @@ -75,27 +75,25 @@ class StandardCompileServer extends SocketServer { val guessedPassword = in.readLine() val input = in.readLine() + def fscError(msg: String): Unit = out println ( + FakePos("fsc"), + msg + "\n fsc -help gives more information" + ) if (input == null || password != guessedPassword) return val args = input.split("\0", -1).toList - if (args contains "-shutdown") { - out.println("[Compile server exited]") + val command = newOfflineCompilerCommand(args, new Settings(fscError)) + + if (command.fscShutdown.value) { shutDown = true - return + return out.println("[Compile server exited]") } - if (args contains "-reset") { - out.println("[Compile server was reset]") + if (command.fscReset.value) { compiler = null - return + return out.println("[Compile server was reset]") } - def fscError(msg: String) { - out.println(FakePos("fsc"), msg + "\n fsc -help gives more information") - } - - val command = newOfflineCompilerCommand(args, new Settings(fscError)) - reporter = new ConsoleReporter(command.settings, in, out) { // disable prompts, so that compile server cannot block override def displayPrompt = () @@ -112,7 +110,7 @@ class StandardCompileServer extends SocketServer { compiler.reporter = reporter } else { - if (args contains "-verbose") { + if (command.verbose) { val reason = if (compiler == null) "compiler is null" else "settings not equal" out.println("[Starting new compile server instance because %s]".format(reason)) } @@ -124,14 +122,15 @@ class StandardCompileServer extends SocketServer { } catch { case ex @ FatalError(msg) => - if (command.settings.debug.value) - ex.printStackTrace(out); - reporter.error(null, "fatal error: " + msg) - compiler = null + if (command.debug) + ex.printStackTrace(out) + + reporter.error(null, "fatal error: " + msg) + compiler = null case ex: Throwable => ex.printStackTrace(out); - reporter.error(null, "fatal error (server aborted): " + ex.getMessage()) - shutDown = true + reporter.error(null, "fatal error (server aborted): " + ex.getMessage()) + shutDown = true } } @@ -139,7 +138,10 @@ class StandardCompileServer extends SocketServer { if (isMemoryFullEnough) compiler = null } +} + +object CompileServer extends StandardCompileServer { /** A directory holding redirected output */ private val redirectDir = (compileSocket.tmpDir / "output-redirects").createDirectory() @@ -151,12 +153,11 @@ class StandardCompileServer extends SocketServer { redirect(System.setErr, "scala-compile-server-err.log") System.err.println("...starting server on socket "+port+"...") System.err.flush() + compileSocket.setPort(port) run() + compileSocket.deletePort(port) exit(0) } } - - -object CompileServer extends StandardCompileServer -- cgit v1.2.3