Changes in the compiler needed to run KAPT 4 (KT-51982)
This commit is contained in:
committed by
Space Team
parent
dac8688a29
commit
84bf411cc3
@@ -77,9 +77,7 @@ private fun switchToFallbackModeIfNecessary(arguments: CommonCompilerArguments,
|
||||
arguments.skipPrereleaseCheck = true
|
||||
arguments.allowUnstableDependencies = true
|
||||
}
|
||||
isK2 && isKaptUsed && arguments.useKapt4 -> warn("Kapt 4 is still experimental. Use with caution.")
|
||||
arguments.useKapt4 && !isK2 -> warn("-Xuse-kapt4 flag can be only used with language version 2.0+.")
|
||||
arguments.useKapt4 && !isKaptUsed -> warn("-Xuse-kapt4 flag is present but no Kapt configuration options are provided.")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
val targetDescription = chunk.map { input -> input.getModuleName() + "-" + input.getModuleType() }.let { names ->
|
||||
names.singleOrNull() ?: names.joinToString()
|
||||
}
|
||||
if (configuration.getBoolean(CommonConfigurationKeys.USE_FIR) && configuration.getBoolean(CommonConfigurationKeys.USE_LIGHT_TREE)) {
|
||||
if (configuration.getBoolean(CommonConfigurationKeys.USE_FIR) && configuration.getBoolean(CommonConfigurationKeys.USE_LIGHT_TREE)) {
|
||||
val projectEnvironment =
|
||||
createProjectEnvironment(configuration, rootDisposable, EnvironmentConfigFiles.JVM_CONFIG_FILES, messageCollector)
|
||||
|
||||
|
||||
+5
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.fir.backend.*
|
||||
import org.jetbrains.kotlin.fir.backend.jvm.*
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
||||
import org.jetbrains.kotlin.fir.extensions.FirAnalysisHandlerExtension
|
||||
import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrar
|
||||
import org.jetbrains.kotlin.fir.pipeline.*
|
||||
import org.jetbrains.kotlin.fir.session.*
|
||||
@@ -90,6 +91,10 @@ object FirKotlinToJvmBytecodeCompiler {
|
||||
|
||||
// TODO: run lowerings for all modules in the chunk, then run codegen for all modules.
|
||||
val project = (projectEnvironment as? VfsBasedProjectEnvironment)?.project
|
||||
if (project != null) {
|
||||
FirAnalysisHandlerExtension.analyze(project, projectConfiguration)?.let { return it }
|
||||
}
|
||||
|
||||
for (module in chunk) {
|
||||
val moduleConfiguration = projectConfiguration.applyModuleProperties(module, buildFile)
|
||||
val context = CompilationContext(
|
||||
|
||||
@@ -47,6 +47,7 @@ import org.jetbrains.kotlin.fir.backend.Fir2IrConfiguration
|
||||
import org.jetbrains.kotlin.fir.backend.jvm.FirJvmBackendClassResolver
|
||||
import org.jetbrains.kotlin.fir.backend.jvm.FirJvmBackendExtension
|
||||
import org.jetbrains.kotlin.fir.backend.jvm.JvmFir2IrExtensions
|
||||
import org.jetbrains.kotlin.fir.extensions.FirAnalysisHandlerExtension
|
||||
import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrar
|
||||
import org.jetbrains.kotlin.fir.pipeline.FirResult
|
||||
import org.jetbrains.kotlin.fir.pipeline.buildResolveAndCheckFirViaLightTree
|
||||
@@ -87,6 +88,9 @@ fun compileModulesUsingFrontendIrAndLightTree(
|
||||
|
||||
performanceManager?.notifyCompilerInitialized(0, 0, targetDescription)
|
||||
|
||||
val project = projectEnvironment.project
|
||||
FirAnalysisHandlerExtension.analyze(project, compilerConfiguration)?.let { return it }
|
||||
|
||||
val outputs = mutableListOf<GenerationState>()
|
||||
var mainClassFqName: FqName? = null
|
||||
|
||||
@@ -509,7 +513,7 @@ private fun VirtualFileSystem.findJarRoot(file: File): VirtualFile? =
|
||||
findFileByPath("$file${URLUtil.JAR_SEPARATOR}")
|
||||
|
||||
private fun VirtualFileSystem.findExistingRoot(
|
||||
root: JvmContentRoot, rootDescription: String, messageCollector: MessageCollector
|
||||
root: JvmContentRoot, rootDescription: String, messageCollector: MessageCollector,
|
||||
): VirtualFile? {
|
||||
return findFileByPath(root.file.absolutePath).also {
|
||||
if (it == null) {
|
||||
|
||||
+19
-2
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.extensions
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor
|
||||
|
||||
@@ -13,7 +14,22 @@ abstract class FirAnalysisHandlerExtension {
|
||||
companion object : ProjectExtensionDescriptor<FirAnalysisHandlerExtension>(
|
||||
"org.jetbrains.kotlin.fir.firAnalyzeCompleteHandlerExtension",
|
||||
FirAnalysisHandlerExtension::class.java
|
||||
)
|
||||
) {
|
||||
/**
|
||||
* Applies [FirAnalysisHandlerExtension] instances to a project
|
||||
* @receiver the project to analyze
|
||||
* @param configuration compiler configuration
|
||||
* @return [null] if no applicable extensions were found, [true] if all applicable extensions returned [true] from [doAnalysis],
|
||||
* [false] if any applicable extension returned [false]
|
||||
*
|
||||
* @see FirAnalysisHandlerExtension.isApplicable
|
||||
* @see FirAnalysisHandlerExtension.doAnalysis
|
||||
*/
|
||||
fun analyze(project: Project, configuration: CompilerConfiguration): Boolean? {
|
||||
val extensions = FirAnalysisHandlerExtension.getInstances(project).filter { it.isApplicable(configuration) }
|
||||
return if (extensions.isEmpty()) null else extensions.all { it.doAnalysis(configuration) }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether [doAnalysis] should be called
|
||||
@@ -25,7 +41,8 @@ abstract class FirAnalysisHandlerExtension {
|
||||
/**
|
||||
* Performs code analysis
|
||||
* @param configuration compiler configuration
|
||||
* @return true if analysis completed successfully. There can be different causes of failure, an incorrect configuration for example.
|
||||
* @return [true] if analysis completed successfully, [false] otherwise.
|
||||
* There can be different causes of failure, an incorrect configuration for example.
|
||||
* A failure means that there's no reason to continue building the project.
|
||||
*/
|
||||
abstract fun doAnalysis(configuration: CompilerConfiguration): Boolean
|
||||
|
||||
Reference in New Issue
Block a user