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