From 0c39358b5fdf2ef49d08d4f83d5fca8e3b0796d6 Mon Sep 17 00:00:00 2001 From: Sergey Rostov Date: Thu, 22 Nov 2018 14:54:01 +0300 Subject: [PATCH] JPS: fix testJpsDaemonIC 1. Checking for COMPILE_DAEMON_CUSTOM_RUN_FILES_PATH_FOR_TESTS was moved to COMPILE_DAEMON_DEFAULT_RUN_DIR_PATH. Looks like COMPILE_DAEMON_CUSTOM_RUN_FILES_PATH_FOR_TESTS was introduced incorrectly in 220fab0d3f0267df8c06d6c3a09429a515c66557. Checking of this property was added in DaemonOptions.runFilesPathOrDefault, while DaemonOptions.runFilesPath was internally used in runFilesPathOrDefault and in many other places. For example DaemonOptions.runFilesPath used to pass this option to daemon server. So daemon was started with runFilesPath that ignores COMPILE_DAEMON_CUSTOM_RUN_FILES_PATH_FOR_TESTS. 2. JpsKotlinCompilerRunner._jpsCompileServiceSession was leaked between tests. Fixed by extracting @TestOnly releaseCompileServiceSession() and calling it in tests tearDown() 3. The result of compileWithDaemon was ignored in compileWithDaemonOrFallback. So, the fallback was never called, and the FAIL_ON_FALLBACK_PROPERTY was actually was never worked. This was fixed. Also the message was improved to make it easier to find the original fail cause. --- .../kotlin/daemon/common/DaemonParams.kt | 7 +++--- .../jps/build/BaseKotlinJpsBuildTestCase.kt | 2 ++ .../compilerRunner/JpsKotlinCompilerRunner.kt | 25 ++++++++++++------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/DaemonParams.kt b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/DaemonParams.kt index f1abc5b4c74..fb17db5b4ac 100644 --- a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/DaemonParams.kt +++ b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/DaemonParams.kt @@ -52,7 +52,8 @@ val COMPILE_DAEMON_IS_READY_MESSAGE = "Kotlin compile daemon is ready" val COMPILE_DAEMON_CUSTOM_RUN_FILES_PATH_FOR_TESTS: String = "kotlin.daemon.custom.run.files.path.for.tests" val COMPILE_DAEMON_DEFAULT_RUN_DIR_PATH: String get() = - FileSystem.getRuntimeStateFilesPath("kotlin", "daemon") + System.getProperty(COMPILE_DAEMON_CUSTOM_RUN_FILES_PATH_FOR_TESTS) + ?: FileSystem.getRuntimeStateFilesPath("kotlin", "daemon") val CLASSPATH_ID_DIGEST = "MD5" @@ -226,9 +227,7 @@ data class DaemonOptions( // TODO: consider implementing generic approach to it or may be replace getters with ones returning default if necessary val DaemonOptions.runFilesPathOrDefault: String - get() = System.getProperty(COMPILE_DAEMON_CUSTOM_RUN_FILES_PATH_FOR_TESTS) - ?: runFilesPath.takeUnless { it.isBlank() } - ?: COMPILE_DAEMON_DEFAULT_RUN_DIR_PATH + get() = if (runFilesPath.isBlank()) COMPILE_DAEMON_DEFAULT_RUN_DIR_PATH else runFilesPath fun Iterable.distinctStringsDigest(): ByteArray = MessageDigest.getInstance(CLASSPATH_ID_DIGEST) diff --git a/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/BaseKotlinJpsBuildTestCase.kt b/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/BaseKotlinJpsBuildTestCase.kt index 8841eed766e..76267b23734 100644 --- a/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/BaseKotlinJpsBuildTestCase.kt +++ b/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/BaseKotlinJpsBuildTestCase.kt @@ -18,6 +18,7 @@ package org.jetbrains.kotlin.jps.build import org.jetbrains.jps.builders.JpsBuildTestCase import org.jetbrains.jps.model.library.JpsLibrary +import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner abstract class BaseKotlinJpsBuildTestCase : JpsBuildTestCase() { @Throws(Exception::class) @@ -32,6 +33,7 @@ abstract class BaseKotlinJpsBuildTestCase : JpsBuildTestCase() { super.tearDown() myModel = null myBuildParams.clear() + JpsKotlinCompilerRunner.releaseCompileServiceSession() } private val libraries = mutableMapOf() diff --git a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt index 4d8cc2b9566..09b44cbf83f 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.compilerRunner import com.intellij.util.xmlb.XmlSerializerUtil +import org.jetbrains.annotations.TestOnly import org.jetbrains.jps.api.GlobalOptions import org.jetbrains.kotlin.cli.common.ExitCode import org.jetbrains.kotlin.cli.common.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY @@ -52,16 +53,22 @@ class JpsKotlinCompilerRunner { @Volatile private var _jpsCompileServiceSession: CompileServiceSession? = null + @TestOnly + fun releaseCompileServiceSession() { + _jpsCompileServiceSession?.let { + try { + it.compileService.releaseCompileSession(it.sessionId) + } catch (_: Throwable) { + } + } + _jpsCompileServiceSession = null + } + @Synchronized private fun getOrCreateDaemonConnection(newConnection: () -> CompileServiceSession?): CompileServiceSession? { // TODO: consider adding state "ping" to the daemon interface if (_jpsCompileServiceSession == null || _jpsCompileServiceSession!!.compileService.getDaemonOptions() !is CompileService.CallResult.Good) { - _jpsCompileServiceSession?.let { - try { - it.compileService.releaseCompileSession(it.sessionId) - } catch (_: Throwable) { - } - } + releaseCompileServiceSession() _jpsCompileServiceSession = newConnection() } @@ -180,7 +187,7 @@ class JpsKotlinCompilerRunner { compilerClassName: String, compilerArgs: CommonCompilerArguments, environment: JpsCompilerEnvironment - ) { + ): Int? { val targetPlatform = when (compilerClassName) { KotlinCompilerClass.JVM -> CompileService.TargetPlatform.JVM KotlinCompilerClass.JS -> CompileService.TargetPlatform.JS @@ -196,7 +203,7 @@ class JpsKotlinCompilerRunner { reportSeverity(verbose), requestedCompilationResults = emptyArray() ) - doWithDaemon(environment) { sessionId, daemon -> + return doWithDaemon(environment) { sessionId, daemon -> environment.withProgressReporter { progress -> progress.compilationStarted() daemon.compile( @@ -265,7 +272,7 @@ class JpsKotlinCompilerRunner { environment: JpsCompilerEnvironment ) { if ("true" == System.getProperty("kotlin.jps.tests") && "true" == System.getProperty(FAIL_ON_FALLBACK_PROPERTY)) { - error("Fallback strategy is disabled in tests!") + error("Cannot compile with Daemon, see logs bellow. Fallback strategy is disabled in tests") } // otherwise fallback to in-process