From b23092b447801f81a524084c941fa80b2e0de82e Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Fri, 10 Jun 2022 09:47:24 +0300 Subject: [PATCH] jvm-abi-gen: report compilation errors instead of throwing exceptions during configuration --- .../kotlin/jvm/abi/JvmAbiComponentRegistrar.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/plugins/jvm-abi-gen/src/org/jetbrains/kotlin/jvm/abi/JvmAbiComponentRegistrar.kt b/plugins/jvm-abi-gen/src/org/jetbrains/kotlin/jvm/abi/JvmAbiComponentRegistrar.kt index ce8b7720e90..3750274b4f6 100644 --- a/plugins/jvm-abi-gen/src/org/jetbrains/kotlin/jvm/abi/JvmAbiComponentRegistrar.kt +++ b/plugins/jvm-abi-gen/src/org/jetbrains/kotlin/jvm/abi/JvmAbiComponentRegistrar.kt @@ -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 -} \ No newline at end of file +}