diff options
author | Paul Phillips <paulp@improving.org> | 2011-03-18 18:23:14 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-03-18 18:23:14 +0000 |
commit | f3b970b28cf640904fe0d340f9eb7de37514cb67 (patch) | |
tree | b5e77b7b78ec8743c8e4e0131cc7af4eb5611f7c /src/compiler/scala/tools/nsc/CompileServer.scala | |
parent | d5d7953ab4c31b4f58f51b530ca82603f9e59b94 (diff) | |
download | scala-f3b970b28cf640904fe0d340f9eb7de37514cb67.tar.gz scala-f3b970b28cf640904fe0d340f9eb7de37514cb67.tar.bz2 scala-f3b970b28cf640904fe0d340f9eb7de37514cb67.zip |
Accumulated work on fsc.
adds the following new options.
-ipv4 Use IPv4 rather than IPv6 for the server socket absolute-cp Make
-classpath elements absolute paths before sending to server max-idle
-Set idle timeout in minutes for fsc (use 0 for no timeout)
My question marks are what are the right defaults for the first two.
Former behavior is to absolutize the classpath always and never prefer
IPv4 sockets. I changed the default to not absolutize the classpath,
with the option if you need it; I left the system default in place for
the socket creation, but I have a feeling we should default to IPv4. My
only hesitation is that the only way to request an IPv4 socket from java
involves mutating a global system property. (Robustness FTW.) So for
now, you have to give -ipv4.
Closes #3626, #3785, #3788, #3789. Review by community.
Diffstat (limited to 'src/compiler/scala/tools/nsc/CompileServer.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/CompileServer.scala | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/src/compiler/scala/tools/nsc/CompileServer.scala b/src/compiler/scala/tools/nsc/CompileServer.scala index fc98e30085..a34be6226b 100644 --- a/src/compiler/scala/tools/nsc/CompileServer.scala +++ b/src/compiler/scala/tools/nsc/CompileServer.scala @@ -21,6 +21,11 @@ import settings.FscSettings */ class StandardCompileServer extends SocketServer { lazy val compileSocket: CompileSocket = CompileSocket + private var compiler: Global = null + + var reporter: ConsoleReporter = _ + var shutdown = false + var verbose = false val versionMsg = "Fast Scala compiler " + Properties.versionString + " -- " + @@ -28,16 +33,6 @@ class StandardCompileServer extends SocketServer { val MaxCharge = 0.8 - private var compiler: Global = null - var reporter: ConsoleReporter = _ - var shutdown = false - - private def exit(code: Int): Nothing = { - System.err.close() - System.out.close() - sys.exit(code) - } - private val runtime = Runtime.getRuntime() import runtime.{ totalMemory, freeMemory, maxMemory } @@ -53,9 +48,9 @@ class StandardCompileServer extends SocketServer { } def printMemoryStats() { - System.out.println("New session, total memory = %s, max memory = %s, free memory = %s".format( - totalMemory, maxMemory, freeMemory)) - System.out.flush() + def mb(bytes: Long) = "%dMB".format(bytes / 1000000) + info("New session: total memory = %s, max memory = %s, free memory = %s".format( + mb(totalMemory), mb(maxMemory), mb(freeMemory))) } def isMemoryFullEnough() = { @@ -97,13 +92,18 @@ class StandardCompileServer extends SocketServer { if (input == null || password != guessedPassword) return - val args = input.split("\0", -1).toList + val args = input.split("\0", -1).toList val settings = new FscSettings(fscError) - def logVerbose(msg: String) = - if (settings.verbose.value) - out println msg + val command = newOfflineCompilerCommand(args, settings) - val command = newOfflineCompilerCommand(args, settings) + // Update the idle timeout if given + if (!settings.idleMins.isDefault) { + val mins = settings.idleMins.value + if (mins == 0) echo("Disabling idle timeout on compile server.") + else echo("Setting idle timeout to " + mins + " minutes.") + + this.idleMinutes = mins + } if (settings.shutdown.value) { shutdown = true return out.println("[Compile server exited]") @@ -112,6 +112,7 @@ class StandardCompileServer extends SocketServer { compiler = null return out.println("[Compile server was reset]") } + this.verbose = settings.verbose.value reporter = new ConsoleReporter(command.settings, in, out) { // disable prompts, so that compile server cannot block @@ -119,14 +120,14 @@ class StandardCompileServer extends SocketServer { } def isCompilerReusable: Boolean = { if (compiler == null) { - logVerbose("[Creating new instance for compile server.]") - logVerbose("[Compiler version: " + Properties.versionString + ".]") + info("[Creating new instance for compile server.]") + info("[Compiler version: " + Properties.versionString + ".]") return false } val unequal = unequalSettings(command.settings, compiler.settings) if (unequal.nonEmpty) { - logVerbose("[Replacing compiler with new instance because settings are unequal.]") - logVerbose("[Asymmetric settings: " + unequal.mkString(", ") + "]") + info("[Replacing compiler with new instance because settings are unequal.]") + info("[Asymmetric settings: " + unequal.mkString(", ") + "]") } unequal.isEmpty } @@ -144,8 +145,7 @@ class StandardCompileServer extends SocketServer { compiler = newGlobal(command.settings, reporter) } val c = compiler - val run = new c.Run() - try run compile command.files + try new c.Run() compile command.files catch { case ex @ FatalError(msg) => reporter.error(null, "fatal error: " + msg) @@ -157,7 +157,7 @@ class StandardCompileServer extends SocketServer { } reporter.printSummary() if (isMemoryFullEnough) { - logVerbose("Nulling out compiler due to memory utilization.") + info("Nulling out compiler due to memory utilization.") compiler = null } } @@ -166,12 +166,19 @@ class StandardCompileServer extends SocketServer { object CompileServer extends StandardCompileServer { /** A directory holding redirected output */ - private val redirectDir = (compileSocket.tmpDir / "output-redirects").createDirectory() + private lazy val redirectDir = (compileSocket.tmpDir / "output-redirects").createDirectory() private def redirect(setter: PrintStream => Unit, filename: String): Unit = setter(new PrintStream((redirectDir / filename).createFile().bufferedOutput())) def main(args: Array[String]) { + val debug = args contains "-v" + + if (debug) { + echo("Starting CompileServer on port " + port) + echo("Redirect dir is " + redirectDir) + } + redirect(System.setOut, "scala-compile-server-out.log") redirect(System.setErr, "scala-compile-server-err.log") System.err.println("...starting server on socket "+port+"...") |