Adding support for JS compilation on daemon

This commit is contained in:
Ilya Chernikov
2015-10-07 12:28:33 +02:00
parent 391c292b8d
commit 99b638a58b
7 changed files with 61 additions and 25 deletions
@@ -111,12 +111,12 @@ public object KotlinCompilerClient {
}
public fun compile(compiler: CompileService, args: Array<out String>, out: OutputStream): Int {
public fun compile(compilerService: CompileService, targetPlatform: CompileService.TargetPlatform, args: Array<out String>, out: OutputStream): Int {
val outStrm = RemoteOutputStreamServer(out)
val servicesFacade = CompilerCallbackServicesFacadeServer()
try {
return compiler.remoteCompile(args, servicesFacade, outStrm, CompileService.OutputFormat.PLAIN, outStrm)
return compilerService.remoteCompile(targetPlatform, args, servicesFacade, outStrm, CompileService.OutputFormat.PLAIN, outStrm)
}
finally {
servicesFacade.disconnect()
@@ -125,13 +125,23 @@ public object KotlinCompilerClient {
}
public fun incrementalCompile(compiler: CompileService, args: Array<out String>, services: CompilationServices, compilerOut: OutputStream, daemonOut: OutputStream, profiler: Profiler = DummyProfiler()): Int {
public fun incrementalCompile(compileService: CompileService,
targetPlatform: CompileService.TargetPlatform,
args: Array<out String>,
callbackServices: CompilationServices,
compilerOut: OutputStream,
daemonOut: OutputStream,
profiler: Profiler = DummyProfiler()
): Int {
val compilerOutStreamServer = RemoteOutputStreamServer(compilerOut)
val daemonOutStreamServer = RemoteOutputStreamServer(daemonOut)
val servicesFacade = CompilerCallbackServicesFacadeServer(incrementalCompilationComponents = services.incrementalCompilationComponents, compilationCancelledStatus = services.compilationCanceledStatus)
val servicesFacade = CompilerCallbackServicesFacadeServer(incrementalCompilationComponents = callbackServices.incrementalCompilationComponents,
compilationCancelledStatus = callbackServices.compilationCanceledStatus)
try {
return profiler.withMeasure(this) { compiler.remoteIncrementalCompile(args, servicesFacade, compilerOutStreamServer, CompileService.OutputFormat.XML, daemonOutStreamServer) }
return profiler.withMeasure(this) {
compileService.remoteIncrementalCompile(targetPlatform, args, servicesFacade, compilerOutStreamServer, CompileService.OutputFormat.XML, daemonOutStreamServer)
}
}
finally {
servicesFacade.disconnect()
@@ -202,7 +212,7 @@ public object KotlinCompilerClient {
val memBefore = daemon.getUsedMemory() / 1024
val startTime = System.nanoTime()
val res = daemon.remoteCompile(filteredArgs.toArrayList().toTypedArray(), servicesFacade, outStrm, CompileService.OutputFormat.PLAIN, outStrm)
val res = daemon.remoteCompile(CompileService.TargetPlatform.JVM, filteredArgs.toArrayList().toTypedArray(), servicesFacade, outStrm, CompileService.OutputFormat.PLAIN, outStrm)
val endTime = System.nanoTime()
println("Compilation result code: $res")
@@ -26,6 +26,11 @@ public interface CompileService : Remote {
XML
}
public enum class TargetPlatform : java.io.Serializable {
JVM,
JS
}
@Throws(RemoteException::class)
public fun getCompilerId(): CompilerId
@@ -37,15 +42,16 @@ public interface CompileService : Remote {
@Throws(RemoteException::class)
public fun remoteCompile(
targetPlatform: TargetPlatform,
args: Array<out String>,
servicesFacade: CompilerCallbackServicesFacade,
compilerOutputStream: RemoteOutputStream,
outputFormat: OutputFormat,
serviceOutputStream: RemoteOutputStream
outputFormat: OutputFormat, serviceOutputStream: RemoteOutputStream
): Int
@Throws(RemoteException::class)
public fun remoteIncrementalCompile(
targetPlatform: TargetPlatform,
args: Array<out String>,
servicesFacade: CompilerCallbackServicesFacade,
compilerOutputStream: RemoteOutputStream,
@@ -16,6 +16,8 @@
package org.jetbrains.kotlin.rmi.service
import org.jetbrains.kotlin.cli.common.CLICompiler
import org.jetbrains.kotlin.cli.js.K2JSCompiler
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
import org.jetbrains.kotlin.rmi.*
import java.io.File
@@ -133,8 +135,15 @@ public object CompileDaemon {
}
runFile.deleteOnExit()
val compiler = K2JVMCompiler()
val compilerService = CompileServiceImpl(registry, compiler, compilerId, daemonOptions, port)
val compilerSelector = object : CompilerSelector {
private val jvm by lazy { K2JVMCompiler() }
private val js by lazy { K2JSCompiler() }
override fun get(targetPlatform: CompileService.TargetPlatform): CLICompiler<*> = when (targetPlatform) {
CompileService.TargetPlatform.JVM -> jvm
CompileService.TargetPlatform.JS -> js
}
}
val compilerService = CompileServiceImpl(registry, compilerSelector, compilerId, daemonOptions, port)
if (daemonOptions.runFilesPath.isNotEmpty())
println(daemonOptions.runFilesPath)
@@ -35,9 +35,13 @@ import kotlin.concurrent.write
fun nowSeconds() = TimeUnit.NANOSECONDS.toSeconds(System.nanoTime())
class CompileServiceImpl<Compiler: CLICompiler<*>>(
interface CompilerSelector {
operator fun get(targetPlatform: CompileService.TargetPlatform): CLICompiler<*>
}
class CompileServiceImpl(
val registry: Registry,
val compiler: Compiler,
val compiler: CompilerSelector,
val selfCompilerId: CompilerId,
val daemonOptions: DaemonOptions,
port: Int
@@ -58,20 +62,21 @@ class CompileServiceImpl<Compiler: CLICompiler<*>>(
}
}
override fun remoteCompile(args: Array<out String>,
override fun remoteCompile(targetPlatform: CompileService.TargetPlatform,
args: Array<out String>,
servicesFacade: CompilerCallbackServicesFacade,
compilerOutputStream: RemoteOutputStream,
outputFormat: CompileService.OutputFormat,
serviceOutputStream: RemoteOutputStream
outputFormat: CompileService.OutputFormat, serviceOutputStream: RemoteOutputStream
): Int =
doCompile(args, compilerOutputStream, serviceOutputStream) { printStream, profiler ->
when (outputFormat) {
CompileService.OutputFormat.PLAIN -> compiler.exec(printStream, *args)
CompileService.OutputFormat.XML -> compiler.execAndOutputXml(printStream, createCompileServices(servicesFacade, profiler), *args)
CompileService.OutputFormat.PLAIN -> compiler[targetPlatform].exec(printStream, *args)
CompileService.OutputFormat.XML -> compiler[targetPlatform].execAndOutputXml(printStream, createCompileServices(servicesFacade, profiler), *args)
}
}
override fun remoteIncrementalCompile(args: Array<out String>,
override fun remoteIncrementalCompile(targetPlatform: CompileService.TargetPlatform,
args: Array<out String>,
servicesFacade: CompilerCallbackServicesFacade,
compilerOutputStream: RemoteOutputStream,
compilerOutputFormat: CompileService.OutputFormat,
@@ -80,7 +85,7 @@ class CompileServiceImpl<Compiler: CLICompiler<*>>(
doCompile(args, compilerOutputStream, serviceOutputStream) { printStream, profiler ->
when (compilerOutputFormat) {
CompileService.OutputFormat.PLAIN -> throw NotImplementedError("Only XML output is supported in remote incremental compilation")
CompileService.OutputFormat.XML -> compiler.execAndOutputXml(printStream, createCompileServices(servicesFacade, profiler), *args)
CompileService.OutputFormat.XML -> compiler[targetPlatform].execAndOutputXml(printStream, createCompileServices(servicesFacade, profiler), *args)
}
}