[KLIB Resolver] Report KLIB resolver issues as compiler messages

The reason of this change is to make messages (especially warnings)
that are reported by the KLIB resolver become visible to the end user.
This can be achieved to forwarding such messages to the appropriate
compiler's components such as
`org.jetbrains.kotlin.cli.common.messages.MessageCollector` and
`org.jetbrains.kotlin.ir.util.IrMessageLogger`.

Also: The default `DummyLogger` should be used as minimal as possible.
Because it just forwards messages to the standard output (console)
where they can remain unattended. When the compiler is executed
from the Gradle plugin such messages appear only in DEBUG Gradle's log.

^KT-63573
This commit is contained in:
Dmitriy Dolovov
2023-11-28 18:52:19 +01:00
committed by Space Team
parent 8430be39c9
commit 46081f968d
21 changed files with 136 additions and 108 deletions
@@ -0,0 +1,30 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.backend.common
import org.jetbrains.kotlin.analyzer.CompilationErrorException
import org.jetbrains.kotlin.ir.util.IrMessageLogger
import org.jetbrains.kotlin.ir.util.IrMessageLogger.Severity.*
import org.jetbrains.kotlin.util.DummyLogger
import org.jetbrains.kotlin.util.Logger
/**
* An adapter for the [Logger] interface that reports all messages to compiler's [IrMessageLogger].
*/
private class IrMessageLoggerAdapter(private val irMessageLogger: IrMessageLogger) : Logger {
override fun log(message: String) = irMessageLogger.report(INFO, message, null)
override fun warning(message: String) = irMessageLogger.report(WARNING, message, null)
override fun error(message: String) = irMessageLogger.report(ERROR, message, null)
override fun fatal(message: String): Nothing {
error(message)
throw CompilationErrorException()
}
}
fun IrMessageLogger.toLogger(): Logger {
return if (this != IrMessageLogger.None) IrMessageLoggerAdapter(this) else DummyLogger
}