[Gradle] Read system properties at configuration time using Gradle providers
The change is a step to fully support Gradle configuration cache. Relates to #KT-43605 Relates to #KT-44611
This commit is contained in:
@@ -16,8 +16,48 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.cli.common
|
package org.jetbrains.kotlin.cli.common
|
||||||
|
|
||||||
val KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY = "kotlin.environment.keepalive"
|
import com.intellij.util.LineSeparator
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
enum class CompilerSystemProperties(val property: String) {
|
||||||
|
COMPILE_DAEMON_ENABLED_PROPERTY("kotlin.daemon.enabled"),
|
||||||
|
COMPILE_DAEMON_JVM_OPTIONS_PROPERTY("kotlin.daemon.jvm.options"),
|
||||||
|
COMPILE_DAEMON_OPTIONS_PROPERTY("kotlin.daemon.options"),
|
||||||
|
COMPILE_DAEMON_CLIENT_OPTIONS_PROPERTY("kotlin.daemon.client.options"),
|
||||||
|
COMPILE_DAEMON_CLIENT_ALIVE_PATH_PROPERTY("kotlin.daemon.client.alive.path"),
|
||||||
|
COMPILE_DAEMON_LOG_PATH_PROPERTY("kotlin.daemon.log.path"),
|
||||||
|
COMPILE_DAEMON_REPORT_PERF_PROPERTY("kotlin.daemon.perf"),
|
||||||
|
COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY("kotlin.daemon.verbose"),
|
||||||
|
COMPILE_DAEMON_STARTUP_TIMEOUT_PROPERTY("kotlin.daemon.startup.timeout"),
|
||||||
|
JAVA_RMI_SERVER_HOSTNAME("java.rmi.server.hostname"),
|
||||||
|
DAEMON_RMI_SOCKET_BACKLOG_SIZE_PROPERTY("kotlin.daemon.socket.backlog.size"),
|
||||||
|
DAEMON_RMI_SOCKET_CONNECT_ATTEMPTS_PROPERTY("kotlin.daemon.socket.connect.attempts"),
|
||||||
|
DAEMON_RMI_SOCKET_CONNECT_INTERVAL_PROPERTY("kotlin.daemon.socket.connect.interval"),
|
||||||
|
KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY("kotlin.environment.keepalive"),
|
||||||
|
COMPILE_DAEMON_CUSTOM_RUN_FILES_PATH_FOR_TESTS("kotlin.daemon.custom.run.files.path.for.tests"),
|
||||||
|
KOTLIN_COLORS_ENABLED_PROPERTY("kotlin.colors.enabled"),
|
||||||
|
OS_NAME("os.name")
|
||||||
|
;
|
||||||
|
|
||||||
|
var value
|
||||||
|
get() = systemPropertyGetter(property)
|
||||||
|
set(value) {
|
||||||
|
systemPropertySetter(property, value!!)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
var systemPropertyGetter: (String) -> String? = {
|
||||||
|
System.getProperty(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
var systemPropertySetter: (String, String) -> String? = { key, value ->
|
||||||
|
System.setProperty(key, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val isWindows: Boolean
|
||||||
|
get() = CompilerSystemProperties.OS_NAME.value!!.toLowerCase(Locale.ENGLISH).startsWith("windows")
|
||||||
|
|
||||||
fun String?.toBooleanLenient(): Boolean? = when (this?.toLowerCase()) {
|
fun String?.toBooleanLenient(): Boolean? = when (this?.toLowerCase()) {
|
||||||
null -> false
|
null -> false
|
||||||
|
|||||||
@@ -205,8 +205,8 @@ abstract class CLITool<A : CommonToolArguments> {
|
|||||||
if (System.getProperty("java.awt.headless") == null) {
|
if (System.getProperty("java.awt.headless") == null) {
|
||||||
System.setProperty("java.awt.headless", "true")
|
System.setProperty("java.awt.headless", "true")
|
||||||
}
|
}
|
||||||
if (System.getProperty(PlainTextMessageRenderer.KOTLIN_COLORS_ENABLED_PROPERTY) == null) {
|
if (CompilerSystemProperties.KOTLIN_COLORS_ENABLED_PROPERTY.value == null) {
|
||||||
System.setProperty(PlainTextMessageRenderer.KOTLIN_COLORS_ENABLED_PROPERTY, "true")
|
CompilerSystemProperties.KOTLIN_COLORS_ENABLED_PROPERTY.value = "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
setupIdeaStandaloneExecution()
|
setupIdeaStandaloneExecution()
|
||||||
|
|||||||
+4
-5
@@ -16,13 +16,13 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.cli.common.messages;
|
package org.jetbrains.kotlin.cli.common.messages;
|
||||||
|
|
||||||
import com.intellij.openapi.util.SystemInfo;
|
|
||||||
import com.intellij.util.LineSeparator;
|
|
||||||
import kotlin.text.StringsKt;
|
import kotlin.text.StringsKt;
|
||||||
import org.fusesource.jansi.Ansi;
|
import org.fusesource.jansi.Ansi;
|
||||||
import org.fusesource.jansi.internal.CLibrary;
|
import org.fusesource.jansi.internal.CLibrary;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties;
|
||||||
|
import org.jetbrains.kotlin.cli.common.PropertiesKt;
|
||||||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.CapitalizeDecapitalizeKt;
|
import org.jetbrains.kotlin.util.capitalizeDecapitalize.CapitalizeDecapitalizeKt;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
@@ -31,13 +31,12 @@ import java.util.Set;
|
|||||||
import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*;
|
import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*;
|
||||||
|
|
||||||
public abstract class PlainTextMessageRenderer implements MessageRenderer {
|
public abstract class PlainTextMessageRenderer implements MessageRenderer {
|
||||||
public static final String KOTLIN_COLORS_ENABLED_PROPERTY = "kotlin.colors.enabled";
|
|
||||||
public static final boolean COLOR_ENABLED;
|
public static final boolean COLOR_ENABLED;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
boolean colorEnabled = false;
|
boolean colorEnabled = false;
|
||||||
// TODO: investigate why ANSI escape codes on Windows only work in REPL for some reason
|
// TODO: investigate why ANSI escape codes on Windows only work in REPL for some reason
|
||||||
if (!SystemInfo.isWindows && "true".equals(System.getProperty(KOTLIN_COLORS_ENABLED_PROPERTY))) {
|
if (!PropertiesKt.isWindows() && "true".equals(CompilerSystemProperties.KOTLIN_COLORS_ENABLED_PROPERTY.getValue())) {
|
||||||
try {
|
try {
|
||||||
// AnsiConsole doesn't check isatty() for stderr (see https://github.com/fusesource/jansi/pull/35).
|
// AnsiConsole doesn't check isatty() for stderr (see https://github.com/fusesource/jansi/pull/35).
|
||||||
colorEnabled = CLibrary.isatty(CLibrary.STDERR_FILENO) != 0;
|
colorEnabled = CLibrary.isatty(CLibrary.STDERR_FILENO) != 0;
|
||||||
@@ -49,7 +48,7 @@ public abstract class PlainTextMessageRenderer implements MessageRenderer {
|
|||||||
COLOR_ENABLED = colorEnabled;
|
COLOR_ENABLED = colorEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String LINE_SEPARATOR = LineSeparator.getSystemLineSeparator().getSeparatorString();
|
private static final String LINE_SEPARATOR = System.lineSeparator();
|
||||||
|
|
||||||
private static final Set<CompilerMessageSeverity> IMPORTANT_MESSAGE_SEVERITIES = EnumSet.of(EXCEPTION, ERROR, STRONG_WARNING, WARNING);
|
private static final Set<CompilerMessageSeverity> IMPORTANT_MESSAGE_SEVERITIES = EnumSet.of(EXCEPTION, ERROR, STRONG_WARNING, WARNING);
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ import org.jetbrains.kotlin.asJava.finder.JavaElementFinder
|
|||||||
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
|
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
|
||||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||||
import org.jetbrains.kotlin.cli.common.CliModuleVisibilityManagerImpl
|
import org.jetbrains.kotlin.cli.common.CliModuleVisibilityManagerImpl
|
||||||
import org.jetbrains.kotlin.cli.common.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY
|
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
|
||||||
import org.jetbrains.kotlin.cli.common.config.ContentRoot
|
import org.jetbrains.kotlin.cli.common.config.ContentRoot
|
||||||
import org.jetbrains.kotlin.cli.common.config.KotlinSourceRoot
|
import org.jetbrains.kotlin.cli.common.config.KotlinSourceRoot
|
||||||
import org.jetbrains.kotlin.cli.common.config.kotlinSourceRoots
|
import org.jetbrains.kotlin.cli.common.config.kotlinSourceRoots
|
||||||
@@ -498,7 +498,7 @@ class KotlinCoreEnvironment private constructor(
|
|||||||
}
|
}
|
||||||
// Disposing of the environment is unsafe in production then parallel builds are enabled, but turning it off universally
|
// Disposing of the environment is unsafe in production then parallel builds are enabled, but turning it off universally
|
||||||
// breaks a lot of tests, therefore it is disabled for production and enabled for tests
|
// breaks a lot of tests, therefore it is disabled for production and enabled for tests
|
||||||
if (System.getProperty(KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY).toBooleanLenient() != true) {
|
if (CompilerSystemProperties.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY.value.toBooleanLenient() != true) {
|
||||||
// JPS may run many instances of the compiler in parallel (there's an option for compiling independent modules in parallel in IntelliJ)
|
// JPS may run many instances of the compiler in parallel (there's an option for compiling independent modules in parallel in IntelliJ)
|
||||||
// All projects share the same ApplicationEnvironment, and when the last project is disposed, the ApplicationEnvironment is disposed as well
|
// All projects share the same ApplicationEnvironment, and when the last project is disposed, the ApplicationEnvironment is disposed as well
|
||||||
@Suppress("ObjectLiteralToLambda") // Disposer tree depends on identity of disposables.
|
@Suppress("ObjectLiteralToLambda") // Disposer tree depends on identity of disposables.
|
||||||
|
|||||||
+9
-10
@@ -10,6 +10,7 @@ import kotlinx.coroutines.Deferred
|
|||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
|
||||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||||
import org.jetbrains.kotlin.daemon.client.CompileServiceSessionAsync
|
import org.jetbrains.kotlin.daemon.client.CompileServiceSessionAsync
|
||||||
@@ -44,13 +45,13 @@ class KotlinCompilerClient : KotlinCompilerDaemonClient {
|
|||||||
val DAEMON_DEFAULT_STARTUP_TIMEOUT_MS = 10000L
|
val DAEMON_DEFAULT_STARTUP_TIMEOUT_MS = 10000L
|
||||||
val DAEMON_CONNECT_CYCLE_ATTEMPTS = 3
|
val DAEMON_CONNECT_CYCLE_ATTEMPTS = 3
|
||||||
|
|
||||||
val verboseReporting = System.getProperty(COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY) != null
|
val verboseReporting = CompilerSystemProperties.COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY.value != null
|
||||||
|
|
||||||
private val log = Logger.getLogger("KotlinCompilerClient")
|
private val log = Logger.getLogger("KotlinCompilerClient")
|
||||||
|
|
||||||
override fun getOrCreateClientFlagFile(daemonOptions: DaemonOptions): File =
|
override fun getOrCreateClientFlagFile(daemonOptions: DaemonOptions): File =
|
||||||
// for jps property is passed from IDEA to JPS in KotlinBuildProcessParametersProvider
|
// for jps property is passed from IDEA to JPS in KotlinBuildProcessParametersProvider
|
||||||
System.getProperty(COMPILE_DAEMON_CLIENT_ALIVE_PATH_PROPERTY)
|
CompilerSystemProperties.COMPILE_DAEMON_CLIENT_ALIVE_PATH_PROPERTY.value
|
||||||
?.let(String::trimQuotes)
|
?.let(String::trimQuotes)
|
||||||
?.takeUnless(String::isBlank)
|
?.takeUnless(String::isBlank)
|
||||||
?.let(::File)
|
?.let(::File)
|
||||||
@@ -210,8 +211,6 @@ class KotlinCompilerClient : KotlinCompilerDaemonClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val COMPILE_DAEMON_CLIENT_OPTIONS_PROPERTY: String = "kotlin.daemon.client.options"
|
|
||||||
|
|
||||||
data class ClientOptions(
|
data class ClientOptions(
|
||||||
var stop: Boolean = false
|
var stop: Boolean = false
|
||||||
) : OptionsGroup {
|
) : OptionsGroup {
|
||||||
@@ -220,11 +219,11 @@ class KotlinCompilerClient : KotlinCompilerDaemonClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun configureClientOptions(opts: ClientOptions): ClientOptions {
|
private fun configureClientOptions(opts: ClientOptions): ClientOptions {
|
||||||
System.getProperty(COMPILE_DAEMON_CLIENT_OPTIONS_PROPERTY)?.let {
|
CompilerSystemProperties.COMPILE_DAEMON_CLIENT_OPTIONS_PROPERTY.value?.let {
|
||||||
val unrecognized = it.trimQuotes().split(",").filterExtractProps(opts.mappers, "")
|
val unrecognized = it.trimQuotes().split(",").filterExtractProps(opts.mappers, "")
|
||||||
if (unrecognized.any())
|
if (unrecognized.any())
|
||||||
throw IllegalArgumentException(
|
throw IllegalArgumentException(
|
||||||
"Unrecognized client options passed via property $COMPILE_DAEMON_OPTIONS_PROPERTY: " + unrecognized.joinToString(" ") +
|
"Unrecognized client options passed via property ${CompilerSystemProperties.COMPILE_DAEMON_CLIENT_OPTIONS_PROPERTY.property}: " + unrecognized.joinToString(" ") +
|
||||||
"\nSupported options: " + opts.mappers.joinToString(", ", transform = { it.names.first() })
|
"\nSupported options: " + opts.mappers.joinToString(", ", transform = { it.names.first() })
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -456,11 +455,11 @@ class KotlinCompilerClient : KotlinCompilerDaemonClient {
|
|||||||
reportingTargets: DaemonReportingTargets
|
reportingTargets: DaemonReportingTargets
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val javaExecutable = File(File(System.getProperty("java.home"), "bin"), "java")
|
val javaExecutable = File(File(System.getProperty("java.home"), "bin"), "java")
|
||||||
val serverHostname = System.getProperty(JAVA_RMI_SERVER_HOSTNAME) ?: error("$JAVA_RMI_SERVER_HOSTNAME is not set!")
|
val serverHostname = CompilerSystemProperties.JAVA_RMI_SERVER_HOSTNAME.value ?: error("${CompilerSystemProperties.JAVA_RMI_SERVER_HOSTNAME.property} is not set!")
|
||||||
val platformSpecificOptions = listOf(
|
val platformSpecificOptions = listOf(
|
||||||
// hide daemon window
|
// hide daemon window
|
||||||
"-Djava.awt.headless=true",
|
"-Djava.awt.headless=true",
|
||||||
"-D$JAVA_RMI_SERVER_HOSTNAME=$serverHostname"
|
"-D${CompilerSystemProperties.JAVA_RMI_SERVER_HOSTNAME.property}=$serverHostname"
|
||||||
)
|
)
|
||||||
val args = listOf(
|
val args = listOf(
|
||||||
javaExecutable.absolutePath, "-cp", compilerId.compilerClasspath.joinToString(File.pathSeparator)
|
javaExecutable.absolutePath, "-cp", compilerId.compilerClasspath.joinToString(File.pathSeparator)
|
||||||
@@ -509,13 +508,13 @@ class KotlinCompilerClient : KotlinCompilerDaemonClient {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// trying to wait for process
|
// trying to wait for process
|
||||||
val daemonStartupTimeout = System.getProperty(COMPILE_DAEMON_STARTUP_TIMEOUT_PROPERTY)?.let {
|
val daemonStartupTimeout = CompilerSystemProperties.COMPILE_DAEMON_STARTUP_TIMEOUT_PROPERTY.value?.let {
|
||||||
try {
|
try {
|
||||||
it.toLong()
|
it.toLong()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
reportingTargets.report(
|
reportingTargets.report(
|
||||||
DaemonReportCategory.INFO,
|
DaemonReportCategory.INFO,
|
||||||
"unable to interpret $COMPILE_DAEMON_STARTUP_TIMEOUT_PROPERTY property ('$it'); using default timeout $DAEMON_DEFAULT_STARTUP_TIMEOUT_MS ms"
|
"unable to interpret ${CompilerSystemProperties.COMPILE_DAEMON_STARTUP_TIMEOUT_PROPERTY.property} property ('$it'); using default timeout $DAEMON_DEFAULT_STARTUP_TIMEOUT_MS ms"
|
||||||
)
|
)
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-9
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.daemon.client
|
package org.jetbrains.kotlin.daemon.client
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
|
||||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||||
import org.jetbrains.kotlin.daemon.common.*
|
import org.jetbrains.kotlin.daemon.common.*
|
||||||
@@ -48,11 +49,11 @@ object KotlinCompilerClient {
|
|||||||
val DAEMON_DEFAULT_STARTUP_TIMEOUT_MS = 10000L
|
val DAEMON_DEFAULT_STARTUP_TIMEOUT_MS = 10000L
|
||||||
val DAEMON_CONNECT_CYCLE_ATTEMPTS = 3
|
val DAEMON_CONNECT_CYCLE_ATTEMPTS = 3
|
||||||
|
|
||||||
val verboseReporting = System.getProperty(COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY) != null
|
val verboseReporting = CompilerSystemProperties.COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY.value != null
|
||||||
|
|
||||||
fun getOrCreateClientFlagFile(daemonOptions: DaemonOptions): File =
|
fun getOrCreateClientFlagFile(daemonOptions: DaemonOptions): File =
|
||||||
// for jps property is passed from IDEA to JPS in KotlinBuildProcessParametersProvider
|
// for jps property is passed from IDEA to JPS in KotlinBuildProcessParametersProvider
|
||||||
System.getProperty(COMPILE_DAEMON_CLIENT_ALIVE_PATH_PROPERTY)
|
CompilerSystemProperties.COMPILE_DAEMON_CLIENT_ALIVE_PATH_PROPERTY.value
|
||||||
?.let(String::trimQuotes)
|
?.let(String::trimQuotes)
|
||||||
?.takeUnless(String::isBlank)
|
?.takeUnless(String::isBlank)
|
||||||
?.let(::File)
|
?.let(::File)
|
||||||
@@ -211,7 +212,6 @@ object KotlinCompilerClient {
|
|||||||
).get()
|
).get()
|
||||||
}
|
}
|
||||||
|
|
||||||
val COMPILE_DAEMON_CLIENT_OPTIONS_PROPERTY: String = "kotlin.daemon.client.options"
|
|
||||||
data class ClientOptions(
|
data class ClientOptions(
|
||||||
var stop: Boolean = false
|
var stop: Boolean = false
|
||||||
) : OptionsGroup {
|
) : OptionsGroup {
|
||||||
@@ -220,11 +220,11 @@ object KotlinCompilerClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun configureClientOptions(opts: ClientOptions): ClientOptions {
|
private fun configureClientOptions(opts: ClientOptions): ClientOptions {
|
||||||
System.getProperty(COMPILE_DAEMON_CLIENT_OPTIONS_PROPERTY)?.let {
|
CompilerSystemProperties.COMPILE_DAEMON_CLIENT_OPTIONS_PROPERTY.value?.let {
|
||||||
val unrecognized = it.trimQuotes().split(",").filterExtractProps(opts.mappers, "")
|
val unrecognized = it.trimQuotes().split(",").filterExtractProps(opts.mappers, "")
|
||||||
if (unrecognized.any())
|
if (unrecognized.any())
|
||||||
throw IllegalArgumentException(
|
throw IllegalArgumentException(
|
||||||
"Unrecognized client options passed via property $COMPILE_DAEMON_OPTIONS_PROPERTY: " + unrecognized.joinToString(" ") +
|
"Unrecognized client options passed via property ${CompilerSystemProperties.COMPILE_DAEMON_CLIENT_OPTIONS_PROPERTY.property}: " + unrecognized.joinToString(" ") +
|
||||||
"\nSupported options: " + opts.mappers.joinToString(", ", transform = { it.names.first() }))
|
"\nSupported options: " + opts.mappers.joinToString(", ", transform = { it.names.first() }))
|
||||||
}
|
}
|
||||||
return opts
|
return opts
|
||||||
@@ -369,11 +369,11 @@ object KotlinCompilerClient {
|
|||||||
|
|
||||||
private fun startDaemon(compilerId: CompilerId, daemonJVMOptions: DaemonJVMOptions, daemonOptions: DaemonOptions, reportingTargets: DaemonReportingTargets): Boolean {
|
private fun startDaemon(compilerId: CompilerId, daemonJVMOptions: DaemonJVMOptions, daemonOptions: DaemonOptions, reportingTargets: DaemonReportingTargets): Boolean {
|
||||||
val javaExecutable = File(File(System.getProperty("java.home"), "bin"), "java")
|
val javaExecutable = File(File(System.getProperty("java.home"), "bin"), "java")
|
||||||
val serverHostname = System.getProperty(JAVA_RMI_SERVER_HOSTNAME) ?: error("$JAVA_RMI_SERVER_HOSTNAME is not set!")
|
val serverHostname = CompilerSystemProperties.JAVA_RMI_SERVER_HOSTNAME.value ?: error("${CompilerSystemProperties.JAVA_RMI_SERVER_HOSTNAME.property} is not set!")
|
||||||
val platformSpecificOptions = listOf(
|
val platformSpecificOptions = listOf(
|
||||||
// hide daemon window
|
// hide daemon window
|
||||||
"-Djava.awt.headless=true",
|
"-Djava.awt.headless=true",
|
||||||
"-D$JAVA_RMI_SERVER_HOSTNAME=$serverHostname")
|
"-D$${CompilerSystemProperties.JAVA_RMI_SERVER_HOSTNAME.property}=$serverHostname")
|
||||||
val javaVersion = System.getProperty("java.specification.version")?.toIntOrNull()
|
val javaVersion = System.getProperty("java.specification.version")?.toIntOrNull()
|
||||||
val javaIllegalAccessWorkaround =
|
val javaIllegalAccessWorkaround =
|
||||||
if (javaVersion != null && javaVersion >= 16)
|
if (javaVersion != null && javaVersion >= 16)
|
||||||
@@ -424,12 +424,12 @@ object KotlinCompilerClient {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// trying to wait for process
|
// trying to wait for process
|
||||||
val daemonStartupTimeout = System.getProperty(COMPILE_DAEMON_STARTUP_TIMEOUT_PROPERTY)?.let {
|
val daemonStartupTimeout = CompilerSystemProperties.COMPILE_DAEMON_STARTUP_TIMEOUT_PROPERTY.value?.let {
|
||||||
try {
|
try {
|
||||||
it.toLong()
|
it.toLong()
|
||||||
}
|
}
|
||||||
catch (e: Exception) {
|
catch (e: Exception) {
|
||||||
reportingTargets.report(DaemonReportCategory.INFO, "unable to interpret $COMPILE_DAEMON_STARTUP_TIMEOUT_PROPERTY property ('$it'); using default timeout $DAEMON_DEFAULT_STARTUP_TIMEOUT_MS ms")
|
reportingTargets.report(DaemonReportCategory.INFO, "unable to interpret ${CompilerSystemProperties.COMPILE_DAEMON_STARTUP_TIMEOUT_PROPERTY.property} property ('$it'); using default timeout $DAEMON_DEFAULT_STARTUP_TIMEOUT_MS ms")
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
} ?: DAEMON_DEFAULT_STARTUP_TIMEOUT_MS
|
} ?: DAEMON_DEFAULT_STARTUP_TIMEOUT_MS
|
||||||
|
|||||||
+51
-57
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.daemon.common
|
package org.jetbrains.kotlin.daemon.common
|
||||||
|
|
||||||
import org.jetbrains.kotlin.cli.common.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY
|
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
import java.lang.management.ManagementFactory
|
import java.lang.management.ManagementFactory
|
||||||
@@ -24,53 +24,47 @@ import java.security.MessageDigest
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.reflect.KMutableProperty1
|
import kotlin.reflect.KMutableProperty1
|
||||||
|
|
||||||
|
const val COMPILER_JAR_NAME: String = "kotlin-compiler.jar"
|
||||||
|
const val COMPILER_SERVICE_RMI_NAME: String = "KotlinJvmCompilerService"
|
||||||
|
const val COMPILER_DAEMON_CLASS_FQN: String = "org.jetbrains.kotlin.daemon.KotlinCompileDaemon"
|
||||||
|
const val COMPILE_DAEMON_FIND_PORT_ATTEMPTS: Int = 10
|
||||||
|
const val COMPILE_DAEMON_PORTS_RANGE_START: Int = 17001
|
||||||
|
const val COMPILE_DAEMON_PORTS_RANGE_END: Int = 18000
|
||||||
|
const val COMPILE_DAEMON_CMDLINE_OPTIONS_PREFIX: String = "--daemon-"
|
||||||
|
const val COMPILE_DAEMON_DEFAULT_FILES_PREFIX: String = "kotlin-daemon"
|
||||||
|
const val COMPILE_DAEMON_TIMEOUT_INFINITE_S: Int = 0
|
||||||
|
const val COMPILE_DAEMON_DEFAULT_IDLE_TIMEOUT_S: Int = 7200 // 2 hours
|
||||||
|
const val COMPILE_DAEMON_DEFAULT_UNUSED_TIMEOUT_S: Int = 60
|
||||||
|
const val COMPILE_DAEMON_DEFAULT_SHUTDOWN_DELAY_MS: Long = 1000L // 1 sec
|
||||||
|
const val COMPILE_DAEMON_MEMORY_THRESHOLD_INFINITE: Long = 0L
|
||||||
|
const val COMPILE_DAEMON_FORCE_SHUTDOWN_DEFAULT_TIMEOUT_MS: Long = 10000L // 10 secs
|
||||||
|
const val COMPILE_DAEMON_TIMEOUT_INFINITE_MS: Long = 0L
|
||||||
|
const val COMPILE_DAEMON_IS_READY_MESSAGE = "Kotlin compile daemon is ready"
|
||||||
|
|
||||||
val COMPILER_JAR_NAME: String = "kotlin-compiler.jar"
|
val COMPILE_DAEMON_DEFAULT_RUN_DIR_PATH: String
|
||||||
val COMPILER_SERVICE_RMI_NAME: String = "KotlinJvmCompilerService"
|
get() = CompilerSystemProperties.COMPILE_DAEMON_CUSTOM_RUN_FILES_PATH_FOR_TESTS.value ?: FileSystem.getRuntimeStateFilesPath(
|
||||||
val COMPILER_DAEMON_CLASS_FQN: String = "org.jetbrains.kotlin.daemon.KotlinCompileDaemon"
|
"kotlin",
|
||||||
val COMPILE_DAEMON_FIND_PORT_ATTEMPTS: Int = 10
|
"daemon"
|
||||||
val COMPILE_DAEMON_PORTS_RANGE_START: Int = 17001
|
)
|
||||||
val COMPILE_DAEMON_PORTS_RANGE_END: Int = 18000
|
|
||||||
val COMPILE_DAEMON_ENABLED_PROPERTY: String = "kotlin.daemon.enabled"
|
|
||||||
val COMPILE_DAEMON_JVM_OPTIONS_PROPERTY: String = "kotlin.daemon.jvm.options"
|
|
||||||
val COMPILE_DAEMON_OPTIONS_PROPERTY: String = "kotlin.daemon.options"
|
|
||||||
val COMPILE_DAEMON_CLIENT_ALIVE_PATH_PROPERTY: String = "kotlin.daemon.client.alive.path"
|
|
||||||
val COMPILE_DAEMON_LOG_PATH_PROPERTY: String = "kotlin.daemon.log.path"
|
|
||||||
val COMPILE_DAEMON_REPORT_PERF_PROPERTY: String = "kotlin.daemon.perf"
|
|
||||||
val COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY: String = "kotlin.daemon.verbose"
|
|
||||||
val COMPILE_DAEMON_CMDLINE_OPTIONS_PREFIX: String = "--daemon-"
|
|
||||||
val COMPILE_DAEMON_STARTUP_TIMEOUT_PROPERTY: String = "kotlin.daemon.startup.timeout"
|
|
||||||
val COMPILE_DAEMON_DEFAULT_FILES_PREFIX: String = "kotlin-daemon"
|
|
||||||
val COMPILE_DAEMON_TIMEOUT_INFINITE_S: Int = 0
|
|
||||||
val COMPILE_DAEMON_DEFAULT_IDLE_TIMEOUT_S: Int = 7200 // 2 hours
|
|
||||||
val COMPILE_DAEMON_DEFAULT_UNUSED_TIMEOUT_S: Int = 60
|
|
||||||
val COMPILE_DAEMON_DEFAULT_SHUTDOWN_DELAY_MS: Long = 1000L // 1 sec
|
|
||||||
val COMPILE_DAEMON_MEMORY_THRESHOLD_INFINITE: Long = 0L
|
|
||||||
val COMPILE_DAEMON_FORCE_SHUTDOWN_DEFAULT_TIMEOUT_MS: Long = 10000L // 10 secs
|
|
||||||
val COMPILE_DAEMON_TIMEOUT_INFINITE_MS: Long = 0L
|
|
||||||
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() =
|
|
||||||
System.getProperty(COMPILE_DAEMON_CUSTOM_RUN_FILES_PATH_FOR_TESTS)
|
|
||||||
?: FileSystem.getRuntimeStateFilesPath("kotlin", "daemon")
|
|
||||||
|
|
||||||
val CLASSPATH_ID_DIGEST = "MD5"
|
val CLASSPATH_ID_DIGEST = "MD5"
|
||||||
|
|
||||||
|
|
||||||
open class PropMapper<C, V, out P : KMutableProperty1<C, V>>(val dest: C,
|
open class PropMapper<C, V, out P : KMutableProperty1<C, V>>(
|
||||||
val prop: P,
|
val dest: C,
|
||||||
val names: List<String> = listOf(prop.name),
|
val prop: P,
|
||||||
val fromString: (String) -> V,
|
val names: List<String> = listOf(prop.name),
|
||||||
val toString: ((V) -> String?) = { it.toString() },
|
val fromString: (String) -> V,
|
||||||
val skipIf: ((V) -> Boolean) = { false },
|
val toString: ((V) -> String?) = { it.toString() },
|
||||||
val mergeDelimiter: String? = null) {
|
val skipIf: ((V) -> Boolean) = { false },
|
||||||
|
val mergeDelimiter: String? = null
|
||||||
|
) {
|
||||||
open fun toArgs(prefix: String = COMPILE_DAEMON_CMDLINE_OPTIONS_PREFIX): List<String> =
|
open fun toArgs(prefix: String = COMPILE_DAEMON_CMDLINE_OPTIONS_PREFIX): List<String> =
|
||||||
when {
|
when {
|
||||||
skipIf(prop.get(dest)) -> listOf<String>()
|
skipIf(prop.get(dest)) -> listOf<String>()
|
||||||
mergeDelimiter != null -> listOf(listOfNotNull(prefix + names.first(), toString(prop.get(dest))).joinToString(mergeDelimiter))
|
mergeDelimiter != null -> listOf(listOfNotNull(prefix + names.first(), toString(prop.get(dest))).joinToString(mergeDelimiter))
|
||||||
else -> listOfNotNull(prefix + names.first(), toString(prop.get(dest)))
|
else -> listOfNotNull(prefix + names.first(), toString(prop.get(dest)))
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun apply(s: String) = prop.set(dest, fromString(s))
|
open fun apply(s: String) = prop.set(dest, fromString(s))
|
||||||
}
|
}
|
||||||
@@ -255,7 +249,7 @@ data class CompilerId(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun isDaemonEnabled(): Boolean = System.getProperty(COMPILE_DAEMON_ENABLED_PROPERTY) != null
|
fun isDaemonEnabled(): Boolean = CompilerSystemProperties.COMPILE_DAEMON_ENABLED_PROPERTY.value != null
|
||||||
|
|
||||||
fun configureDaemonJVMOptions(opts: DaemonJVMOptions,
|
fun configureDaemonJVMOptions(opts: DaemonJVMOptions,
|
||||||
vararg additionalParams: String,
|
vararg additionalParams: String,
|
||||||
@@ -289,16 +283,16 @@ fun configureDaemonJVMOptions(opts: DaemonJVMOptions,
|
|||||||
|
|
||||||
if (inheritOtherJvmOptions) {
|
if (inheritOtherJvmOptions) {
|
||||||
opts.jvmParams.addAll(
|
opts.jvmParams.addAll(
|
||||||
otherArgs.filterNot {
|
otherArgs.filterNot {
|
||||||
it.startsWith("agentlib") ||
|
it.startsWith("agentlib") ||
|
||||||
it.startsWith("D" + COMPILE_DAEMON_LOG_PATH_PROPERTY) ||
|
it.startsWith("D" + CompilerSystemProperties.COMPILE_DAEMON_LOG_PATH_PROPERTY.property) ||
|
||||||
it.startsWith("D" + KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY) ||
|
it.startsWith("D" + CompilerSystemProperties.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY.property) ||
|
||||||
it.startsWith("D" + COMPILE_DAEMON_JVM_OPTIONS_PROPERTY) ||
|
it.startsWith("D" + CompilerSystemProperties.COMPILE_DAEMON_JVM_OPTIONS_PROPERTY.property) ||
|
||||||
it.startsWith("D" + COMPILE_DAEMON_OPTIONS_PROPERTY)
|
it.startsWith("D" + CompilerSystemProperties.COMPILE_DAEMON_OPTIONS_PROPERTY.property)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.getProperty(COMPILE_DAEMON_JVM_OPTIONS_PROPERTY)?.let {
|
CompilerSystemProperties.COMPILE_DAEMON_JVM_OPTIONS_PROPERTY.value?.let {
|
||||||
opts.jvmParams.addAll(
|
opts.jvmParams.addAll(
|
||||||
it.trimQuotes()
|
it.trimQuotes()
|
||||||
.split("(?<!\\\\),".toRegex()) // using independent non-capturing group with negative lookahead zero length assertion to split only on non-escaped commas
|
.split("(?<!\\\\),".toRegex()) // using independent non-capturing group with negative lookahead zero length assertion to split only on non-escaped commas
|
||||||
@@ -311,8 +305,8 @@ fun configureDaemonJVMOptions(opts: DaemonJVMOptions,
|
|||||||
opts.jvmParams.addAll(additionalParams)
|
opts.jvmParams.addAll(additionalParams)
|
||||||
|
|
||||||
if (inheritAdditionalProperties) {
|
if (inheritAdditionalProperties) {
|
||||||
System.getProperty(COMPILE_DAEMON_LOG_PATH_PROPERTY)?.let { opts.jvmParams.add("D$COMPILE_DAEMON_LOG_PATH_PROPERTY=\"$it\"") }
|
CompilerSystemProperties.COMPILE_DAEMON_LOG_PATH_PROPERTY.value?.let { opts.jvmParams.add("D${CompilerSystemProperties.COMPILE_DAEMON_LOG_PATH_PROPERTY.property}=\"$it\"") }
|
||||||
System.getProperty(KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY)?.let { opts.jvmParams.add("D$KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY") }
|
CompilerSystemProperties.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY.value?.let { opts.jvmParams.add("D${CompilerSystemProperties.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY.property}") }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.jvmParams.none { it.matches(jvmAssertArgsRegex) }) {
|
if (opts.jvmParams.none { it.matches(jvmAssertArgsRegex) }) {
|
||||||
@@ -338,15 +332,15 @@ fun configureDaemonJVMOptions(
|
|||||||
)
|
)
|
||||||
|
|
||||||
fun configureDaemonOptions(opts: DaemonOptions): DaemonOptions {
|
fun configureDaemonOptions(opts: DaemonOptions): DaemonOptions {
|
||||||
System.getProperty(COMPILE_DAEMON_OPTIONS_PROPERTY)?.let {
|
CompilerSystemProperties.COMPILE_DAEMON_OPTIONS_PROPERTY.value?.let {
|
||||||
val unrecognized = it.trimQuotes().split(",").filterExtractProps(opts.mappers, "")
|
val unrecognized = it.trimQuotes().split(",").filterExtractProps(opts.mappers, "")
|
||||||
if (unrecognized.any())
|
if (unrecognized.any())
|
||||||
throw IllegalArgumentException(
|
throw IllegalArgumentException(
|
||||||
"Unrecognized daemon options passed via property $COMPILE_DAEMON_OPTIONS_PROPERTY: " + unrecognized.joinToString(" ") +
|
"Unrecognized daemon options passed via property ${CompilerSystemProperties.COMPILE_DAEMON_OPTIONS_PROPERTY.property}: " + unrecognized.joinToString(" ") +
|
||||||
"\nSupported options: " + opts.mappers.joinToString(", ", transform = { it.names.first() }))
|
"\nSupported options: " + opts.mappers.joinToString(", ", transform = { it.names.first() }))
|
||||||
}
|
}
|
||||||
System.getProperty(COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY)?.let { opts.verbose = true }
|
CompilerSystemProperties.COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY.value?.let { opts.verbose = true }
|
||||||
System.getProperty(COMPILE_DAEMON_REPORT_PERF_PROPERTY)?.let { opts.reportPerf = true }
|
CompilerSystemProperties.COMPILE_DAEMON_REPORT_PERF_PROPERTY.value?.let { opts.reportPerf = true }
|
||||||
return opts
|
return opts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-11
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.daemon.common
|
package org.jetbrains.kotlin.daemon.common
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
import java.net.*
|
import java.net.*
|
||||||
@@ -26,12 +27,7 @@ import java.rmi.server.RMIClientSocketFactory
|
|||||||
import java.rmi.server.RMIServerSocketFactory
|
import java.rmi.server.RMIServerSocketFactory
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
const val SOCKET_ANY_FREE_PORT = 0
|
||||||
const val SOCKET_ANY_FREE_PORT = 0
|
|
||||||
const val JAVA_RMI_SERVER_HOSTNAME = "java.rmi.server.hostname"
|
|
||||||
const val DAEMON_RMI_SOCKET_BACKLOG_SIZE_PROPERTY = "kotlin.daemon.socket.backlog.size"
|
|
||||||
const val DAEMON_RMI_SOCKET_CONNECT_ATTEMPTS_PROPERTY = "kotlin.daemon.socket.connect.attempts"
|
|
||||||
const val DAEMON_RMI_SOCKET_CONNECT_INTERVAL_PROPERTY = "kotlin.daemon.socket.connect.interval"
|
|
||||||
const val DEFAULT_SERVER_SOCKET_BACKLOG_SIZE = 50
|
const val DEFAULT_SERVER_SOCKET_BACKLOG_SIZE = 50
|
||||||
const val DEFAULT_SOCKET_CONNECT_ATTEMPTS = 3
|
const val DEFAULT_SOCKET_CONNECT_ATTEMPTS = 3
|
||||||
const val DEFAULT_SOCKET_CONNECT_INTERVAL_MS = 10L
|
const val DEFAULT_SOCKET_CONNECT_INTERVAL_MS = 10L
|
||||||
@@ -43,9 +39,9 @@ object LoopbackNetworkInterface {
|
|||||||
|
|
||||||
// size of the requests queue for daemon services, so far seems that we don't need any big numbers here
|
// size of the requests queue for daemon services, so far seems that we don't need any big numbers here
|
||||||
// but if we'll start getting "connection refused" errors, that could be the first place to try to fix it
|
// but if we'll start getting "connection refused" errors, that could be the first place to try to fix it
|
||||||
val SERVER_SOCKET_BACKLOG_SIZE by lazy { System.getProperty(DAEMON_RMI_SOCKET_BACKLOG_SIZE_PROPERTY)?.toIntOrNull() ?: DEFAULT_SERVER_SOCKET_BACKLOG_SIZE }
|
val SERVER_SOCKET_BACKLOG_SIZE by lazy { CompilerSystemProperties.DAEMON_RMI_SOCKET_BACKLOG_SIZE_PROPERTY.value?.toIntOrNull() ?: DEFAULT_SERVER_SOCKET_BACKLOG_SIZE }
|
||||||
val SOCKET_CONNECT_ATTEMPTS by lazy { System.getProperty(DAEMON_RMI_SOCKET_CONNECT_ATTEMPTS_PROPERTY)?.toIntOrNull() ?: DEFAULT_SOCKET_CONNECT_ATTEMPTS }
|
val SOCKET_CONNECT_ATTEMPTS by lazy { CompilerSystemProperties.DAEMON_RMI_SOCKET_CONNECT_ATTEMPTS_PROPERTY.value?.toIntOrNull() ?: DEFAULT_SOCKET_CONNECT_ATTEMPTS }
|
||||||
val SOCKET_CONNECT_INTERVAL_MS by lazy { System.getProperty(DAEMON_RMI_SOCKET_CONNECT_INTERVAL_PROPERTY)?.toLongOrNull() ?: DEFAULT_SOCKET_CONNECT_INTERVAL_MS }
|
val SOCKET_CONNECT_INTERVAL_MS by lazy { CompilerSystemProperties.DAEMON_RMI_SOCKET_CONNECT_INTERVAL_PROPERTY.value?.toLongOrNull() ?: DEFAULT_SOCKET_CONNECT_INTERVAL_MS }
|
||||||
|
|
||||||
val serverLoopbackSocketFactory by lazy { ServerLoopbackSocketFactory() }
|
val serverLoopbackSocketFactory by lazy { ServerLoopbackSocketFactory() }
|
||||||
val clientLoopbackSocketFactory by lazy { ClientLoopbackSocketFactory() }
|
val clientLoopbackSocketFactory by lazy { ClientLoopbackSocketFactory() }
|
||||||
@@ -125,7 +121,7 @@ fun findPortAndCreateRegistry(attempts: Int, portRangeStart: Int, portRangeEnd:
|
|||||||
* which may be slow and can cause a timeout when there is a network problem/misconfiguration.
|
* which may be slow and can cause a timeout when there is a network problem/misconfiguration.
|
||||||
*/
|
*/
|
||||||
fun ensureServerHostnameIsSetUp() {
|
fun ensureServerHostnameIsSetUp() {
|
||||||
if (System.getProperty(JAVA_RMI_SERVER_HOSTNAME) == null) {
|
if (CompilerSystemProperties.JAVA_RMI_SERVER_HOSTNAME.value == null) {
|
||||||
System.setProperty(JAVA_RMI_SERVER_HOSTNAME, LoopbackNetworkInterface.loopbackInetAddressName)
|
CompilerSystemProperties.JAVA_RMI_SERVER_HOSTNAME.value = LoopbackNetworkInterface.loopbackInetAddressName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ import org.jetbrains.kotlin.build.report.BuildReporter
|
|||||||
import org.jetbrains.kotlin.build.report.RemoteBuildReporter
|
import org.jetbrains.kotlin.build.report.RemoteBuildReporter
|
||||||
import org.jetbrains.kotlin.build.report.RemoteReporter
|
import org.jetbrains.kotlin.build.report.RemoteReporter
|
||||||
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.ExitCode
|
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||||
import org.jetbrains.kotlin.cli.common.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY
|
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.*
|
import org.jetbrains.kotlin.cli.common.arguments.*
|
||||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||||
@@ -102,7 +102,7 @@ abstract class CompileServiceImplBase(
|
|||||||
protected val log by lazy { Logger.getLogger("compiler") }
|
protected val log by lazy { Logger.getLogger("compiler") }
|
||||||
|
|
||||||
init {
|
init {
|
||||||
System.setProperty(KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY, "true")
|
CompilerSystemProperties.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY.value = "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
// wrapped in a class to encapsulate alive check logic
|
// wrapped in a class to encapsulate alive check logic
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.daemon
|
package org.jetbrains.kotlin.daemon
|
||||||
|
|
||||||
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.environment.setIdeaIoUseFallback
|
import org.jetbrains.kotlin.cli.common.environment.setIdeaIoUseFallback
|
||||||
import org.jetbrains.kotlin.cli.js.K2JSCompiler
|
import org.jetbrains.kotlin.cli.js.K2JSCompiler
|
||||||
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
|
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
|
||||||
@@ -60,7 +61,7 @@ abstract class KotlinCompileDaemonBase {
|
|||||||
init {
|
init {
|
||||||
val logTime: String = SimpleDateFormat("yyyy-MM-dd.HH-mm-ss-SSS").format(Date())
|
val logTime: String = SimpleDateFormat("yyyy-MM-dd.HH-mm-ss-SSS").format(Date())
|
||||||
val (logPath: String, fileIsGiven: Boolean) =
|
val (logPath: String, fileIsGiven: Boolean) =
|
||||||
System.getProperty(COMPILE_DAEMON_LOG_PATH_PROPERTY)?.trimQuotes()?.let { Pair(it, File(it).isFile) } ?: Pair("%t", false)
|
CompilerSystemProperties.COMPILE_DAEMON_LOG_PATH_PROPERTY.value?.trimQuotes()?.let { Pair(it, File(it).isFile) } ?: Pair("%t", false)
|
||||||
val cfg: String =
|
val cfg: String =
|
||||||
"handlers = java.util.logging.FileHandler\n" +
|
"handlers = java.util.logging.FileHandler\n" +
|
||||||
"java.util.logging.FileHandler.level = ALL\n" +
|
"java.util.logging.FileHandler.level = ALL\n" +
|
||||||
|
|||||||
+2
-2
@@ -16,7 +16,7 @@ import kotlinx.coroutines.channels.Channel
|
|||||||
import kotlinx.coroutines.channels.actor
|
import kotlinx.coroutines.channels.actor
|
||||||
import kotlinx.coroutines.channels.consumeEach
|
import kotlinx.coroutines.channels.consumeEach
|
||||||
import org.jetbrains.kotlin.cli.common.CLICompiler
|
import org.jetbrains.kotlin.cli.common.CLICompiler
|
||||||
import org.jetbrains.kotlin.cli.common.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY
|
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
|
||||||
import org.jetbrains.kotlin.cli.common.repl.ReplCheckResult
|
import org.jetbrains.kotlin.cli.common.repl.ReplCheckResult
|
||||||
import org.jetbrains.kotlin.cli.common.repl.ReplCodeLine
|
import org.jetbrains.kotlin.cli.common.repl.ReplCodeLine
|
||||||
import org.jetbrains.kotlin.cli.common.repl.ReplCompileResult
|
import org.jetbrains.kotlin.cli.common.repl.ReplCompileResult
|
||||||
@@ -402,7 +402,7 @@ class CompileServiceServerSideImpl(
|
|||||||
scheduler = CompileServiceTaskScheduler(log)
|
scheduler = CompileServiceTaskScheduler(log)
|
||||||
|
|
||||||
// assuming logically synchronized
|
// assuming logically synchronized
|
||||||
System.setProperty(KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY, "true")
|
CompilerSystemProperties.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY.value = "true"
|
||||||
|
|
||||||
// TODO UNCOMMENT THIS : this.toRMIServer(daemonOptions, compilerId) // also create RMI server in order to support old clients
|
// TODO UNCOMMENT THIS : this.toRMIServer(daemonOptions, compilerId) // also create RMI server in order to support old clients
|
||||||
// rmiServer = this.toRMIServer(daemonOptions, compilerId)
|
// rmiServer = this.toRMIServer(daemonOptions, compilerId)
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ package org.jetbrains.kotlin.compilerRunner
|
|||||||
import com.intellij.util.xmlb.XmlSerializerUtil
|
import com.intellij.util.xmlb.XmlSerializerUtil
|
||||||
import org.jetbrains.annotations.TestOnly
|
import org.jetbrains.annotations.TestOnly
|
||||||
import org.jetbrains.jps.api.GlobalOptions
|
import org.jetbrains.jps.api.GlobalOptions
|
||||||
|
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
|
||||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||||
import org.jetbrains.kotlin.cli.common.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY
|
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.*
|
import org.jetbrains.kotlin.cli.common.arguments.*
|
||||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollectorUtil
|
import org.jetbrains.kotlin.cli.common.messages.MessageCollectorUtil
|
||||||
import org.jetbrains.kotlin.config.CompilerSettings
|
import org.jetbrains.kotlin.config.CompilerSettings
|
||||||
@@ -295,7 +295,7 @@ class JpsKotlinCompilerRunner {
|
|||||||
// unfortunately it cannot be currently set by default globally, because it breaks many tests
|
// unfortunately it cannot be currently set by default globally, because it breaks many tests
|
||||||
// since there is no reliable way so far to detect running under tests, switching it on only for parallel builds
|
// since there is no reliable way so far to detect running under tests, switching it on only for parallel builds
|
||||||
if (System.getProperty(GlobalOptions.COMPILE_PARALLEL_OPTION, "false").toBoolean())
|
if (System.getProperty(GlobalOptions.COMPILE_PARALLEL_OPTION, "false").toBoolean())
|
||||||
System.setProperty(KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY, "true")
|
CompilerSystemProperties.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY.value = "true"
|
||||||
|
|
||||||
val rc = environment.withProgressReporter { progress ->
|
val rc = environment.withProgressReporter { progress ->
|
||||||
progress.compilationStarted()
|
progress.compilationStarted()
|
||||||
|
|||||||
+1
-3
@@ -24,6 +24,7 @@ import org.gradle.api.internal.FeaturePreviews
|
|||||||
import org.gradle.api.logging.Logger
|
import org.gradle.api.logging.Logger
|
||||||
import org.gradle.api.logging.Logging
|
import org.gradle.api.logging.Logging
|
||||||
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
|
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
|
||||||
|
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
|
||||||
import org.jetbrains.kotlin.gradle.dsl.*
|
import org.jetbrains.kotlin.gradle.dsl.*
|
||||||
import org.jetbrains.kotlin.gradle.logging.kotlinDebug
|
import org.jetbrains.kotlin.gradle.logging.kotlinDebug
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget
|
||||||
@@ -76,9 +77,6 @@ abstract class KotlinBasePluginWrapper : Plugin<Project> {
|
|||||||
it.add(project.dependencies.create("$KOTLIN_MODULE_GROUP:$KOTLIN_KLIB_COMMONIZER_EMBEDDABLE:$kotlinPluginVersion"))
|
it.add(project.dependencies.create("$KOTLIN_MODULE_GROUP:$KOTLIN_KLIB_COMMONIZER_EMBEDDABLE:$kotlinPluginVersion"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: consider only set if if daemon or parallel compilation are enabled, though this way it should be safe too
|
|
||||||
System.setProperty(org.jetbrains.kotlin.cli.common.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY, "true")
|
|
||||||
|
|
||||||
val kotlinGradleBuildServices = KotlinGradleBuildServices.getInstance(project, listenerRegistryHolder)
|
val kotlinGradleBuildServices = KotlinGradleBuildServices.getInstance(project, listenerRegistryHolder)
|
||||||
|
|
||||||
kotlinGradleBuildServices.detectKotlinPluginLoadedInMultipleProjects(project, kotlinPluginVersion)
|
kotlinGradleBuildServices.detectKotlinPluginLoadedInMultipleProjects(project, kotlinPluginVersion)
|
||||||
|
|||||||
+29
-11
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.build.report.metrics.BuildMetricsReporter
|
|||||||
import org.jetbrains.kotlin.build.report.metrics.BuildMetricsReporterImpl
|
import org.jetbrains.kotlin.build.report.metrics.BuildMetricsReporterImpl
|
||||||
import org.jetbrains.kotlin.build.report.metrics.BuildTime
|
import org.jetbrains.kotlin.build.report.metrics.BuildTime
|
||||||
import org.jetbrains.kotlin.build.report.metrics.measure
|
import org.jetbrains.kotlin.build.report.metrics.measure
|
||||||
|
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.CommonToolArguments
|
import org.jetbrains.kotlin.cli.common.arguments.CommonToolArguments
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
||||||
@@ -334,6 +335,21 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractKo
|
|||||||
|
|
||||||
@TaskAction
|
@TaskAction
|
||||||
fun execute(inputs: IncrementalTaskInputs) {
|
fun execute(inputs: IncrementalTaskInputs) {
|
||||||
|
CompilerSystemProperties.systemPropertyGetter = {
|
||||||
|
val value = 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 ->
|
||||||
|
val oldValue = kotlinDaemonProperties[key]
|
||||||
|
if (oldValue == value) return@setter oldValue
|
||||||
|
kotlinDaemonProperties[key] = value
|
||||||
|
System.setProperty(key, value)
|
||||||
|
logger.warn("System property set $key = $value (was: $oldValue)")
|
||||||
|
oldValue
|
||||||
|
}
|
||||||
|
CompilerSystemProperties.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY.value = "true"
|
||||||
|
|
||||||
// If task throws exception, but its outputs are changed during execution,
|
// If task throws exception, but its outputs are changed during execution,
|
||||||
// then Gradle forces next build to be non-incremental (see Gradle's DefaultTaskArtifactStateRepository#persistNewOutputs)
|
// then Gradle forces next build to be non-incremental (see Gradle's DefaultTaskArtifactStateRepository#persistNewOutputs)
|
||||||
// To prevent this, we backup outputs before incremental build and restore when exception is thrown
|
// To prevent this, we backup outputs before incremental build and restore when exception is thrown
|
||||||
@@ -425,6 +441,15 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractKo
|
|||||||
val taskBuildDir = taskBuildDirectory
|
val taskBuildDir = taskBuildDirectory
|
||||||
return taskBuildDir.walk().any { it != taskBuildDir && it.isFile }
|
return taskBuildDir.walk().any { it != taskBuildDir && it.isFile }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@get:Internal
|
||||||
|
val kotlinDaemonProperties: MutableMap<String, String?> by lazy {
|
||||||
|
if (isGradleVersionAtLeast(6, 5)) {
|
||||||
|
CompilerSystemProperties.values()
|
||||||
|
.associate { it.property to project.providers.systemProperty(it.property).forUseAtConfigurationTime().orNull }
|
||||||
|
.toMutableMap()
|
||||||
|
} else mutableMapOf()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open class KotlinCompileArgumentsProvider<T : AbstractKotlinCompile<out CommonCompilerArguments>>(taskProvider: T) {
|
open class KotlinCompileArgumentsProvider<T : AbstractKotlinCompile<out CommonCompilerArguments>>(taskProvider: T) {
|
||||||
@@ -686,17 +711,6 @@ open class Kotlin2JsCompile : AbstractKotlinCompile<K2JSCompilerArguments>(), Ko
|
|||||||
|
|
||||||
override fun getSourceRoots() = SourceRoots.KotlinOnly.create(getSource(), sourceFilesExtensions)
|
override fun getSourceRoots() = SourceRoots.KotlinOnly.create(getSource(), sourceFilesExtensions)
|
||||||
|
|
||||||
@get:InputFiles
|
|
||||||
@get:Optional
|
|
||||||
@get:PathSensitive(PathSensitivity.RELATIVE)
|
|
||||||
internal val friendDependencies: List<String>
|
|
||||||
get() {
|
|
||||||
val filter = libraryFilter
|
|
||||||
return friendPaths.files.filter {
|
|
||||||
it.exists() && filter(it)
|
|
||||||
}.map { it.absolutePath }
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
@get:InputFiles
|
@get:InputFiles
|
||||||
@get:Optional
|
@get:Optional
|
||||||
@@ -760,6 +774,10 @@ open class Kotlin2JsCompile : AbstractKotlinCompile<K2JSCompilerArguments>(), Ko
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val friendDependencies: List<String> = friendPaths.files.filter {
|
||||||
|
it.exists() && libraryFilter(it)
|
||||||
|
}.map { it.absolutePath }
|
||||||
|
|
||||||
args.friendModules = friendDependencies.joinToString(File.pathSeparator)
|
args.friendModules = friendDependencies.joinToString(File.pathSeparator)
|
||||||
|
|
||||||
if (args.sourceMapBaseDirs == null && !args.sourceMapPrefix.isNullOrEmpty()) {
|
if (args.sourceMapBaseDirs == null && !args.sourceMapPrefix.isNullOrEmpty()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user