[KLIB Resolver] Deprecate Logger.fatal()
Invocation of Logger.fatal() may cause severe side effects such as throwing an exception or even terminating the current JVM process (check various implementations of this function for details). The code that uses Logger.fatal() sometimes expects a particular kind of side effect. This is totally a design flaw. And it's definitely not a responsibility of Logger to influence the execution flow of the program.
This commit is contained in:
committed by
Space Team
parent
50dd94502b
commit
e92017f64e
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.commonizer
|
||||
|
||||
import org.jetbrains.kotlin.commonizer.cli.errorAndExitJvmProcess
|
||||
import org.jetbrains.kotlin.commonizer.konan.NativeLibrary
|
||||
import org.jetbrains.kotlin.library.ToolingSingleFileKlibResolveStrategy
|
||||
import org.jetbrains.kotlin.library.metadata.KlibMetadataVersion
|
||||
@@ -29,11 +30,11 @@ internal class DefaultNativeLibraryLoader(
|
||||
)
|
||||
|
||||
if (library.versions.metadataVersion == null)
|
||||
logger.fatal("Library does not have metadata version specified in manifest: $file")
|
||||
logger.errorAndExitJvmProcess("Library does not have metadata version specified in manifest: $file")
|
||||
|
||||
val metadataVersion = library.metadataVersion
|
||||
if (metadataVersion?.isCompatibleWithCurrentCompilerVersion() != true)
|
||||
logger.fatal(
|
||||
logger.errorAndExitJvmProcess(
|
||||
"""
|
||||
Library has incompatible metadata version ${metadataVersion ?: "\"unknown\""}: $file
|
||||
Please make sure that all libraries passed to commonizer compatible metadata version ${KlibMetadataVersion.INSTANCE}
|
||||
|
||||
@@ -20,10 +20,11 @@ internal class CliLoggerAdapter(
|
||||
|
||||
override fun warning(message: String) = printlnIndented("Warning: $message", *CommonizerLogLevel.values())
|
||||
|
||||
override fun error(message: String) = fatal(message)
|
||||
override fun error(message: String) = printlnIndented("Error: $message\n", *CommonizerLogLevel.values())
|
||||
|
||||
@Deprecated(Logger.FATAL_DEPRECATION_MESSAGE, ReplaceWith(Logger.FATAL_REPLACEMENT))
|
||||
override fun fatal(message: String): Nothing {
|
||||
printlnIndented("Error: $message\n", *CommonizerLogLevel.values())
|
||||
error(message)
|
||||
exitProcess(1)
|
||||
}
|
||||
|
||||
@@ -36,3 +37,8 @@ internal class CliLoggerAdapter(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal fun Logger.errorAndExitJvmProcess(message: String): Nothing {
|
||||
error(message)
|
||||
exitProcess(1)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.commonizer.konan
|
||||
|
||||
import org.jetbrains.kotlin.commonizer.*
|
||||
import org.jetbrains.kotlin.commonizer.cli.errorAndExitJvmProcess
|
||||
import org.jetbrains.kotlin.commonizer.repository.Repository
|
||||
import org.jetbrains.kotlin.commonizer.stats.StatsCollector
|
||||
import org.jetbrains.kotlin.commonizer.utils.progress
|
||||
@@ -94,8 +95,8 @@ internal class LibraryCommonizer internal constructor(
|
||||
private fun checkPreconditions() {
|
||||
outputTargets.forEach { outputTarget ->
|
||||
when (outputTarget.allLeaves().size) {
|
||||
0 -> logger.fatal("No targets specified")
|
||||
1 -> logger.fatal("Too few targets specified: $outputTarget")
|
||||
0 -> logger.errorAndExitJvmProcess("No targets specified")
|
||||
1 -> logger.errorAndExitJvmProcess("Too few targets specified: $outputTarget")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user