KT-65684: KAPT: (Re)enable fallback to K1 KAPT and make it default

[KAPT] KT-65684 Set languageVersion=1.9 in KaptToolIntegrationTestGenerated

[KAPT] KT-65684 Re-enable a few now-passing tests in Kapt4IT

[KAPT] KT-65684 Fix the logic setting -Xuse-kapt4 flag in Kapt4IT.forceKapt4()

The change is needed to make sure that all the tests have the flag set,
 otherwise some of them would silently switch to the fallback node.
Also disables a few now failing tests.

[KAPT] KT-65684 Revert "KT-64385 Enable K2 KAPT by default"

This reverts commit 7e9d6e60


Merge-request: KT-MR-14291
Merged-by: Pavel Mikhailovskii <Pavel.Mikhailovskii@jetbrains.com>
This commit is contained in:
Pavel Mikhailovskii
2024-02-09 12:54:28 +00:00
committed by Space Team
parent e532220305
commit 7ab9e03347
40 changed files with 459 additions and 127 deletions
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.cli.common
import com.intellij.ide.highlighter.JavaFileType
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.CommonToolArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.ManualLanguageFeatureSetting
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
@@ -47,6 +48,7 @@ fun CompilerConfiguration.setupCommonArguments(
}
}
switchToFallbackModeIfNecessary(arguments, messageCollector)
setupLanguageVersionSettings(arguments)
val usesK2 = arguments.useK2 || languageVersionSettings.languageVersion.usesK2
@@ -55,6 +57,34 @@ fun CompilerConfiguration.setupCommonArguments(
buildHmppModuleStructure(arguments)?.let { put(CommonConfigurationKeys.HMPP_MODULE_STRUCTURE, it) }
}
private fun switchToFallbackModeIfNecessary(arguments: CommonCompilerArguments, messageCollector: MessageCollector) {
fun warn(message: String) {
if (!arguments.suppressVersionWarnings) messageCollector.report(CompilerMessageSeverity.STRONG_WARNING, message)
}
if (arguments !is K2JVMCompilerArguments) return
val isK2 =
arguments.useK2 || (arguments.languageVersion?.startsWith('2') ?: (LanguageVersion.LATEST_STABLE >= LanguageVersion.KOTLIN_2_0))
val isKaptUsed = arguments.pluginOptions?.any { it.startsWith("plugin:org.jetbrains.kotlin.kapt3") } == true
when {
isK2 && isKaptUsed && !arguments.useKapt4 -> {
warn("Kapt currently doesn't support language version 2.0+. Falling back to 1.9.")
arguments.languageVersion = LanguageVersion.KOTLIN_1_9.versionString
if (arguments.apiVersion?.startsWith("2") == true) {
arguments.apiVersion = ApiVersion.KOTLIN_1_9.versionString
}
arguments.useK2 = false
arguments.skipMetadataVersionCheck = true
arguments.skipPrereleaseCheck = true
arguments.allowUnstableDependencies = true
}
arguments.useKapt4 -> warn(
if (isK2) "K2 kapt is an experimental feature. Use with caution."
else "-Xuse-kapt4 flag can be only used with language version 2.0+."
)
}
}
fun CompilerConfiguration.setupLanguageVersionSettings(arguments: CommonCompilerArguments) {
languageVersionSettings = arguments.toLanguageVersionSettings(getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY))
}