summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/CompileClient.scala
blob: 752e9a79300806256b2984ec325e2c85f84ad401 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* NSC -- new Scala compiler
 * Copyright 2005-2011 LAMP/EPFL
 * @author  Martin Odersky
 */

package scala.tools.nsc

import java.io.{ BufferedReader, File, InputStreamReader, PrintWriter }
import Properties.fileEndings
import io.Path
import settings.FscSettings

/** The client part of the fsc offline compiler.  Instead of compiling
 *  things itself, it send requests to a CompileServer.
 */
class StandardCompileClient extends HasCompileSocket {
  lazy val compileSocket: CompileSocket = CompileSocket

  val versionMsg  = "Fast " + Properties.versionMsg
  var verbose = false

  def main0(argsIn: Array[String]): Int = {
    // TODO: put -J -and -D options back.  Right now they are lost
    // because bash parses them out and they don't arrive.
    val (vmArgs, fscArgs) = (Nil, argsIn.toList)
    val settings = new FscSettings
    val command  = new CompilerCommand(fscArgs, settings)
    verbose = settings.verbose.value
    val shutdown = settings.shutdown.value

    if (settings.version.value) {
      Console println versionMsg
      return 0
    }
    if (verbose) {
      Console println fscArgs.mkString("[Given arguments: ", " ", "]")
      Console println vmArgs.mkString("[VM arguments: ", " ", "]")
    }
    val socket =
      if (settings.server.value == "") compileSocket.getOrCreateSocket(vmArgs mkString " ", !shutdown)
      else Some(compileSocket.getSocket(settings.server.value))

    val success = socket match {
      case Some(sock) => compileOnServer(sock, fscArgs)
      case _          =>
        Console.println(
          if (shutdown) "[No compilation server running.]"
          else "Compilation failed."
        )
        shutdown
    }
    if (success) 1 else 0
  }
}

object CompileClient extends StandardCompileClient {
  def main(args: Array[String]): Unit = sys exit {
    try main0(args)
    catch { case _: Exception => 1 }
  }
}