Adding support for JS compilation on daemon
This commit is contained in:
@@ -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 outStrm = RemoteOutputStreamServer(out)
|
||||||
val servicesFacade = CompilerCallbackServicesFacadeServer()
|
val servicesFacade = CompilerCallbackServicesFacadeServer()
|
||||||
try {
|
try {
|
||||||
return compiler.remoteCompile(args, servicesFacade, outStrm, CompileService.OutputFormat.PLAIN, outStrm)
|
return compilerService.remoteCompile(targetPlatform, args, servicesFacade, outStrm, CompileService.OutputFormat.PLAIN, outStrm)
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
servicesFacade.disconnect()
|
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 compilerOutStreamServer = RemoteOutputStreamServer(compilerOut)
|
||||||
val daemonOutStreamServer = RemoteOutputStreamServer(daemonOut)
|
val daemonOutStreamServer = RemoteOutputStreamServer(daemonOut)
|
||||||
val servicesFacade = CompilerCallbackServicesFacadeServer(incrementalCompilationComponents = services.incrementalCompilationComponents, compilationCancelledStatus = services.compilationCanceledStatus)
|
val servicesFacade = CompilerCallbackServicesFacadeServer(incrementalCompilationComponents = callbackServices.incrementalCompilationComponents,
|
||||||
|
compilationCancelledStatus = callbackServices.compilationCanceledStatus)
|
||||||
try {
|
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 {
|
finally {
|
||||||
servicesFacade.disconnect()
|
servicesFacade.disconnect()
|
||||||
@@ -202,7 +212,7 @@ public object KotlinCompilerClient {
|
|||||||
val memBefore = daemon.getUsedMemory() / 1024
|
val memBefore = daemon.getUsedMemory() / 1024
|
||||||
val startTime = System.nanoTime()
|
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()
|
val endTime = System.nanoTime()
|
||||||
println("Compilation result code: $res")
|
println("Compilation result code: $res")
|
||||||
|
|||||||
@@ -26,6 +26,11 @@ public interface CompileService : Remote {
|
|||||||
XML
|
XML
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum class TargetPlatform : java.io.Serializable {
|
||||||
|
JVM,
|
||||||
|
JS
|
||||||
|
}
|
||||||
|
|
||||||
@Throws(RemoteException::class)
|
@Throws(RemoteException::class)
|
||||||
public fun getCompilerId(): CompilerId
|
public fun getCompilerId(): CompilerId
|
||||||
|
|
||||||
@@ -37,15 +42,16 @@ public interface CompileService : Remote {
|
|||||||
|
|
||||||
@Throws(RemoteException::class)
|
@Throws(RemoteException::class)
|
||||||
public fun remoteCompile(
|
public fun remoteCompile(
|
||||||
|
targetPlatform: TargetPlatform,
|
||||||
args: Array<out String>,
|
args: Array<out String>,
|
||||||
servicesFacade: CompilerCallbackServicesFacade,
|
servicesFacade: CompilerCallbackServicesFacade,
|
||||||
compilerOutputStream: RemoteOutputStream,
|
compilerOutputStream: RemoteOutputStream,
|
||||||
outputFormat: OutputFormat,
|
outputFormat: OutputFormat, serviceOutputStream: RemoteOutputStream
|
||||||
serviceOutputStream: RemoteOutputStream
|
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
@Throws(RemoteException::class)
|
@Throws(RemoteException::class)
|
||||||
public fun remoteIncrementalCompile(
|
public fun remoteIncrementalCompile(
|
||||||
|
targetPlatform: TargetPlatform,
|
||||||
args: Array<out String>,
|
args: Array<out String>,
|
||||||
servicesFacade: CompilerCallbackServicesFacade,
|
servicesFacade: CompilerCallbackServicesFacade,
|
||||||
compilerOutputStream: RemoteOutputStream,
|
compilerOutputStream: RemoteOutputStream,
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.rmi.service
|
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.cli.jvm.K2JVMCompiler
|
||||||
import org.jetbrains.kotlin.rmi.*
|
import org.jetbrains.kotlin.rmi.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -133,8 +135,15 @@ public object CompileDaemon {
|
|||||||
}
|
}
|
||||||
runFile.deleteOnExit()
|
runFile.deleteOnExit()
|
||||||
|
|
||||||
val compiler = K2JVMCompiler()
|
val compilerSelector = object : CompilerSelector {
|
||||||
val compilerService = CompileServiceImpl(registry, compiler, compilerId, daemonOptions, port)
|
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())
|
if (daemonOptions.runFilesPath.isNotEmpty())
|
||||||
println(daemonOptions.runFilesPath)
|
println(daemonOptions.runFilesPath)
|
||||||
|
|||||||
@@ -35,9 +35,13 @@ import kotlin.concurrent.write
|
|||||||
|
|
||||||
fun nowSeconds() = TimeUnit.NANOSECONDS.toSeconds(System.nanoTime())
|
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 registry: Registry,
|
||||||
val compiler: Compiler,
|
val compiler: CompilerSelector,
|
||||||
val selfCompilerId: CompilerId,
|
val selfCompilerId: CompilerId,
|
||||||
val daemonOptions: DaemonOptions,
|
val daemonOptions: DaemonOptions,
|
||||||
port: Int
|
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,
|
servicesFacade: CompilerCallbackServicesFacade,
|
||||||
compilerOutputStream: RemoteOutputStream,
|
compilerOutputStream: RemoteOutputStream,
|
||||||
outputFormat: CompileService.OutputFormat,
|
outputFormat: CompileService.OutputFormat, serviceOutputStream: RemoteOutputStream
|
||||||
serviceOutputStream: RemoteOutputStream
|
|
||||||
): Int =
|
): Int =
|
||||||
doCompile(args, compilerOutputStream, serviceOutputStream) { printStream, profiler ->
|
doCompile(args, compilerOutputStream, serviceOutputStream) { printStream, profiler ->
|
||||||
when (outputFormat) {
|
when (outputFormat) {
|
||||||
CompileService.OutputFormat.PLAIN -> compiler.exec(printStream, *args)
|
CompileService.OutputFormat.PLAIN -> compiler[targetPlatform].exec(printStream, *args)
|
||||||
CompileService.OutputFormat.XML -> compiler.execAndOutputXml(printStream, createCompileServices(servicesFacade, profiler), *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,
|
servicesFacade: CompilerCallbackServicesFacade,
|
||||||
compilerOutputStream: RemoteOutputStream,
|
compilerOutputStream: RemoteOutputStream,
|
||||||
compilerOutputFormat: CompileService.OutputFormat,
|
compilerOutputFormat: CompileService.OutputFormat,
|
||||||
@@ -80,7 +85,7 @@ class CompileServiceImpl<Compiler: CLICompiler<*>>(
|
|||||||
doCompile(args, compilerOutputStream, serviceOutputStream) { printStream, profiler ->
|
doCompile(args, compilerOutputStream, serviceOutputStream) { printStream, profiler ->
|
||||||
when (compilerOutputFormat) {
|
when (compilerOutputFormat) {
|
||||||
CompileService.OutputFormat.PLAIN -> throw NotImplementedError("Only XML output is supported in remote incremental compilation")
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class CompilerDaemonTest : KotlinIntegrationTestBase() {
|
|||||||
val daemon = KotlinCompilerClient.connectToCompileService(compilerId, daemonJVMOptions, daemonOptions, DaemonReportingTargets(out = System.err), autostart = true, checkId = true)
|
val daemon = KotlinCompilerClient.connectToCompileService(compilerId, daemonJVMOptions, daemonOptions, DaemonReportingTargets(out = System.err), autostart = true, checkId = true)
|
||||||
TestCase.assertNotNull("failed to connect daemon", daemon)
|
TestCase.assertNotNull("failed to connect daemon", daemon)
|
||||||
val strm = ByteArrayOutputStream()
|
val strm = ByteArrayOutputStream()
|
||||||
val code = KotlinCompilerClient.compile(daemon!!, args, strm)
|
val code = KotlinCompilerClient.compile(daemon!!, CompileService.TargetPlatform.JVM, args, strm)
|
||||||
return CompilerResults(code, strm.toString())
|
return CompilerResults(code, strm.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ public object KotlinCompilerRunner {
|
|||||||
|
|
||||||
val argsArray = argumentsList.toTypedArray()
|
val argsArray = argumentsList.toTypedArray()
|
||||||
|
|
||||||
if (!tryCompileWithDaemon(messageCollector, collector, environment, argsArray)) {
|
if (!tryCompileWithDaemon(compilerClassName, argsArray, environment, messageCollector, collector)) {
|
||||||
// otherwise fallback to in-process
|
// otherwise fallback to in-process
|
||||||
|
|
||||||
val stream = ByteArrayOutputStream()
|
val stream = ByteArrayOutputStream()
|
||||||
@@ -125,10 +125,10 @@ public object KotlinCompilerRunner {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun tryCompileWithDaemon(messageCollector: MessageCollector,
|
private fun tryCompileWithDaemon(compilerClassName: String,
|
||||||
collector: OutputItemsCollector,
|
argsArray: Array<String>,
|
||||||
environment: CompilerEnvironment,
|
environment: CompilerEnvironment,
|
||||||
argsArray: Array<String>): Boolean {
|
messageCollector: MessageCollector, collector: OutputItemsCollector): Boolean {
|
||||||
|
|
||||||
if (isDaemonEnabled()) {
|
if (isDaemonEnabled()) {
|
||||||
val libPath = CompilerRunnerUtil.getLibPath(environment.kotlinPaths, messageCollector)
|
val libPath = CompilerRunnerUtil.getLibPath(environment.kotlinPaths, messageCollector)
|
||||||
@@ -158,7 +158,12 @@ public object KotlinCompilerRunner {
|
|||||||
|
|
||||||
val profiler = if (daemonOptions.reportPerf) WallAndThreadTotalProfiler() else DummyProfiler()
|
val profiler = if (daemonOptions.reportPerf) WallAndThreadTotalProfiler() else DummyProfiler()
|
||||||
|
|
||||||
val res = KotlinCompilerClient.incrementalCompile(daemon, argsArray, services, compilerOut, daemonOut, profiler)
|
val targetPlatform = when (compilerClassName) {
|
||||||
|
K2JVM_COMPILER -> CompileService.TargetPlatform.JVM
|
||||||
|
K2JS_COMPILER -> CompileService.TargetPlatform.JS
|
||||||
|
else -> throw IllegalArgumentException("Unknown compiler type $compilerClassName")
|
||||||
|
}
|
||||||
|
val res = KotlinCompilerClient.incrementalCompile(daemon, targetPlatform, argsArray, services, compilerOut, daemonOut, profiler)
|
||||||
|
|
||||||
processCompilerOutput(messageCollector, collector, compilerOut, res.toString())
|
processCompilerOutput(messageCollector, collector, compilerOut, res.toString())
|
||||||
BufferedReader(StringReader(daemonOut.toString())).forEachLine {
|
BufferedReader(StringReader(daemonOut.toString())).forEachLine {
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ public class SimpleKotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
|
|||||||
rebuildAll()
|
rebuildAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: add JS tests
|
||||||
public fun testDaemon() {
|
public fun testDaemon() {
|
||||||
System.setProperty(COMPILE_DAEMON_ENABLED_PROPERTY,"")
|
System.setProperty(COMPILE_DAEMON_ENABLED_PROPERTY,"")
|
||||||
System.setProperty(COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY, "")
|
System.setProperty(COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY, "")
|
||||||
|
|||||||
Reference in New Issue
Block a user