Refactor daemon startup for better logging and cleaner code
This commit is contained in:
+22
-16
@@ -93,22 +93,26 @@ object KotlinCompilerClient {
|
|||||||
leaseSession: Boolean,
|
leaseSession: Boolean,
|
||||||
sessionAliveFlagFile: File? = null
|
sessionAliveFlagFile: File? = null
|
||||||
): CompileServiceSession? = connectLoop(reportingTargets, autostart) { isLastAttempt ->
|
): CompileServiceSession? = connectLoop(reportingTargets, autostart) { isLastAttempt ->
|
||||||
|
|
||||||
|
fun CompileService.leaseImpl(): CompileServiceSession? {
|
||||||
|
// the newJVMOptions could be checked here for additional parameters, if needed
|
||||||
|
registerClient(clientAliveFlagFile.absolutePath)
|
||||||
|
reportingTargets.report(DaemonReportCategory.DEBUG, "connected to the daemon")
|
||||||
|
|
||||||
|
if (!leaseSession) return CompileServiceSession(this, CompileService.NO_SESSION)
|
||||||
|
|
||||||
|
return leaseCompileSession(sessionAliveFlagFile?.absolutePath).takeUnless { it is CompileService.CallResult.Dying }?.let {
|
||||||
|
CompileServiceSession(this, it.get())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ensureServerHostnameIsSetUp()
|
ensureServerHostnameIsSetUp()
|
||||||
val (service, newJVMOptions) = tryFindSuitableDaemonOrNewOpts(File(daemonOptions.runFilesPath), compilerId, daemonJVMOptions, { cat, msg -> reportingTargets.report(cat, msg) })
|
val (service, newJVMOptions) = tryFindSuitableDaemonOrNewOpts(File(daemonOptions.runFilesPath), compilerId, daemonJVMOptions, { cat, msg -> reportingTargets.report(cat, msg) })
|
||||||
|
|
||||||
if (service != null) {
|
if (service != null) {
|
||||||
// the newJVMOptions could be checked here for additional parameters, if needed
|
service.leaseImpl()
|
||||||
service.registerClient(clientAliveFlagFile.absolutePath)
|
}
|
||||||
reportingTargets.report(DaemonReportCategory.DEBUG, "connected to the daemon")
|
else {
|
||||||
if (!leaseSession) CompileServiceSession(service, CompileService.NO_SESSION)
|
|
||||||
else {
|
|
||||||
val sessionId = service.leaseCompileSession(sessionAliveFlagFile?.absolutePath)
|
|
||||||
if (sessionId is CompileService.CallResult.Dying)
|
|
||||||
null
|
|
||||||
else
|
|
||||||
CompileServiceSession(service, sessionId.get())
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
reportingTargets.report(DaemonReportCategory.DEBUG, "no suitable daemon found")
|
|
||||||
if (!isLastAttempt && autostart) {
|
if (!isLastAttempt && autostart) {
|
||||||
startDaemon(compilerId, newJVMOptions, daemonOptions, reportingTargets)
|
startDaemon(compilerId, newJVMOptions, daemonOptions, reportingTargets)
|
||||||
reportingTargets.report(DaemonReportCategory.DEBUG, "new daemon started, trying to find it")
|
reportingTargets.report(DaemonReportCategory.DEBUG, "new daemon started, trying to find it")
|
||||||
@@ -315,9 +319,11 @@ object KotlinCompilerClient {
|
|||||||
|
|
||||||
if (res != null) return res
|
if (res != null) return res
|
||||||
|
|
||||||
reportingTargets.report(DaemonReportCategory.INFO,
|
if (err != null) {
|
||||||
(if (attempts >= DAEMON_CONNECT_CYCLE_ATTEMPTS || !autostart) "no more retries on: " else "retrying($attempts) on: ")
|
reportingTargets.report(DaemonReportCategory.INFO,
|
||||||
+ err?.toString())
|
(if (attempts >= DAEMON_CONNECT_CYCLE_ATTEMPTS || !autostart) "no more retries on: " else "retrying($attempts) on: ")
|
||||||
|
+ err?.toString())
|
||||||
|
}
|
||||||
|
|
||||||
if (attempts++ > DAEMON_CONNECT_CYCLE_ATTEMPTS || !autostart) {
|
if (attempts++ > DAEMON_CONNECT_CYCLE_ATTEMPTS || !autostart) {
|
||||||
return null
|
return null
|
||||||
|
|||||||
-2
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.daemon.common
|
package org.jetbrains.kotlin.daemon.common
|
||||||
|
|
||||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
|
|
||||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
import java.rmi.Remote
|
import java.rmi.Remote
|
||||||
import java.rmi.RemoteException
|
import java.rmi.RemoteException
|
||||||
|
|||||||
@@ -123,8 +123,6 @@ class CompilerApiTest : KotlinIntegrationTestBase() {
|
|||||||
verbose = true,
|
verbose = true,
|
||||||
reportPerf = true)
|
reportPerf = true)
|
||||||
|
|
||||||
KotlinCompilerClient.shutdownCompileService(compilerId, daemonOptions)
|
|
||||||
|
|
||||||
val logFile = createTempFile("kotlin-daemon-test.", ".log")
|
val logFile = createTempFile("kotlin-daemon-test.", ".log")
|
||||||
|
|
||||||
val daemonJVMOptions = configureDaemonJVMOptions("D$COMPILE_DAEMON_LOG_PATH_PROPERTY=\"${logFile.loggerCompatiblePath}\"",
|
val daemonJVMOptions = configureDaemonJVMOptions("D$COMPILE_DAEMON_LOG_PATH_PROPERTY=\"${logFile.loggerCompatiblePath}\"",
|
||||||
@@ -164,8 +162,6 @@ class CompilerApiTest : KotlinIntegrationTestBase() {
|
|||||||
verbose = true,
|
verbose = true,
|
||||||
reportPerf = true)
|
reportPerf = true)
|
||||||
|
|
||||||
KotlinCompilerClient.shutdownCompileService(compilerId, daemonOptions)
|
|
||||||
|
|
||||||
val logFile = createTempFile("kotlin-daemon-test.", ".log")
|
val logFile = createTempFile("kotlin-daemon-test.", ".log")
|
||||||
|
|
||||||
val daemonJVMOptions = configureDaemonJVMOptions("D$COMPILE_DAEMON_LOG_PATH_PROPERTY=\"${logFile.loggerCompatiblePath}\"",
|
val daemonJVMOptions = configureDaemonJVMOptions("D$COMPILE_DAEMON_LOG_PATH_PROPERTY=\"${logFile.loggerCompatiblePath}\"",
|
||||||
|
|||||||
Reference in New Issue
Block a user