Log daemon exception for In process compilation into error.log

This commit is contained in:
nataliya.valtman
2022-09-29 13:28:33 +02:00
committed by Space Team
parent 242b83edbd
commit 2379185398
6 changed files with 22 additions and 11 deletions
@@ -40,19 +40,19 @@ fun launchProcessWithFallback(processBuilder: ProcessBuilder, reportingTargets:
NativePlatformLauncherWrapper().launch(processBuilder)
}
catch (e: UnsatisfiedLinkError) {
reportingTargets.report(DaemonReportCategory.DEBUG, "Could not start process with native process launcher, falling back to ProcessBuilder#start ($e)", reportingSource)
reportingTargets.report(DaemonReportCategory.EXCEPTION, "Could not start process with native process launcher, falling back to ProcessBuilder#start ($e)", reportingSource)
null
}
catch (e: IOException) {
reportingTargets.report(DaemonReportCategory.DEBUG, "Could not start process with native process launcher, falling back to ProcessBuilder#start (${e.cause})", reportingSource)
reportingTargets.report(DaemonReportCategory.EXCEPTION, "Could not start process with native process launcher, falling back to ProcessBuilder#start (${e.cause})", reportingSource)
null
}
catch (e: NoClassDefFoundError) {
reportingTargets.report(DaemonReportCategory.DEBUG, "net.rubygrapefruit.platform library is not in the classpath, falling back to ProcessBuilder#start ($e)", reportingSource)
reportingTargets.report(DaemonReportCategory.EXCEPTION, "net.rubygrapefruit.platform library is not in the classpath, falling back to ProcessBuilder#start ($e)", reportingSource)
null
}
catch (e: ClassNotFoundException) {
reportingTargets.report(DaemonReportCategory.DEBUG, "net.rubygrapefruit.platform library is not in the classpath, falling back to ProcessBuilder#start ($e)", reportingSource)
reportingTargets.report(DaemonReportCategory.EXCEPTION, "net.rubygrapefruit.platform library is not in the classpath, falling back to ProcessBuilder#start ($e)", reportingSource)
null
}
?: processBuilder.start()
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.incremental
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.incremental.AbiSnapshotImpl.Companion.readAbiSnapshot
import org.jetbrains.kotlin.incremental.AbiSnapshotImpl.Companion.writeAbiSnapshot
import org.jetbrains.kotlin.incremental.util.ExceptionLocation
import org.jetbrains.kotlin.incremental.util.reportException
import java.io.*
@@ -51,7 +52,7 @@ data class BuildInfo(val startTS: Long, val dependencyToAbiSnapshot: Map<String,
it.readBuildInfo()
}
} catch (e: Exception) {
messageCollector.reportException(e)
messageCollector.reportException(e, ExceptionLocation.INCREMENTAL_COMPILATION)
null
}
}
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.incremental.components.ExpectActualTracker
import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.incremental.parsing.classesFqNames
import org.jetbrains.kotlin.incremental.util.BufferingMessageCollector
import org.jetbrains.kotlin.incremental.util.ExceptionLocation
import org.jetbrains.kotlin.incremental.util.reportException
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
@@ -98,7 +99,7 @@ abstract class IncrementalCompilerRunner<
)
}
is ICResult.Failed -> {
messageCollector.reportException(result.cause)
messageCollector.reportException(result.cause, ExceptionLocation.INCREMENTAL_COMPILATION)
reporter.warn {
// The indentation after the first line is intentional (so that this message is distinct from next message)
"""
@@ -7,8 +7,13 @@ package org.jetbrains.kotlin.incremental.util
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
internal fun MessageCollector.reportException(e: Throwable) {
report(severity = CompilerMessageSeverity.EXCEPTION, message = "Incremental compilation failed:${e.message}\n${e.stackTraceToString()}")
public fun MessageCollector.reportException(e: Throwable, location: ExceptionLocation) {
report(severity = CompilerMessageSeverity.EXCEPTION, message = "$location failed:${e.message}\n${e.stackTraceToString()}")
}
public enum class ExceptionLocation(val readablename: String) {
INCREMENTAL_COMPILATION("Incremental compilation"),
DAEMON("Daemon compilation"),
OUT_OF_PROCESS_COMPILATION("Out of process compilation")
}
@@ -22,6 +22,8 @@ import org.jetbrains.kotlin.gradle.utils.stackTraceAsString
import org.jetbrains.kotlin.incremental.ChangedFiles
import org.jetbrains.kotlin.incremental.ClasspathChanges
import org.jetbrains.kotlin.incremental.IncrementalModuleInfo
import org.jetbrains.kotlin.incremental.util.ExceptionLocation
import org.jetbrains.kotlin.incremental.util.reportException
import org.jetbrains.kotlin.util.removeSuffixIfPresent
import org.slf4j.LoggerFactory
import java.io.*
@@ -153,6 +155,7 @@ internal class GradleKotlinCompilerWork @Inject constructor(
try {
return compileWithDaemon(messageCollector) to KotlinCompilerExecutionStrategy.DAEMON
} catch (e: Throwable) {
messageCollector.reportException(e, ExceptionLocation.DAEMON)
if (!compilerExecutionSettings.useDaemonFallbackStrategy) {
throw RuntimeException(
"Failed to compile with Kotlin daemon. Fallback strategy (compiling without Kotlin daemon) is turned off. " +
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
import org.jetbrains.kotlin.config.KotlinCompilerVersion
import org.jetbrains.kotlin.daemon.client.DaemonReportingTargets
import org.jetbrains.kotlin.daemon.client.launchProcessWithFallback
import org.jetbrains.kotlin.gradle.logging.GradleErrorMessageCollector
import org.jetbrains.kotlin.gradle.logging.GradleKotlinLogger
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilerExecutionStrategy
import org.jetbrains.org.objectweb.asm.ClassReader
@@ -107,13 +108,13 @@ internal fun runToolInSeparateProcess(
compilerClassName,
"@${compilerOptions.absolutePath}"
)
val messageCollector = createLoggingMessageCollector(logger)
val messageCollector = GradleErrorMessageCollector(createLoggingMessageCollector(logger))
val process = launchProcessWithFallback(builder, DaemonReportingTargets(messageCollector = messageCollector))
// important to read inputStream, otherwise the process may hang on some systems
val readErrThread = thread {
process.errorStream!!.bufferedReader().forEachLine {
logger.error(it)
messageCollector.report(CompilerMessageSeverity.EXCEPTION, it)
}
}