[Daemon] Introduce the way to get Kotlin daemon compiler version

#KT-48294 In Progress
This commit is contained in:
Alexander Likhachev
2021-08-27 17:53:09 +03:00
committed by Space
parent 815329df15
commit 612b96bd54
8 changed files with 43 additions and 0 deletions
@@ -142,6 +142,11 @@ class CompileServiceClientSideImpl(
return readMessage(id)
}
override suspend fun getKotlinVersion(): CompileService.CallResult<String> {
val id = sendMessage(GetKotlinVersionMessage())
return readMessage(id)
}
override suspend fun getDaemonJVMOptions(): CompileService.CallResult<DaemonJVMOptions> {
val id = sendMessage(GetDaemonJVMOptionsMessage())
val res = readMessage<CompileService.CallResult<DaemonJVMOptions>>(id)
@@ -258,6 +263,11 @@ class CompileServiceClientSideImpl(
sendReply(server.getDaemonInfo())
}
class GetKotlinVersionMessage : Server.Message<CompileServiceServerSide>() {
override suspend fun processImpl(server: CompileServiceServerSide, sendReply: (Any?) -> Unit) =
sendReply(server.getKotlinVersion())
}
class RegisterClientMessage(val aliveFlagPath: String?) : Server.Message<CompileServiceServerSide>() {
override suspend fun processImpl(server: CompileServiceServerSide, sendReply: (Any?) -> Unit) =
sendReply(server.registerClient(aliveFlagPath))
@@ -44,6 +44,10 @@ class CompileServiceRMIWrapper(val server: CompileServiceServerSide, daemonOptio
server.getDaemonInfo()
}
override fun getKotlinVersion() = runBlocking {
server.getKotlinVersion()
}
override fun getDaemonJVMOptions() = runBlocking {
server.getDaemonJVMOptions()
}
@@ -80,6 +80,9 @@ interface CompileService : Remote {
@Throws(RemoteException::class)
fun getDaemonInfo(): CallResult<String>
@Throws(RemoteException::class)
fun getKotlinVersion(): CallResult<String>
@Throws(RemoteException::class)
fun getDaemonJVMOptions(): CallResult<DaemonJVMOptions>
@@ -20,6 +20,8 @@ interface CompileServiceAsync {
suspend fun getDaemonInfo(): CompileService.CallResult<String>
suspend fun getKotlinVersion(): CompileService.CallResult<String>
suspend fun getDaemonJVMOptions(): CompileService.CallResult<DaemonJVMOptions>
suspend fun registerClient(aliveFlagPath: String?): CompileService.CallResult<Nothing>
@@ -58,6 +58,8 @@ class CompileServiceAsyncWrapper(
override suspend fun getDaemonInfo() =
rmiCompileService.getDaemonInfo()
override suspend fun getKotlinVersion() =
rmiCompileService.getKotlinVersion()
override suspend fun getDaemonJVMOptions() =
rmiCompileService.getDaemonJVMOptions()
@@ -144,6 +144,9 @@ class CompileServiceClientRMIWrapper(
asyncCompileService.getDaemonInfo()
}
override fun getKotlinVersion() = runBlocking {
asyncCompileService.getKotlinVersion()
}
override fun getDaemonJVMOptions() = runBlocking {
asyncCompileService.getDaemonJVMOptions()
@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.cli.jvm.compiler.jarfs.FastJarFileSystem
import org.jetbrains.kotlin.cli.jvm.compiler.jarfs.FastJarHandler
import org.jetbrains.kotlin.cli.metadata.K2MetadataCompiler
import org.jetbrains.kotlin.config.KotlinCompilerVersion
import org.jetbrains.kotlin.config.Services
import org.jetbrains.kotlin.daemon.common.*
import org.jetbrains.kotlin.daemon.report.CompileServicesFacadeMessageCollector
@@ -663,6 +664,14 @@ class CompileServiceImpl(
CompileService.CallResult.Good("Kotlin daemon on port $port")
}
override fun getKotlinVersion(): CompileService.CallResult<String> = ifAlive {
try {
CompileService.CallResult.Good(KotlinCompilerVersion.VERSION)
} catch (e: Exception) {
CompileService.CallResult.Error("Unknown Kotlin version")
}
}
override fun getDaemonOptions(): CompileService.CallResult<DaemonOptions> = ifAlive {
CompileService.CallResult.Good(daemonOptions)
}
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.cli.jvm.compiler.jarfs.FastJarFileSystem
import org.jetbrains.kotlin.cli.metadata.K2MetadataCompiler
import org.jetbrains.kotlin.config.KotlinCompilerVersion
import org.jetbrains.kotlin.config.Services
import org.jetbrains.kotlin.daemon.CompileServiceImplBase
import org.jetbrains.kotlin.daemon.CompilerSelector
@@ -230,6 +231,15 @@ class CompileServiceServerSideImpl(
CompileService.CallResult.Good("Kotlin daemon on socketPort $port")
}
override suspend fun getKotlinVersion(): CompileService.CallResult<String> =
ifAlive(minAliveness = Aliveness.Dying) {
try {
CompileService.CallResult.Good(KotlinCompilerVersion.VERSION)
} catch (e: Exception) {
CompileService.CallResult.Error("Unknown Kotlin version")
}
}
override suspend fun getDaemonOptions(): CompileService.CallResult<DaemonOptions> = ifAlive {
CompileService.CallResult.Good(daemonOptions)
}