[KAPT4] KT-61761 Prevent Kapt from reporting unsupported plugin in K2/PSI

Also:
- remove the redundant KaptOptions.USE_K2
- prevent registration of Kapt4AnalysisHandlerExtension in K1
This commit is contained in:
strangepleasures
2023-09-12 16:58:38 +00:00
committed by Space Team
parent 6475942ced
commit 52b0ea65d2
4 changed files with 10 additions and 18 deletions
@@ -149,10 +149,9 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
createProjectEnvironment(configuration, rootDisposable, EnvironmentConfigFiles.JVM_CONFIG_FILES, messageCollector)
if (messageCollector.hasErrors()) return COMPILATION_ERROR
// TODO: uncomment (KT-61761)
// if (!FirKotlinToJvmBytecodeCompiler.checkNotSupportedPlugins(configuration, messageCollector)) {
// return COMPILATION_ERROR
// }
if (!FirKotlinToJvmBytecodeCompiler.checkNotSupportedPlugins(configuration, messageCollector)) {
return COMPILATION_ERROR
}
compileModulesUsingFrontendIrAndLightTree(
projectEnvironment, configuration, messageCollector, buildFile, chunk.single(), targetDescription,
@@ -130,7 +130,6 @@ enum class KaptFlag(val description: String, val defaultValue: Boolean = false)
STRIP_METADATA("Strip @Metadata annotations from stubs"),
KEEP_KDOC_COMMENTS_IN_STUBS("Keep KDoc comments in stubs", defaultValue = true),
USE_JVM_IR("Use JVM IR backend", defaultValue = true),
USE_K2("Use K2"),
;
}
@@ -125,7 +125,7 @@ class Kapt3CommandLineProcessor : CommandLineProcessor {
STRIP_METADATA_OPTION -> setFlag(KaptFlag.STRIP_METADATA, value)
KEEP_KDOC_COMMENTS_IN_STUBS -> setFlag(KaptFlag.KEEP_KDOC_COMMENTS_IN_STUBS, value)
USE_JVM_IR -> setFlag(KaptFlag.USE_JVM_IR, value)
USE_K2 -> setFlag(KaptFlag.USE_K2, value)
USE_K2 -> {}
SHOW_PROCESSOR_STATS -> setFlag(KaptFlag.SHOW_PROCESSOR_STATS, value)
DUMP_PROCESSOR_STATS -> processorsStatsReportFile = File(value)
@@ -169,11 +169,11 @@ class Kapt3CommandLineProcessor : CommandLineProcessor {
@Suppress("DEPRECATION")
class Kapt3ComponentRegistrar : ComponentRegistrar {
override val supportsK2: Boolean
get() = false
get() = true
override fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration) {
val optionsBuilder = (configuration[KAPT_OPTIONS] ?: KaptOptions.Builder())
if (configuration.getBoolean(USE_FIR) || KaptFlag.USE_K2 in optionsBuilder.flags) return
if (configuration.getBoolean(USE_FIR)) return
doOpenInternalPackagesIfRequired()
val contentRoots = configuration[CLIConfigurationKeys.CONTENT_ROOTS] ?: emptyList()
@@ -32,8 +32,7 @@ import java.io.File
private class Kapt4AnalysisHandlerExtension : FirAnalysisHandlerExtension() {
override fun isApplicable(configuration: CompilerConfiguration): Boolean {
val options = configuration[KAPT_OPTIONS]
return options != null && (configuration.getBoolean(USE_FIR) || KaptFlag.USE_K2 in options.flags)
return configuration[KAPT_OPTIONS] != null && configuration.getBoolean(USE_FIR)
}
@OptIn(KtAnalysisApiInternals::class)
@@ -181,16 +180,11 @@ private class Kapt4AnalysisHandlerExtension : FirAnalysisHandlerExtension() {
class Kapt4CompilerPluginRegistrar : CompilerPluginRegistrar() {
override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) {
Companion.registerExtensions(this)
if (!configuration.getBoolean(USE_FIR)) return
FirAnalysisHandlerExtension.registerExtension(Kapt4AnalysisHandlerExtension())
}
override val supportsK2: Boolean
get() = true
companion object {
fun registerExtensions(extensionStorage: ExtensionStorage) = with(extensionStorage) {
FirAnalysisHandlerExtension.registerExtension(Kapt4AnalysisHandlerExtension())
}
}
}