From e2d2c5ff42d603f13884947a6961c25a88433e7e Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Fri, 23 Jun 2017 18:00:16 +0200 Subject: [PATCH] Refactor daemon startup for better logging and cleaner code --- .../daemon/client/KotlinCompilerClient.kt | 38 +++++++++++-------- .../common/CompilerServicesFacadeBase.kt | 2 - .../kotlin/daemon/CompilerApiTest.kt | 4 -- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt b/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt index 36e321f71ee..e95ec9d1961 100644 --- a/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt +++ b/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt @@ -93,22 +93,26 @@ object KotlinCompilerClient { leaseSession: Boolean, sessionAliveFlagFile: File? = null ): 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() val (service, newJVMOptions) = tryFindSuitableDaemonOrNewOpts(File(daemonOptions.runFilesPath), compilerId, daemonJVMOptions, { cat, msg -> reportingTargets.report(cat, msg) }) + if (service != null) { - // the newJVMOptions could be checked here for additional parameters, if needed - service.registerClient(clientAliveFlagFile.absolutePath) - reportingTargets.report(DaemonReportCategory.DEBUG, "connected to the daemon") - 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") + service.leaseImpl() + } + else { if (!isLastAttempt && autostart) { startDaemon(compilerId, newJVMOptions, daemonOptions, reportingTargets) reportingTargets.report(DaemonReportCategory.DEBUG, "new daemon started, trying to find it") @@ -315,9 +319,11 @@ object KotlinCompilerClient { if (res != null) return res - reportingTargets.report(DaemonReportCategory.INFO, - (if (attempts >= DAEMON_CONNECT_CYCLE_ATTEMPTS || !autostart) "no more retries on: " else "retrying($attempts) on: ") - + err?.toString()) + if (err != null) { + reportingTargets.report(DaemonReportCategory.INFO, + (if (attempts >= DAEMON_CONNECT_CYCLE_ATTEMPTS || !autostart) "no more retries on: " else "retrying($attempts) on: ") + + err?.toString()) + } if (attempts++ > DAEMON_CONNECT_CYCLE_ATTEMPTS || !autostart) { return null diff --git a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilerServicesFacadeBase.kt b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilerServicesFacadeBase.kt index 700fbc9ead1..0e65caa0de6 100644 --- a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilerServicesFacadeBase.kt +++ b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilerServicesFacadeBase.kt @@ -16,8 +16,6 @@ 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.rmi.Remote import java.rmi.RemoteException diff --git a/compiler/tests/org/jetbrains/kotlin/daemon/CompilerApiTest.kt b/compiler/tests/org/jetbrains/kotlin/daemon/CompilerApiTest.kt index 13869568460..5113bd98c33 100644 --- a/compiler/tests/org/jetbrains/kotlin/daemon/CompilerApiTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/daemon/CompilerApiTest.kt @@ -123,8 +123,6 @@ class CompilerApiTest : KotlinIntegrationTestBase() { verbose = true, reportPerf = true) - KotlinCompilerClient.shutdownCompileService(compilerId, daemonOptions) - val logFile = createTempFile("kotlin-daemon-test.", ".log") val daemonJVMOptions = configureDaemonJVMOptions("D$COMPILE_DAEMON_LOG_PATH_PROPERTY=\"${logFile.loggerCompatiblePath}\"", @@ -164,8 +162,6 @@ class CompilerApiTest : KotlinIntegrationTestBase() { verbose = true, reportPerf = true) - KotlinCompilerClient.shutdownCompileService(compilerId, daemonOptions) - val logFile = createTempFile("kotlin-daemon-test.", ".log") val daemonJVMOptions = configureDaemonJVMOptions("D$COMPILE_DAEMON_LOG_PATH_PROPERTY=\"${logFile.loggerCompatiblePath}\"",