[FE] Add ability to set compatibility of plugin with K2 in ComponentRegistrar

This commit is contained in:
Dmitriy Novozhilov
2022-05-13 16:43:14 +03:00
committed by teamcity
parent 67589b1b09
commit 4003ca0691
4 changed files with 20 additions and 7 deletions
@@ -87,13 +87,17 @@ object FirKotlinToJvmBytecodeCompiler {
)
projectConfiguration.get(ComponentRegistrar.PLUGIN_COMPONENT_REGISTRARS)?.let { pluginComponentRegistrars ->
val nonScriptPlugins = pluginComponentRegistrars.filter {
it::class.java.canonicalName != CLICompiler.SCRIPT_PLUGIN_REGISTRAR_NAME
val notSupportedPlugins = pluginComponentRegistrars.filter {
!it.supportsK2 || it::class.java.canonicalName != CLICompiler.SCRIPT_PLUGIN_REGISTRAR_NAME
}
if (nonScriptPlugins.isNotEmpty()) {
if (notSupportedPlugins.isNotEmpty()) {
messageCollector.report(
CompilerMessageSeverity.ERROR,
"Compiler plugins are enabled with K2 compiler.\n K2 does not support plugins yet, so please remove -Xuse-k2 flag"
"""
|There are some plugins incompatible with K2 compiler:
|${notSupportedPlugins.joinToString(separator = "\n|") { " ${it::class.qualifiedName}" }}
|Please remove -Xuse-k2
""".trimMargin()
)
return false
}
@@ -26,4 +26,7 @@ interface ComponentRegistrar {
}
fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration)
val supportsK2: Boolean
get() = false
}
+3 -2
View File
@@ -1,6 +1,7 @@
warning: ATTENTION!
This build uses experimental K2 compiler:
-Xuse-k2
error: compiler plugins are enabled with K2 compiler.
K2 does not support plugins yet, so please remove -Xuse-k2 flag
error: there are some plugins incompatible with K2 compiler:
org.jetbrains.kotlin.android.synthetic.AndroidComponentRegistrar
Please remove -Xuse-k2
COMPILATION_ERROR
@@ -43,6 +43,11 @@ private fun <T : Any> ProjectExtensionDescriptor<T>.registerExtensionIfRequired(
}
class ScriptingCompilerConfigurationComponentRegistrar : ComponentRegistrar {
// Actually this plugin don't support K2, but it automatically registered in some cases,
// so for now this flag is just a stub
override val supportsK2: Boolean
get() = true
override fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration) {
val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
val hostConfiguration = ScriptingHostConfiguration(defaultJvmScriptingHostConfiguration) {
@@ -84,4 +89,4 @@ private inline fun withClassloadingProblemsReporting(messageCollector: MessageCo
System.err.println(msg)
}
}
}
}