[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
@@ -5,8 +5,7 @@
package org.jetbrains.kotlin.backend.konan
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.getLogger
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.konan.file.File
import org.jetbrains.kotlin.konan.library.defaultResolver
@@ -15,7 +14,6 @@ import org.jetbrains.kotlin.konan.target.KonanTarget
import org.jetbrains.kotlin.library.UnresolvedLibrary
import org.jetbrains.kotlin.library.metadata.resolver.impl.libraryResolver
import org.jetbrains.kotlin.library.toUnresolvedLibraries
import org.jetbrains.kotlin.util.Logger
class KonanLibrariesResolveSupport(
configuration: CompilerConfiguration,
@@ -34,24 +32,13 @@ class KonanLibrariesResolveSupport(
private val unresolvedLibraries = libraryNames.toUnresolvedLibraries
private val repositories = configuration.getList(KonanConfigKeys.REPOSITORIES)
private val resolverLogger =
object : Logger {
private val collector = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
override fun warning(message: String)= collector.report(CompilerMessageSeverity.STRONG_WARNING, message)
override fun error(message: String) = collector.report(CompilerMessageSeverity.ERROR, message)
override fun log(message: String) = collector.report(CompilerMessageSeverity.LOGGING, message)
override fun fatal(message: String): Nothing {
collector.report(CompilerMessageSeverity.ERROR, message)
throw KonanCompilationException()
}
}
private val resolver = defaultResolver(
repositories,
libraryNames.filter { it.contains(File.separator) } + includedLibraryFiles.map { it.absolutePath },
target,
distribution,
resolverLogger
configuration.getLogger()
).libraryResolver(resolveManifestDependenciesLenient)
// We pass included libraries by absolute paths to avoid repository-based resolution for them.