[Daemon] Improve some daemon log messages

A few messages were improved:
  * If the daemon process died at the startup, add its last 10 lines of the output to the log and report to the EXCEPTION (ERROR in the case of Gradle) level
  * If some exception occurs during connection attempt, add its stacktrace and report to the EXCEPTION (ERROR in the case of Gradle) level
  * Added more DEBUG level messages
  * Some important messages are moved to the INFO level
  * Added a suggestion to report issue to kotl.in/issue
^KT-55322 Fixed
This commit is contained in:
Alexander.Likhachev
2023-11-21 12:58:05 +01:00
committed by Space Team
parent 95bc49054f
commit b000b66ef7
8 changed files with 120 additions and 27 deletions
@@ -69,10 +69,6 @@ class ExecutionStrategyJvmIT : ExecutionStrategyIT() {
}
abstract class ExecutionStrategyIT : KGPDaemonsBaseTest() {
override val defaultBuildOptions: BuildOptions = super.defaultBuildOptions.copy(
logLevel = LogLevel.DEBUG
)
@DisplayName("Compilation via Kotlin daemon")
@GradleTest
fun testDaemon(gradleVersion: GradleVersion) {
@@ -113,7 +109,9 @@ abstract class ExecutionStrategyIT : KGPDaemonsBaseTest() {
"build",
"-Pkotlin.daemon.jvmargs=-Xmxqwerty",
) {
assertOutputContains("Failed to compile with Kotlin daemon. Fallback strategy (compiling without Kotlin daemon) is turned off.")
assertOutputContains("Invalid maximum heap size: -Xmxqwerty")
assertOutputContains("Failed to compile with Kotlin daemon.")
assertOutputContains("Fallback strategy (compiling without Kotlin daemon) is turned off.")
}
}
}
@@ -146,7 +144,9 @@ abstract class ExecutionStrategyIT : KGPDaemonsBaseTest() {
"build",
"-Pkotlin.daemon.jvmargs=-Xmxqwerty",
) {
assertOutputContains("Failed to compile with Kotlin daemon. Fallback strategy (compiling without Kotlin daemon) is turned off.")
assertOutputContains("Invalid maximum heap size: -Xmxqwerty")
assertOutputContains("Failed to compile with Kotlin daemon.")
assertOutputContains("Fallback strategy (compiling without Kotlin daemon) is turned off.")
}
}
}
@@ -212,7 +212,12 @@ abstract class ExecutionStrategyIT : KGPDaemonsBaseTest() {
executionStrategy
} else {
null
}
},
logLevel = if (!testFallbackStrategy && executionStrategy == KotlinCompilerExecutionStrategy.DAEMON) {
LogLevel.DEBUG // used daemon JVM options are reported only to the DEBUG logs
} else {
defaultBuildOptions.logLevel
},
)
) {
setupProject(this)
@@ -232,6 +237,7 @@ abstract class ExecutionStrategyIT : KGPDaemonsBaseTest() {
assertNoBuildWarnings()
if (testFallbackStrategy) {
assertOutputContains("Invalid maximum heap size: -Xmxqwerty")
assertOutputContains("Using fallback strategy: Compile without Kotlin daemon")
} else if (executionStrategy == KotlinCompilerExecutionStrategy.DAEMON) {
// 256m is the default value for Gradle 5.0+
@@ -158,9 +158,12 @@ fun BuildResult.assertOutputContainsExactlyTimes(
* Assert build contains no warnings.
*/
fun BuildResult.assertNoBuildWarnings(
expectedWarnings: Set<String> = emptySet(),
additionalExpectedWarnings: Set<String> = emptySet(),
) {
val cleanedOutput = expectedWarnings.fold(output) { acc, s ->
val expectedWarnings = setOf(
"w: [InternalKotlinGradlePluginPropertiesUsed | WARNING] ATTENTION! This build uses the following Kotlin Gradle Plugin properties:"
)
val cleanedOutput = (expectedWarnings + additionalExpectedWarnings).fold(output) { acc, s ->
acc.replace(s, "")
}
val warnings = cleanedOutput
@@ -176,7 +179,6 @@ fun BuildResult.assertNoBuildWarnings(
}
val expectedK2KaptWarnings = setOf(
"w: [InternalKotlinGradlePluginPropertiesUsed | WARNING] ATTENTION! This build uses the following Kotlin Gradle Plugin properties:",
"w: Kapt currently doesn't support language version 2.0+. Falling back to 1.9."
)
@@ -162,10 +162,17 @@ internal class GradleKotlinCompilerWork @Inject constructor(
severity = CompilerMessageSeverity.EXCEPTION,
message = "Daemon compilation failed: ${e.message}\n${e.stackTraceToString()}"
)
val recommendation = """
Try ./gradlew --stop if this issue persists
If it does not look related to your configuration, please file an issue with logs to https://kotl.in/issue
""".trimIndent()
if (!config.compilerExecutionSettings.useDaemonFallbackStrategy) {
throw RuntimeException(
"Failed to compile with Kotlin daemon. Fallback strategy (compiling without Kotlin daemon) is turned off. " +
"Try ./gradlew --stop if this issue persists.",
"""
|Failed to compile with Kotlin daemon.
|Fallback strategy (compiling without Kotlin daemon) is turned off.
|$recommendation
""".trimMargin(),
e
)
}
@@ -174,7 +181,7 @@ internal class GradleKotlinCompilerWork @Inject constructor(
"""
|Failed to compile with Kotlin daemon: $failDetails
|Using fallback strategy: Compile without Kotlin daemon
|Try ./gradlew --stop if this issue persists.
|$recommendation
""".trimMargin()
)
}
@@ -238,7 +238,7 @@ internal val KotlinCompilerExecutionStrategy.asFinishLogMessage: String
get() = "Finished executing kotlin compiler using $this strategy"
internal fun KotlinLogger.logFinish(strategy: KotlinCompilerExecutionStrategy) {
debug(strategy.asFinishLogMessage)
info(strategy.asFinishLogMessage)
}
internal fun exitCodeFromProcessExitCode(log: KotlinLogger, code: Int): ExitCode {