jvm-abi-gen: report compilation errors instead of throwing exceptions during configuration
This commit is contained in:
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.jvm.abi
|
||||
|
||||
import com.intellij.mock.MockProject
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
import org.jetbrains.kotlin.codegen.extensions.ClassBuilderInterceptorExtension
|
||||
import org.jetbrains.kotlin.codegen.extensions.ClassFileFactoryFinalizerExtension
|
||||
@@ -20,13 +21,14 @@ import java.io.File
|
||||
class JvmAbiComponentRegistrar : ComponentRegistrar {
|
||||
override fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration) {
|
||||
val outputPath = configuration.getNotNull(JvmAbiConfigurationKeys.OUTPUT_PATH)
|
||||
val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
|
||||
if (configuration.get(JvmAbiConfigurationKeys.LEGACY_ABI_GEN, false)) {
|
||||
require(!configuration.getBoolean(CommonConfigurationKeys.USE_FIR)) {
|
||||
"Legacy jvm-abi-gen does not support K2 compiler."
|
||||
if (configuration.getBoolean(CommonConfigurationKeys.USE_FIR)) {
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, "Legacy jvm-abi-gen does not support K2 compiler.")
|
||||
}
|
||||
// Use the two-pass implementation
|
||||
require(!outputPath.endsWith(".jar")) {
|
||||
"Legacy jvm-abi-gen does not support jar output."
|
||||
if (outputPath.endsWith(".jar")) {
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, "Legacy jvm-abi-gen does not support jar output.")
|
||||
}
|
||||
val extension = JvmAbiAnalysisHandlerExtension(configuration.copy().apply {
|
||||
put(JVMConfigurationKeys.OUTPUT_DIRECTORY, File(outputPath))
|
||||
@@ -36,7 +38,6 @@ class JvmAbiComponentRegistrar : ComponentRegistrar {
|
||||
// Use the single-pass implementation, using the new ABI flag in the metadata.
|
||||
configuration.put(JVMConfigurationKeys.RETAIN_OUTPUT_IN_MEMORY, true)
|
||||
val builderExtension = JvmAbiClassBuilderInterceptor()
|
||||
val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
|
||||
val outputExtension = JvmAbiOutputExtension(File(outputPath), builderExtension.abiClassInfo, messageCollector)
|
||||
ClassBuilderInterceptorExtension.registerExtension(project, builderExtension)
|
||||
ClassFileFactoryFinalizerExtension.registerExtension(project, outputExtension)
|
||||
@@ -45,4 +46,4 @@ class JvmAbiComponentRegistrar : ComponentRegistrar {
|
||||
|
||||
override val supportsK2: Boolean
|
||||
get() = true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user