From 4146327bbd6b8e5468c05a570a9190c99c4285e3 Mon Sep 17 00:00:00 2001 From: michelou Date: Thu, 20 Jul 2006 15:24:23 +0000 Subject: fsc prints more info messages with -verbose option --- src/compiler/scala/tools/nsc/CompileClient.scala | 6 ++- src/compiler/scala/tools/nsc/CompileServer.scala | 21 ++++---- src/compiler/scala/tools/nsc/CompileSocket.scala | 67 +++++++++++++----------- src/compiler/scala/tools/util/SocketServer.scala | 10 ++-- 4 files changed, 59 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/CompileClient.scala b/src/compiler/scala/tools/nsc/CompileClient.scala index 9e24a67d72..2b571741bd 100644 --- a/src/compiler/scala/tools/nsc/CompileClient.scala +++ b/src/compiler/scala/tools/nsc/CompileClient.scala @@ -14,6 +14,8 @@ import java.io._ */ object CompileClient { + var verbose = false + def normalize(args: Array[String]): Pair[String, String] = { def absFileName(path: String) = new File(path).getAbsolutePath() def absFileNames(paths: String) = { @@ -35,6 +37,8 @@ object CompileClient { } else if (arg startsWith "-J") { vmArgs append " -"+arg.substring(2) args(i) = "" + } else if (arg == "-verbose") { + verbose = true } i = i + 1 if (i < args.length) { @@ -57,7 +61,7 @@ object CompileClient { def main(args: Array[String]): unit = { val Pair(vmArgs, serverAdr) = normalize(args) - if (args.toList contains "-verbose") { + if (verbose) { System.out.println("[Server arguments: " + args.mkString("", " ", "]")) System.out.println("[VM arguments: " + vmArgs + "]") } diff --git a/src/compiler/scala/tools/nsc/CompileServer.scala b/src/compiler/scala/tools/nsc/CompileServer.scala index 905ca938c3..c88f412948 100644 --- a/src/compiler/scala/tools/nsc/CompileServer.scala +++ b/src/compiler/scala/tools/nsc/CompileServer.scala @@ -3,6 +3,7 @@ * @author Martin Odersky */ // $Id$ + package scala.tools.nsc import scala.tools.util.SocketServer @@ -14,6 +15,9 @@ import java.io._ /** The main class for NSC, a compiler for the programming * language Scala. + * + * @author Martin Odersky + * @version 1.0 */ object CompileServer extends SocketServer { @@ -54,10 +58,8 @@ object CompileServer extends SocketServer { progress = false spawn { Thread.sleep(10000) - if (!progress) { - System.err.println("port file no longer exists; exiting") - exit(1) - } + if (!progress) + fatal("port file no longer exists; exiting") } } } @@ -66,9 +68,10 @@ object CompileServer extends SocketServer { private val runtime = Runtime.getRuntime() def session(): unit = { - System.out.println("New session, total memory = "+runtime.totalMemory()+ - ", max memory = "+runtime.maxMemory()+ - ", free memory = "+runtime.freeMemory) + System.out.println("New session" + + ", total memory = "+ runtime.totalMemory() + + ", max memory = " + runtime.maxMemory() + + ", free memory = " + runtime.freeMemory) val password = CompileSocket.getPassword(port) val guessedPassword = in.readLine() val input = in.readLine() @@ -105,7 +108,7 @@ object CompileServer extends SocketServer { new settings.BooleanSetting("-J", "Pass directly to runtime system") } - reporter.prompt = command.settings.prompt.value; + reporter.prompt = command.settings.prompt.value if (command.settings.version.value) reporter.info(null, versionMsg, true) else if (command.settings.help.value) @@ -118,7 +121,7 @@ object CompileServer extends SocketServer { compiler.settings = command.settings compiler.reporter = reporter } else { - if (args exists ("-verbose" ==)) + if (args contains "-verbose") out.println("[Starting new Scala compile server instance]") compiler = new Global(command.settings, reporter) { override def inform(msg: String) = out.println(msg) diff --git a/src/compiler/scala/tools/nsc/CompileSocket.scala b/src/compiler/scala/tools/nsc/CompileSocket.scala index 14e7566f19..f9feaea80e 100644 --- a/src/compiler/scala/tools/nsc/CompileSocket.scala +++ b/src/compiler/scala/tools/nsc/CompileSocket.scala @@ -39,6 +39,9 @@ object CompileSocket { exit(1) } + private def info(msg: String) = + if (CompileClient.verbose) System.out.println(msg) + /** The temporary directory in which the port identification file is stored */ private val tmpDir = { val totry = List( @@ -55,7 +58,7 @@ object CompileSocket { val fulldir = extensions.foldLeft[File](new File(topdir))( - (dir,ext)=>new File(dir, ext)) + (dir,ext) => new File(dir, ext)) Some(fulldir) } @@ -73,10 +76,11 @@ object CompileSocket { } yield expanded.get - if (potentials.isEmpty) { - fatal("could not find a directory for port files") - } else { + if (potentials.isEmpty) + fatal("Could not find a directory for port files") + else { val d = new File(potentials.head, dirName) + info("[Temp directory: " + d + "]") d.mkdirs d } @@ -97,15 +101,19 @@ object CompileSocket { vmCommand + vmArgs + " " + serverClass /** Start a new server; returns true iff it succeeds */ - def startNewServer(vmArgs: String): Boolean = + private def startNewServer(vmArgs: String): unit = { + val cmd = serverCommand(vmArgs) + info("[Executed command: " + cmd + "]") try { - Runtime.getRuntime().exec(serverCommand(vmArgs)) - true + val proc = Runtime.getRuntime().exec(cmd) + val exitVal = proc.waitFor() + info("[Exit value: " + exitVal + "]") } catch { - case ex: Throwable => { - false - } + case ex: Throwable => + fatal("cannot start server." + + "\ntried command: " + cmd) } + } /** The port identification file */ def portFile(port: int) = new File(tmpDir, port.toString()) @@ -133,17 +141,14 @@ object CompileSocket { def getPort(vmArgs: String): int = { var attempts = 0 var port = pollPort() - if (port < 0) { - if (!startNewServer(vmArgs)) { - fatal("cannot start server." + - "\ntried command: " + serverCommand(vmArgs)) - } - } + if (port < 0) + startNewServer(vmArgs) while (port < 0 && attempts < MaxAttempts) { attempts = attempts + 1 Thread.sleep(sleepTime) port = pollPort() } + info("[Port number: " + port + "]") if (port < 0) fatal("Could not connect to server.") port @@ -156,8 +161,8 @@ object CompileSocket { f.println(new java.util.Random().nextInt.toString) f.close() } catch { - case ex: IOException => - fatal("cannot create file: " + + case ex: /*FileNotFound+Security*/Exception => + fatal("Cannot create file: " + portFile(port).getAbsolutePath() + "; exiting") } @@ -167,22 +172,24 @@ object CompileSocket { def getOrCreateSocket(vmArgs: String): Socket = { val nAttempts = 9 def getsock(attempts: int): Socket = - if (attempts == 0) { - fatal("unable to establish connection to server; exiting") - } else { + if (attempts == 0) + fatal("Unable to establish connection to server; exiting") + else { val port = getPort(vmArgs) val hostName = InetAddress.getLocalHost().getHostName() try { new Socket(hostName, port) } catch { - case e: IOException => + case e: /*IO+Security*/Exception => System.err.println(e) - System.err.println("...connection attempt to server at port "+port+" failed; re-trying...") + System.err.println("...connection attempt to server at port " + + port + " failed; re-trying...") if (attempts % 2 == 0) portFile(port).delete() Thread.sleep(100) val result = getsock(attempts - 1) if (attempts == nAttempts) - System.err.println("...connection established at port "+port+"...") + System.err.println("...connection established at port " + + port + "...") result } } @@ -191,15 +198,15 @@ object CompileSocket { def getSocket(serverAdr: String): Socket = { val cpos = serverAdr indexOf ':' - if (cpos < 0) { - fatal("malformed server address: " + serverAdr + "; exiting") - } else { + if (cpos < 0) + fatal("Malformed server address: " + serverAdr + "; exiting") + else { val hostName = serverAdr.substring(0, cpos) val port = try { Integer.parseInt(serverAdr.substring(cpos+1)) } catch { case ex: Throwable => - fatal("malformed server address: " + serverAdr + "; exiting") + fatal("Malformed server address: " + serverAdr + "; exiting") } getSocket(hostName, port) } @@ -209,8 +216,8 @@ object CompileSocket { try { new Socket(hostName, port) } catch { - case e: IOException => - fatal("unable to establish connection to server " + + case e: /*IO+Security*/Exception => + fatal("Unable to establish connection to server " + hostName + ":" + port + "; exiting") } diff --git a/src/compiler/scala/tools/util/SocketServer.scala b/src/compiler/scala/tools/util/SocketServer.scala index ddfeb3b679..c4d7bba64a 100644 --- a/src/compiler/scala/tools/util/SocketServer.scala +++ b/src/compiler/scala/tools/util/SocketServer.scala @@ -27,19 +27,19 @@ abstract class SocketServer { var out: PrintWriter = _ var in: BufferedReader = _ - private def error(msg: String) = { + def fatal(msg: String) = { System.err.println(msg) exit(1) } val port: int = try { - val s = new ServerSocket(0) + val s = new ServerSocket(0) // a port of 0 creates a socket on any free port. val p = s.getLocalPort() s.close() p } catch { case e: IOException => - error("Could not listen on any port; exiting.") + fatal("Could not listen on any port; exiting.") } def run(): unit = { @@ -48,13 +48,13 @@ abstract class SocketServer { new ServerSocket(port) } catch { case e: IOException => - error("Could not listen on port: " + port + "; exiting.") + fatal("Could not listen on port: " + port + "; exiting.") } val clientSocket = try { serverSocket.accept() } catch { case e: IOException => - error("Accept on port " + port + " failed; exiting.") + fatal("Accept on port " + port + " failed; exiting.") } out = new PrintWriter(clientSocket.getOutputStream(), true) -- cgit v1.2.3