summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorLex Spoon <lex@lexspoon.org>2007-01-18 15:30:56 +0000
committerLex Spoon <lex@lexspoon.org>2007-01-18 15:30:56 +0000
commit4aa9c242f169a1076466e0060f467845ba2d4132 (patch)
tree4f51b328efd4b78a2ffe9d3a9295bdf4c57e3e89 /src/compiler
parentaeb2770ea0398a67dd6966c9cf1b7190267f6925 (diff)
downloadscala-4aa9c242f169a1076466e0060f467845ba2d4132.tar.gz
scala-4aa9c242f169a1076466e0060f467845ba2d4132.tar.bz2
scala-4aa9c242f169a1076466e0060f467845ba2d4132.zip
When "fsc -shutdown" is requested, do not start...
When "fsc -shutdown" is requested, do not start a server if one is not already running.
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/CompileClient.scala9
-rw-r--r--src/compiler/scala/tools/nsc/CompileSocket.scala27
2 files changed, 28 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/CompileClient.scala b/src/compiler/scala/tools/nsc/CompileClient.scala
index 970becc5f5..3e78568660 100644
--- a/src/compiler/scala/tools/nsc/CompileClient.scala
+++ b/src/compiler/scala/tools/nsc/CompileClient.scala
@@ -24,6 +24,7 @@ object CompileClient {
var verbose = false
var version = false
+ var shutdown = false
/** Convert a filename to an absolute path */
def absFileName(path: String) = new File(path).getAbsolutePath()
@@ -53,6 +54,8 @@ object CompileClient {
verbose = true
} else if (arg == "-version") {
version = true
+ } else if (arg == "-shutdown") {
+ shutdown = true
}
i = i + 1
if (i < args.length) {
@@ -90,8 +93,12 @@ object CompileClient {
Console.println("[Server arguments: " + args.mkString("", " ", "]"))
Console.println("[VM arguments: " + vmArgs + "]")
}
- val socket = if (serverAdr == "") CompileSocket.getOrCreateSocket(vmArgs)
+ val socket = if (serverAdr == "") CompileSocket.getOrCreateSocket(vmArgs, !shutdown)
else CompileSocket.getSocket(serverAdr)
+ if(shutdown && (socket==null)) {
+ Console.println("[No compilation server running.]")
+ return 0
+ }
val out = new PrintWriter(socket.getOutputStream(), true)
val in = new BufferedReader(new InputStreamReader(socket.getInputStream()))
out.println(CompileSocket.getPassword(socket.getPort()))
diff --git a/src/compiler/scala/tools/nsc/CompileSocket.scala b/src/compiler/scala/tools/nsc/CompileSocket.scala
index 8499064cf3..ea953e1dd5 100644
--- a/src/compiler/scala/tools/nsc/CompileSocket.scala
+++ b/src/compiler/scala/tools/nsc/CompileSocket.scala
@@ -43,8 +43,10 @@ object CompileSocket {
/** A Pattern object for checking compiler output for errors */
val errorPattern = java.util.regex.Pattern.compile(errorRegex)
+ private def error(msg: String) = System.err.println(msg)
+
private def fatal(msg: String) = {
- System.err.println(msg)
+ error(msg)
exit(1)
}
@@ -145,11 +147,12 @@ object CompileSocket {
}
/** Get the port number to which a scala compile server is connected;
- * If no server is running yet, create one
+ * If no server is running yet, then create one.
*/
def getPort(vmArgs: String): int = {
var attempts = 0
var port = pollPort()
+
if (port < 0)
startNewServer(vmArgs)
while (port < 0 && attempts < MaxAttempts) {
@@ -178,13 +181,19 @@ object CompileSocket {
/** Delete the port number to which a scala compile server was connected */
def deletePort(port: int): unit = portFile(port).delete()
- def getOrCreateSocket(vmArgs: String): Socket = {
+ /** Get a socket connected to a daemon. If create is true, then
+ * create a new daemon if necessary. Returns null if the connection
+ * cannot be established.
+ */
+ def getOrCreateSocket(vmArgs: String, create: boolean): Socket = {
val nAttempts = 49 // try for about 5 seconds
def getsock(attempts: int): Socket =
- if (attempts == 0)
- fatal("Unable to establish connection to compilation daemon")
- else {
- val port = getPort(vmArgs)
+ if (attempts == 0) {
+ error("Unable to establish connection to compilation daemon")
+ null
+ } else {
+ val port = if(create) getPort(vmArgs) else pollPort()
+ if(port < 0) return null
val hostName = InetAddress.getLocalHost().getHostName()
try {
val result = new Socket(hostName, port)
@@ -207,6 +216,10 @@ object CompileSocket {
getsock(nAttempts)
}
+ /** Same as getOrCreateSocket(vmArgs, true). */
+ def getOrCreateSocket(vmArgs: String): Socket =
+ getOrCreateSocket(vmArgs, true)
+
def getSocket(serverAdr: String): Socket = {
val cpos = serverAdr indexOf ':'
if (cpos < 0)