summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2006-07-20 15:24:23 +0000
committermichelou <michelou@epfl.ch>2006-07-20 15:24:23 +0000
commit4146327bbd6b8e5468c05a570a9190c99c4285e3 (patch)
tree21bddbe652ad6de36ba9344cbdef55141503d294 /src/compiler/scala/tools/nsc
parentab9c3ee71d1c5ef758d47fd2d39c79e1dc68ca40 (diff)
downloadscala-4146327bbd6b8e5468c05a570a9190c99c4285e3.tar.gz
scala-4146327bbd6b8e5468c05a570a9190c99c4285e3.tar.bz2
scala-4146327bbd6b8e5468c05a570a9190c99c4285e3.zip
fsc prints more info messages with -verbose option
Diffstat (limited to 'src/compiler/scala/tools/nsc')
-rw-r--r--src/compiler/scala/tools/nsc/CompileClient.scala6
-rw-r--r--src/compiler/scala/tools/nsc/CompileServer.scala21
-rw-r--r--src/compiler/scala/tools/nsc/CompileSocket.scala67
3 files changed, 54 insertions, 40 deletions
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<flag>", "Pass <flag> 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")
}