Update tests after compiler properties rework

#KT-43605 Fixed
This commit is contained in:
Alexander Likhachev
2021-02-14 09:53:16 +03:00
parent 3537c699b5
commit 70d434e992
10 changed files with 63 additions and 53 deletions
@@ -45,6 +45,8 @@ enum class CompilerSystemProperties(val property: String) {
systemPropertySetter(property, value!!) systemPropertySetter(property, value!!)
} }
fun clear(): String? = systemPropertyCleaner(property)
companion object { companion object {
var systemPropertyGetter: (String) -> String? = { var systemPropertyGetter: (String) -> String? = {
System.getProperty(it) System.getProperty(it)
@@ -53,6 +55,10 @@ enum class CompilerSystemProperties(val property: String) {
var systemPropertySetter: (String, String) -> String? = { key, value -> var systemPropertySetter: (String, String) -> String? = { key, value ->
System.setProperty(key, value) System.setProperty(key, value)
} }
var systemPropertyCleaner: (String) -> String? = { key ->
System.clearProperty(key)
}
} }
} }
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.daemon package org.jetbrains.kotlin.daemon
import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.ApplicationManager
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation
@@ -127,7 +128,7 @@ class CompilerApiTest : KotlinIntegrationTestBase() {
val logFile: Path = createTempFile("kotlin-daemon-test.", ".log") val logFile: Path = createTempFile("kotlin-daemon-test.", ".log")
val daemonJVMOptions = configureDaemonJVMOptions("D$COMPILE_DAEMON_LOG_PATH_PROPERTY=\"${logFile.loggerCompatiblePath}\"", val daemonJVMOptions = configureDaemonJVMOptions("D${CompilerSystemProperties.COMPILE_DAEMON_LOG_PATH_PROPERTY.property}=\"${logFile.loggerCompatiblePath}\"",
inheritMemoryLimits = false, inheritOtherJvmOptions = false, inheritAdditionalProperties = false) inheritMemoryLimits = false, inheritOtherJvmOptions = false, inheritAdditionalProperties = false)
val jar = tmpdir.absolutePath + File.separator + "hello.jar" val jar = tmpdir.absolutePath + File.separator + "hello.jar"
@@ -167,7 +168,7 @@ class CompilerApiTest : KotlinIntegrationTestBase() {
val logFile: Path = createTempFile("kotlin-daemon-test.", ".log") val logFile: Path = createTempFile("kotlin-daemon-test.", ".log")
val daemonJVMOptions = configureDaemonJVMOptions("D$COMPILE_DAEMON_LOG_PATH_PROPERTY=\"${logFile.loggerCompatiblePath}\"", val daemonJVMOptions = configureDaemonJVMOptions("D${CompilerSystemProperties.COMPILE_DAEMON_LOG_PATH_PROPERTY.property}=\"${logFile.loggerCompatiblePath}\"",
inheritMemoryLimits = false, inheritOtherJvmOptions = false, inheritAdditionalProperties = false) inheritMemoryLimits = false, inheritOtherJvmOptions = false, inheritAdditionalProperties = false)
try { try {
val (code, outputs) = compileOnDaemon( val (code, outputs) = compileOnDaemon(
@@ -20,6 +20,7 @@ import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.io.FileUtilRt import com.intellij.openapi.util.io.FileUtilRt
import junit.framework.TestCase import junit.framework.TestCase
import org.jetbrains.kotlin.cli.AbstractCliTest import org.jetbrains.kotlin.cli.AbstractCliTest
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector
import org.jetbrains.kotlin.cli.common.repl.* import org.jetbrains.kotlin.cli.common.repl.*
@@ -109,7 +110,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
fun makeTestDaemonJvmOptions(logFile: File? = null, xmx: Int = 384, args: Iterable<String> = listOf()): DaemonJVMOptions { fun makeTestDaemonJvmOptions(logFile: File? = null, xmx: Int = 384, args: Iterable<String> = listOf()): DaemonJVMOptions {
val additionalArgs = arrayListOf<String>() val additionalArgs = arrayListOf<String>()
if (logFile != null) { if (logFile != null) {
additionalArgs.add("D$COMPILE_DAEMON_LOG_PATH_PROPERTY=\"${logFile.loggerCompatiblePath}\"") additionalArgs.add("D${CompilerSystemProperties.COMPILE_DAEMON_LOG_PATH_PROPERTY.property}=\"${logFile.loggerCompatiblePath}\"")
} }
args.forEach { additionalArgs.add(it) } args.forEach { additionalArgs.add(it) }
val baseOpts = if (xmx > 0) DaemonJVMOptions(maxMemory = "${xmx}m") else DaemonJVMOptions() val baseOpts = if (xmx > 0) DaemonJVMOptions(maxMemory = "${xmx}m") else DaemonJVMOptions()
@@ -160,16 +161,16 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
} }
fun testDaemonJvmOptionsParsing() { fun testDaemonJvmOptionsParsing() {
val backupJvmOptions = System.getProperty(COMPILE_DAEMON_JVM_OPTIONS_PROPERTY) val backupJvmOptions = System.getProperty(CompilerSystemProperties.COMPILE_DAEMON_JVM_OPTIONS_PROPERTY.property)
try { try {
System.setProperty(COMPILE_DAEMON_JVM_OPTIONS_PROPERTY, "-aaa,-bbb\\,ccc,-ddd,-Xmx200m,-XX:MaxMetaspaceSize=10k,-XX:ReservedCodeCacheSize=100,-xxx\\,yyy") System.setProperty(CompilerSystemProperties.COMPILE_DAEMON_JVM_OPTIONS_PROPERTY.property, "-aaa,-bbb\\,ccc,-ddd,-Xmx200m,-XX:MaxMetaspaceSize=10k,-XX:ReservedCodeCacheSize=100,-xxx\\,yyy")
val opts = configureDaemonJVMOptions(inheritMemoryLimits = false, inheritAdditionalProperties = false, inheritOtherJvmOptions = false) val opts = configureDaemonJVMOptions(inheritMemoryLimits = false, inheritAdditionalProperties = false, inheritOtherJvmOptions = false)
assertEquals("200m", opts.maxMemory) assertEquals("200m", opts.maxMemory)
assertEquals("10k", opts.maxMetaspaceSize) assertEquals("10k", opts.maxMetaspaceSize)
assertEquals("100", opts.reservedCodeCacheSize) assertEquals("100", opts.reservedCodeCacheSize)
assertEquals(arrayListOf("aaa", "bbb,ccc", "ddd", "xxx,yyy", "ea"), opts.jvmParams) assertEquals(arrayListOf("aaa", "bbb,ccc", "ddd", "xxx,yyy", "ea"), opts.jvmParams)
System.setProperty(COMPILE_DAEMON_JVM_OPTIONS_PROPERTY, "-Xmx300m,-XX:MaxMetaspaceSize=10k,-XX:ReservedCodeCacheSize=100") System.setProperty(CompilerSystemProperties.COMPILE_DAEMON_JVM_OPTIONS_PROPERTY.property, "-Xmx300m,-XX:MaxMetaspaceSize=10k,-XX:ReservedCodeCacheSize=100")
val opts2 = configureDaemonJVMOptions(inheritMemoryLimits = false, inheritAdditionalProperties = false, inheritOtherJvmOptions = false) val opts2 = configureDaemonJVMOptions(inheritMemoryLimits = false, inheritAdditionalProperties = false, inheritOtherJvmOptions = false)
assertEquals("300m", opts2.maxMemory) assertEquals("300m", opts2.maxMemory)
assertEquals( -1, DaemonJVMOptionsMemoryComparator().compare(opts, opts2)) assertEquals( -1, DaemonJVMOptionsMemoryComparator().compare(opts, opts2))
@@ -178,14 +179,14 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
val myXmxParam = ManagementFactory.getRuntimeMXBean().inputArguments.first { it.startsWith("-Xmx") } val myXmxParam = ManagementFactory.getRuntimeMXBean().inputArguments.first { it.startsWith("-Xmx") }
TestCase.assertNotNull(myXmxParam) TestCase.assertNotNull(myXmxParam)
val myXmxVal = myXmxParam.substring(4) val myXmxVal = myXmxParam.substring(4)
System.clearProperty(COMPILE_DAEMON_JVM_OPTIONS_PROPERTY) System.clearProperty(CompilerSystemProperties.COMPILE_DAEMON_JVM_OPTIONS_PROPERTY.property)
val opts3 = configureDaemonJVMOptions(inheritMemoryLimits = true, val opts3 = configureDaemonJVMOptions(inheritMemoryLimits = true,
inheritOtherJvmOptions = true, inheritOtherJvmOptions = true,
inheritAdditionalProperties = false) inheritAdditionalProperties = false)
assertEquals(myXmxVal, opts3.maxMemory) assertEquals(myXmxVal, opts3.maxMemory)
} }
finally { finally {
restoreSystemProperty(COMPILE_DAEMON_JVM_OPTIONS_PROPERTY, backupJvmOptions) restoreSystemProperty(CompilerSystemProperties.COMPILE_DAEMON_JVM_OPTIONS_PROPERTY.property, backupJvmOptions)
} }
} }
@@ -215,12 +216,12 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
} }
private fun withDaemonJvmOptionsSetTo(newValue: String?, fn: () -> Unit) { private fun withDaemonJvmOptionsSetTo(newValue: String?, fn: () -> Unit) {
val backup = getAndSetSystemProperty(COMPILE_DAEMON_JVM_OPTIONS_PROPERTY, newValue) val backup = getAndSetSystemProperty(CompilerSystemProperties.COMPILE_DAEMON_JVM_OPTIONS_PROPERTY.property, newValue)
try { try {
fn() fn()
} finally { } finally {
getAndSetSystemProperty(COMPILE_DAEMON_JVM_OPTIONS_PROPERTY, backup) getAndSetSystemProperty(CompilerSystemProperties.COMPILE_DAEMON_JVM_OPTIONS_PROPERTY.property, backup)
} }
} }
@@ -237,15 +238,15 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
} }
fun testDaemonOptionsParsing() { fun testDaemonOptionsParsing() {
val backupOptions = System.getProperty(COMPILE_DAEMON_OPTIONS_PROPERTY) val backupOptions = System.getProperty(CompilerSystemProperties.COMPILE_DAEMON_OPTIONS_PROPERTY.property)
try { try {
System.setProperty(COMPILE_DAEMON_OPTIONS_PROPERTY, "runFilesPath=abcd,autoshutdownIdleSeconds=1111") System.setProperty(CompilerSystemProperties.COMPILE_DAEMON_OPTIONS_PROPERTY.property, "runFilesPath=abcd,autoshutdownIdleSeconds=1111")
val opts = configureDaemonOptions(DaemonOptions(shutdownDelayMilliseconds = 1)) val opts = configureDaemonOptions(DaemonOptions(shutdownDelayMilliseconds = 1))
assertEquals("abcd", opts.runFilesPath) assertEquals("abcd", opts.runFilesPath)
assertEquals(1111, opts.autoshutdownIdleSeconds) assertEquals(1111, opts.autoshutdownIdleSeconds)
} }
finally { finally {
restoreSystemProperty(COMPILE_DAEMON_OPTIONS_PROPERTY, backupOptions) restoreSystemProperty(CompilerSystemProperties.COMPILE_DAEMON_OPTIONS_PROPERTY.property, backupOptions)
} }
} }
@@ -518,12 +519,12 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
val daemonOptions = makeTestDaemonOptions(getTestName(true)) val daemonOptions = makeTestDaemonOptions(getTestName(true))
val jar = testTempDir.absolutePath + File.separator + "hello.jar" val jar = testTempDir.absolutePath + File.separator + "hello.jar"
val args = listOf( val args = listOf(
File(File(System.getProperty("java.home"), "bin"), "java").absolutePath, File(File(System.getProperty("java.home"), "bin"), "java").absolutePath,
"-Xmx256m", "-Xmx256m",
"-D$COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY", "-D${CompilerSystemProperties.COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY.property}",
"-cp", "-cp",
daemonClientClassPath.joinToString(File.pathSeparator) { it.absolutePath }, daemonClientClassPath.joinToString(File.pathSeparator) { it.absolutePath },
KotlinCompilerClient::class.qualifiedName!!) + KotlinCompilerClient::class.qualifiedName!!) +
daemonOptions.mappers.flatMap { it.toArgs(COMPILE_DAEMON_CMDLINE_OPTIONS_PREFIX) } + daemonOptions.mappers.flatMap { it.toArgs(COMPILE_DAEMON_CMDLINE_OPTIONS_PREFIX) } +
compilerId.mappers.flatMap { it.toArgs(COMPILE_DAEMON_CMDLINE_OPTIONS_PREFIX) } + compilerId.mappers.flatMap { it.toArgs(COMPILE_DAEMON_CMDLINE_OPTIONS_PREFIX) } +
File(getHelloAppBaseDir(), "hello.kt").absolutePath + File(getHelloAppBaseDir(), "hello.kt").absolutePath +
@@ -651,16 +652,16 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
} }
} }
System.setProperty(COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY, "true") CompilerSystemProperties.COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY.value = "true"
System.setProperty(COMPILE_DAEMON_STARTUP_TIMEOUT_PROPERTY, "100000") CompilerSystemProperties.COMPILE_DAEMON_STARTUP_TIMEOUT_PROPERTY.value = "100000"
val succeeded = try { val succeeded = try {
(1..ParallelStartParams.threads).forEach { connectThread(it - 1) } (1..ParallelStartParams.threads).forEach { connectThread(it - 1) }
doneLatch.await(PARALLEL_WAIT_TIMEOUT_S, TimeUnit.SECONDS) doneLatch.await(PARALLEL_WAIT_TIMEOUT_S, TimeUnit.SECONDS)
} }
finally { finally {
System.clearProperty(COMPILE_DAEMON_STARTUP_TIMEOUT_PROPERTY) CompilerSystemProperties.COMPILE_DAEMON_STARTUP_TIMEOUT_PROPERTY.clear()
System.clearProperty(COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY) CompilerSystemProperties.COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY.clear()
} }
Thread.sleep(100) // Wait for processes to finish and close log files Thread.sleep(100) // Wait for processes to finish and close log files
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.daemon.experimental.integration
import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.ApplicationManager
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation
@@ -217,7 +218,7 @@ class CompilerApiTest : KotlinIntegrationTestBase() {
log.info("creating daemonJVMOptions") log.info("creating daemonJVMOptions")
val daemonJVMOptions = configureDaemonJVMOptions( val daemonJVMOptions = configureDaemonJVMOptions(
"D$COMPILE_DAEMON_LOG_PATH_PROPERTY=\"${externalLogFile.loggerCompatiblePath}\"", "D${CompilerSystemProperties.COMPILE_DAEMON_LOG_PATH_PROPERTY.property}=\"${externalLogFile.loggerCompatiblePath}\"",
inheritMemoryLimits = false, inheritMemoryLimits = false,
inheritOtherJvmOptions = false, inheritOtherJvmOptions = false,
inheritAdditionalProperties = false inheritAdditionalProperties = false
@@ -278,7 +279,7 @@ class CompilerApiTest : KotlinIntegrationTestBase() {
reportPerf = true reportPerf = true
) )
val daemonJVMOptions = configureDaemonJVMOptions( val daemonJVMOptions = configureDaemonJVMOptions(
"D$COMPILE_DAEMON_LOG_PATH_PROPERTY=\"${externalLogFile.loggerCompatiblePath}\"", "D${CompilerSystemProperties.COMPILE_DAEMON_LOG_PATH_PROPERTY.property}=\"${externalLogFile.loggerCompatiblePath}\"",
inheritMemoryLimits = false, inheritOtherJvmOptions = false, inheritAdditionalProperties = false inheritMemoryLimits = false, inheritOtherJvmOptions = false, inheritAdditionalProperties = false
) )
try { try {
@@ -11,6 +11,7 @@ import junit.framework.TestCase
import kotlinx.coroutines.* import kotlinx.coroutines.*
import org.jetbrains.kotlin.cli.AbstractCliTest import org.jetbrains.kotlin.cli.AbstractCliTest
import org.jetbrains.kotlin.cli.common.CLICompiler import org.jetbrains.kotlin.cli.common.CLICompiler
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector
import org.jetbrains.kotlin.cli.common.repl.* import org.jetbrains.kotlin.cli.common.repl.*
@@ -173,7 +174,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
fun makeTestDaemonJvmOptions(logFile: File? = null, xmx: Int = 384, args: Iterable<String> = listOf()): DaemonJVMOptions { fun makeTestDaemonJvmOptions(logFile: File? = null, xmx: Int = 384, args: Iterable<String> = listOf()): DaemonJVMOptions {
val additionalArgs = arrayListOf<String>() val additionalArgs = arrayListOf<String>()
if (logFile != null) { if (logFile != null) {
additionalArgs.add("D$COMPILE_DAEMON_LOG_PATH_PROPERTY=\"${logFile.loggerCompatiblePath}\"") additionalArgs.add("D${CompilerSystemProperties.COMPILE_DAEMON_LOG_PATH_PROPERTY.property}=\"${logFile.loggerCompatiblePath}\"")
} }
args.forEach { additionalArgs.add(it) } args.forEach { additionalArgs.add(it) }
val baseOpts = if (xmx > 0) DaemonJVMOptions(maxMemory = "${xmx}m") else DaemonJVMOptions() val baseOpts = if (xmx > 0) DaemonJVMOptions(maxMemory = "${xmx}m") else DaemonJVMOptions()
@@ -230,10 +231,10 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
} }
fun ignore_testDaemonJvmOptionsParsing() { fun ignore_testDaemonJvmOptionsParsing() {
val backupJvmOptions = System.getProperty(COMPILE_DAEMON_JVM_OPTIONS_PROPERTY) val backupJvmOptions = System.getProperty(CompilerSystemProperties.COMPILE_DAEMON_JVM_OPTIONS_PROPERTY.property)
try { try {
System.setProperty( System.setProperty(
COMPILE_DAEMON_JVM_OPTIONS_PROPERTY, CompilerSystemProperties.COMPILE_DAEMON_JVM_OPTIONS_PROPERTY.property,
"-aaa,-bbb\\,ccc,-ddd,-Xmx200m,-XX:MaxMetaspaceSize=10k,-XX:ReservedCodeCacheSize=100,-xxx\\,yyy" "-aaa,-bbb\\,ccc,-ddd,-Xmx200m,-XX:MaxMetaspaceSize=10k,-XX:ReservedCodeCacheSize=100,-xxx\\,yyy"
) )
val opts = val opts =
@@ -243,7 +244,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
assertEquals("100", opts.reservedCodeCacheSize) assertEquals("100", opts.reservedCodeCacheSize)
assertEquals(arrayListOf("aaa", "bbb,ccc", "ddd", "xxx,yyy", "ea"), opts.jvmParams) assertEquals(arrayListOf("aaa", "bbb,ccc", "ddd", "xxx,yyy", "ea"), opts.jvmParams)
System.setProperty(COMPILE_DAEMON_JVM_OPTIONS_PROPERTY, "-Xmx300m,-XX:MaxMetaspaceSize=10k,-XX:ReservedCodeCacheSize=100") System.setProperty(CompilerSystemProperties.COMPILE_DAEMON_JVM_OPTIONS_PROPERTY.property, "-Xmx300m,-XX:MaxMetaspaceSize=10k,-XX:ReservedCodeCacheSize=100")
val opts2 = val opts2 =
configureDaemonJVMOptions(inheritMemoryLimits = false, inheritAdditionalProperties = false, inheritOtherJvmOptions = false) configureDaemonJVMOptions(inheritMemoryLimits = false, inheritAdditionalProperties = false, inheritOtherJvmOptions = false)
assertEquals("300m", opts2.maxMemory) assertEquals("300m", opts2.maxMemory)
@@ -253,7 +254,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
val myXmxParam = ManagementFactory.getRuntimeMXBean().inputArguments.first { it.startsWith("-Xmx") } val myXmxParam = ManagementFactory.getRuntimeMXBean().inputArguments.first { it.startsWith("-Xmx") }
TestCase.assertNotNull(myXmxParam) TestCase.assertNotNull(myXmxParam)
val myXmxVal = myXmxParam.substring(4) val myXmxVal = myXmxParam.substring(4)
System.clearProperty(COMPILE_DAEMON_JVM_OPTIONS_PROPERTY) System.clearProperty(CompilerSystemProperties.COMPILE_DAEMON_JVM_OPTIONS_PROPERTY.property)
val opts3 = configureDaemonJVMOptions( val opts3 = configureDaemonJVMOptions(
inheritMemoryLimits = true, inheritMemoryLimits = true,
inheritOtherJvmOptions = true, inheritOtherJvmOptions = true,
@@ -262,7 +263,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
assertEquals(myXmxVal, opts3.maxMemory) assertEquals(myXmxVal, opts3.maxMemory)
} finally { } finally {
restoreSystemProperty( restoreSystemProperty(
COMPILE_DAEMON_JVM_OPTIONS_PROPERTY, CompilerSystemProperties.COMPILE_DAEMON_JVM_OPTIONS_PROPERTY.property,
backupJvmOptions backupJvmOptions
) )
} }
@@ -294,12 +295,12 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
} }
private fun withDaemonJvmOptionsSetTo(newValue: String?, fn: () -> Unit) { private fun withDaemonJvmOptionsSetTo(newValue: String?, fn: () -> Unit) {
val backup = getAndSetSystemProperty(COMPILE_DAEMON_JVM_OPTIONS_PROPERTY, newValue) val backup = getAndSetSystemProperty(CompilerSystemProperties.COMPILE_DAEMON_JVM_OPTIONS_PROPERTY.property, newValue)
try { try {
fn() fn()
} finally { } finally {
getAndSetSystemProperty(COMPILE_DAEMON_JVM_OPTIONS_PROPERTY, backup) getAndSetSystemProperty(CompilerSystemProperties.COMPILE_DAEMON_JVM_OPTIONS_PROPERTY.property, backup)
} }
} }
@@ -316,14 +317,14 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
} }
fun ignore_testDaemonOptionsParsing() { fun ignore_testDaemonOptionsParsing() {
val backupOptions = System.getProperty(COMPILE_DAEMON_OPTIONS_PROPERTY) val backupOptions = System.getProperty(CompilerSystemProperties.COMPILE_DAEMON_OPTIONS_PROPERTY.property)
try { try {
System.setProperty(COMPILE_DAEMON_OPTIONS_PROPERTY, "runFilesPath=abcd,autoshutdownIdleSeconds=1111") System.setProperty(CompilerSystemProperties.COMPILE_DAEMON_OPTIONS_PROPERTY.property, "runFilesPath=abcd,autoshutdownIdleSeconds=1111")
val opts = configureDaemonOptions(DaemonOptions(shutdownDelayMilliseconds = 1)) val opts = configureDaemonOptions(DaemonOptions(shutdownDelayMilliseconds = 1))
assertEquals("abcd", opts.runFilesPath) assertEquals("abcd", opts.runFilesPath)
assertEquals(1111, opts.autoshutdownIdleSeconds) assertEquals(1111, opts.autoshutdownIdleSeconds)
} finally { } finally {
restoreSystemProperty(COMPILE_DAEMON_OPTIONS_PROPERTY, backupOptions) restoreSystemProperty(CompilerSystemProperties.COMPILE_DAEMON_OPTIONS_PROPERTY.property, backupOptions)
} }
} }
@@ -746,7 +747,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
val args = listOf( val args = listOf(
File(File(System.getProperty("java.home"), "bin"), "java").absolutePath, File(File(System.getProperty("java.home"), "bin"), "java").absolutePath,
"-Xmx256m", "-Xmx256m",
"-D$COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY", "-D${CompilerSystemProperties.COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY.property}",
"-cp", "-cp",
daemonClientClassPath.joinToString(File.pathSeparator) { it.absolutePath }, daemonClientClassPath.joinToString(File.pathSeparator) { it.absolutePath },
KotlinCompilerClientInstance::class.qualifiedName!! KotlinCompilerClientInstance::class.qualifiedName!!
@@ -946,15 +947,15 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
} }
runBlocking { runBlocking {
System.setProperty(COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY, "true") CompilerSystemProperties.COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY.value = "true"
System.setProperty(COMPILE_DAEMON_STARTUP_TIMEOUT_PROPERTY, "100000") CompilerSystemProperties.COMPILE_DAEMON_STARTUP_TIMEOUT_PROPERTY.value = "100000"
val succeeded = try { val succeeded = try {
(1..ParallelStartParams.threads).forEach { connectThread(it - 1) } (1..ParallelStartParams.threads).forEach { connectThread(it - 1) }
doneLatch.await(PARALLEL_WAIT_TIMEOUT_S, TimeUnit.SECONDS) doneLatch.await(PARALLEL_WAIT_TIMEOUT_S, TimeUnit.SECONDS)
} finally { } finally {
System.clearProperty(COMPILE_DAEMON_STARTUP_TIMEOUT_PROPERTY) CompilerSystemProperties.COMPILE_DAEMON_STARTUP_TIMEOUT_PROPERTY.clear()
System.clearProperty(COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY) CompilerSystemProperties.COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY.clear()
} }
delay(1000) // Wait for processes to finish and close log files delay(1000) // Wait for processes to finish and close log files
@@ -42,7 +42,6 @@ import org.jetbrains.jps.model.JpsModuleRootModificationUtil
import org.jetbrains.jps.model.java.JpsJavaExtensionService import org.jetbrains.jps.model.java.JpsJavaExtensionService
import org.jetbrains.jps.model.library.sdk.JpsSdk import org.jetbrains.jps.model.library.sdk.JpsSdk
import org.jetbrains.jps.util.JpsPathUtil import org.jetbrains.jps.util.JpsPathUtil
import org.jetbrains.kotlin.cli.common.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
@@ -42,7 +42,6 @@ import org.jetbrains.jps.model.JpsModuleRootModificationUtil
import org.jetbrains.jps.model.java.JpsJavaExtensionService import org.jetbrains.jps.model.java.JpsJavaExtensionService
import org.jetbrains.jps.model.library.sdk.JpsSdk import org.jetbrains.jps.model.library.sdk.JpsSdk
import org.jetbrains.jps.util.JpsPathUtil import org.jetbrains.jps.util.JpsPathUtil
import org.jetbrains.kotlin.cli.common.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
@@ -18,8 +18,8 @@ package org.jetbrains.kotlin.jps.build
import com.intellij.util.PathUtil import com.intellij.util.PathUtil
import org.jetbrains.jps.model.java.JpsJavaExtensionService import org.jetbrains.jps.model.java.JpsJavaExtensionService
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner
import org.jetbrains.kotlin.daemon.common.COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY
import org.jetbrains.kotlin.daemon.common.OSKind import org.jetbrains.kotlin.daemon.common.OSKind
import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.kotlin.test.KotlinTestUtils
import java.io.File import java.io.File
@@ -69,7 +69,7 @@ class SimpleKotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
// TODO: add JS tests // TODO: add JS tests
fun testDaemon() { fun testDaemon() {
withDaemon { withDaemon {
withSystemProperty(COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY, "true") { withSystemProperty(CompilerSystemProperties.COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY.property, "true") {
withSystemProperty(JpsKotlinCompilerRunner.FAIL_ON_FALLBACK_PROPERTY, "true") { withSystemProperty(JpsKotlinCompilerRunner.FAIL_ON_FALLBACK_PROPERTY, "true") {
testLoadingKotlinFromDifferentModules() testLoadingKotlinFromDifferentModules()
} }
@@ -17,9 +17,8 @@
package org.jetbrains.kotlin.jps.build package org.jetbrains.kotlin.jps.build
import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.io.FileUtil
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner
import org.jetbrains.kotlin.daemon.common.COMPILE_DAEMON_CUSTOM_RUN_FILES_PATH_FOR_TESTS
import org.jetbrains.kotlin.daemon.common.COMPILE_DAEMON_ENABLED_PROPERTY
inline fun withSystemProperty(property: String, newValue: String?, fn: ()->Unit) { inline fun withSystemProperty(property: String, newValue: String?, fn: ()->Unit) {
val backup = System.getProperty(property) val backup = System.getProperty(property)
@@ -47,8 +46,8 @@ inline fun setOrClearSysProperty(property: String, newValue: String?) {
fun withDaemon(fn: () -> Unit) { fun withDaemon(fn: () -> Unit) {
val daemonHome = FileUtil.createTempDirectory("daemon-home", "testJpsDaemonIC") val daemonHome = FileUtil.createTempDirectory("daemon-home", "testJpsDaemonIC")
withSystemProperty(COMPILE_DAEMON_CUSTOM_RUN_FILES_PATH_FOR_TESTS, daemonHome.absolutePath) { withSystemProperty(CompilerSystemProperties.COMPILE_DAEMON_CUSTOM_RUN_FILES_PATH_FOR_TESTS.property, daemonHome.absolutePath) {
withSystemProperty(COMPILE_DAEMON_ENABLED_PROPERTY, "true") { withSystemProperty(CompilerSystemProperties.COMPILE_DAEMON_ENABLED_PROPERTY.property, "true") {
try { try {
fn() fn()
} finally { } finally {
@@ -336,16 +336,19 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractKo
@TaskAction @TaskAction
fun execute(inputs: IncrementalTaskInputs) { fun execute(inputs: IncrementalTaskInputs) {
CompilerSystemProperties.systemPropertyGetter = { CompilerSystemProperties.systemPropertyGetter = {
val value = if (it in kotlinDaemonProperties) kotlinDaemonProperties[it] else System.getProperty(it) if (it in kotlinDaemonProperties) kotlinDaemonProperties[it] else System.getProperty(it)
logger.warn("System property read $it = $value (declared: ${it in kotlinDaemonProperties})")
value
} }
CompilerSystemProperties.systemPropertySetter = setter@{ key, value -> CompilerSystemProperties.systemPropertySetter = setter@{ key, value ->
val oldValue = kotlinDaemonProperties[key] val oldValue = kotlinDaemonProperties[key]
if (oldValue == value) return@setter oldValue if (oldValue == value) return@setter oldValue
kotlinDaemonProperties[key] = value kotlinDaemonProperties[key] = value
System.setProperty(key, value) System.setProperty(key, value)
logger.warn("System property set $key = $value (was: $oldValue)") oldValue
}
CompilerSystemProperties.systemPropertyCleaner = {
val oldValue = kotlinDaemonProperties[it]
kotlinDaemonProperties.remove(it)
System.clearProperty(it)
oldValue oldValue
} }
CompilerSystemProperties.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY.value = "true" CompilerSystemProperties.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY.value = "true"