From e12a5b88acd80a41574d51c88a7776f99c3d2580 Mon Sep 17 00:00:00 2001 From: James Iry Date: Wed, 16 Jan 2013 16:44:44 -0800 Subject: SI-6987 Fixes fsc compile server verbose output Internally the fsc server code was setting a "verbose" flag, but it was always false. Fixing that gives server's verbose output, but because the output was buffered and not flushed the server's output wasn't seen until the compile run was complete. This commit fixes the verbose flag and flushes the server side output. --- src/compiler/scala/tools/nsc/CompileServer.scala | 3 ++- src/compiler/scala/tools/util/SocketServer.scala | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/compiler/scala/tools/nsc/CompileServer.scala b/src/compiler/scala/tools/nsc/CompileServer.scala index c23c1e6154..74118d1e20 100644 --- a/src/compiler/scala/tools/nsc/CompileServer.scala +++ b/src/compiler/scala/tools/nsc/CompileServer.scala @@ -92,10 +92,11 @@ class StandardCompileServer extends SocketServer { val args = input.split("\0", -1).toList val newSettings = new FscSettings(fscError) - this.verbose = newSettings.verbose.value val command = newOfflineCompilerCommand(args, newSettings) + this.verbose = newSettings.verbose.value info("Settings after normalizing paths: " + newSettings) + if (!command.files.isEmpty) info("Input files after normalizing paths: " + (command.files mkString ",")) printMemoryStats() // Update the idle timeout if given diff --git a/src/compiler/scala/tools/util/SocketServer.scala b/src/compiler/scala/tools/util/SocketServer.scala index d29a370c28..21775a01d1 100644 --- a/src/compiler/scala/tools/util/SocketServer.scala +++ b/src/compiler/scala/tools/util/SocketServer.scala @@ -16,7 +16,7 @@ trait CompileOutputCommon { def verbose: Boolean def info(msg: String) = if (verbose) echo(msg) - def echo(msg: String) = Console println msg + def echo(msg: String) = {Console println msg; Console.flush} def warn(msg: String) = System.err println msg def fatal(msg: String) = { warn(msg) ; sys.exit(1) } } -- cgit v1.2.3 From 1dab5bf91361b8d6073db05ba1dff1bc01a83220 Mon Sep 17 00:00:00 2001 From: James Iry Date: Thu, 17 Jan 2013 11:46:10 -0800 Subject: SI-6987 Tests fsc verbose output This commit includes a test of fsc's verbose output. In order for it to work, CompileServer's main method had to be modified to remove a sys exit 0 at the end. It was redundant and made testing a bit harder. In order to prevent a race condition between server and client start up, this commit also adds a server callback that decrements a CountDownLatch that the main testing thread waits for. Finally, the server had to be modified to use Console.withErr and Console.withOut instead of mutating the global System.err and System.out variables. Otherwise the test would be unreliable. --- src/compiler/scala/tools/nsc/CompileServer.scala | 41 ++++++++++++++-------- src/compiler/scala/tools/util/SocketServer.scala | 2 +- test/files/run/t6987.check | 1 + test/files/run/t6987.scala | 43 ++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 15 deletions(-) create mode 100644 test/files/run/t6987.check create mode 100644 test/files/run/t6987.scala diff --git a/src/compiler/scala/tools/nsc/CompileServer.scala b/src/compiler/scala/tools/nsc/CompileServer.scala index 74118d1e20..7a0a072bb8 100644 --- a/src/compiler/scala/tools/nsc/CompileServer.scala +++ b/src/compiler/scala/tools/nsc/CompileServer.scala @@ -174,11 +174,22 @@ object CompileServer extends StandardCompileServer { /** A directory holding redirected output */ private lazy val redirectDir = (compileSocket.tmpDir / "output-redirects").createDirectory() - private def redirect(setter: PrintStream => Unit, filename: String) { - setter(new PrintStream((redirectDir / filename).createFile().bufferedOutput())) - } - - def main(args: Array[String]) { + private def createRedirect(filename: String) = + new PrintStream((redirectDir / filename).createFile().bufferedOutput()) + + def main(args: Array[String]) = + execute(() => (), args) + + /** + * Used for internal testing. The callback is called upon + * server start, notifying the caller that the server is + * ready to run. WARNING: the callback runs in the + * server's thread, blocking the server from doing any work + * until the callback is finished. Callbacks should be kept + * simple and clients should not try to interact with the + * server while the callback is processing. + */ + def execute(startupCallback : () => Unit, args: Array[String]) { val debug = args contains "-v" if (debug) { @@ -186,14 +197,16 @@ object CompileServer extends StandardCompileServer { 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+"...") - System.err.flush() - compileSocket setPort port - run() - - compileSocket deletePort port - sys exit 0 + Console.withErr(createRedirect("scala-compile-server-err.log")) { + Console.withOut(createRedirect("scala-compile-server-out.log")) { + Console.err.println("...starting server on socket "+port+"...") + Console.err.flush() + compileSocket setPort port + startupCallback() + run() + + compileSocket deletePort port + } + } } } diff --git a/src/compiler/scala/tools/util/SocketServer.scala b/src/compiler/scala/tools/util/SocketServer.scala index 21775a01d1..1b06ce2ff2 100644 --- a/src/compiler/scala/tools/util/SocketServer.scala +++ b/src/compiler/scala/tools/util/SocketServer.scala @@ -17,7 +17,7 @@ trait CompileOutputCommon { def info(msg: String) = if (verbose) echo(msg) def echo(msg: String) = {Console println msg; Console.flush} - def warn(msg: String) = System.err println msg + def warn(msg: String) = {Console.err println msg; Console.flush} def fatal(msg: String) = { warn(msg) ; sys.exit(1) } } diff --git a/test/files/run/t6987.check b/test/files/run/t6987.check new file mode 100644 index 0000000000..86fc96c679 --- /dev/null +++ b/test/files/run/t6987.check @@ -0,0 +1 @@ +got successful verbose results! diff --git a/test/files/run/t6987.scala b/test/files/run/t6987.scala new file mode 100644 index 0000000000..37e91d61ae --- /dev/null +++ b/test/files/run/t6987.scala @@ -0,0 +1,43 @@ +import java.io._ +import tools.nsc.{CompileClient, CompileServer} +import java.util.concurrent.{CountDownLatch, TimeUnit} + +object Test extends App { + val startupLatch = new CountDownLatch(1) + // we have to explicitly launch our server because when the client launches a server it uses + // the "scala" shell command meaning whatever version of scala (and whatever version of libraries) + // happens to be in the path gets used + val t = new Thread(new Runnable { + def run() = { + CompileServer.execute(() => startupLatch.countDown(), Array[String]()) + } + }) + t setDaemon true + t.start() + if (!startupLatch.await(2, TimeUnit.MINUTES)) + sys error "Timeout waiting for server to start" + + val baos = new ByteArrayOutputStream() + val ps = new PrintStream(baos) + + val success = (scala.Console withOut ps) { + // shut down the server via the client using the verbose flag + CompileClient.process(Array("-shutdown", "-verbose")) + } + + // now make sure we got success and a verbose result + val msg = baos.toString() + + if (success) { + if (msg contains "Settings after normalizing paths") { + println("got successful verbose results!") + } else { + println("did not get the string expected, full results were:") + println(msg) + } + } else { + println("got a failure. Full results were:") + println(msg) + } + scala.Console.flush +} -- cgit v1.2.3