From 1a373317ed9b9e0f2d06c2faa8490f07172f85fd Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Tue, 20 Dec 2022 16:33:20 +0100 Subject: [PATCH] K2: temporarily disable scripts compilation in LT mode Should be addressed in the new K2 scripting support soon --- .../jvm/compiler/pipeline/compilerPipeline.kt | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/pipeline/compilerPipeline.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/pipeline/compilerPipeline.kt index 9cc77dd434f..b60aaa6e682 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/pipeline/compilerPipeline.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/pipeline/compilerPipeline.kt @@ -62,6 +62,7 @@ import org.jetbrains.kotlin.fir.session.FirSessionFactoryHelper import org.jetbrains.kotlin.fir.session.IncrementalCompilationContext import org.jetbrains.kotlin.fir.session.environment.AbstractProjectEnvironment import org.jetbrains.kotlin.fir.session.environment.AbstractProjectFileSearchScope +import org.jetbrains.kotlin.idea.KotlinFileType import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmIrMangler import org.jetbrains.kotlin.javac.JavacWrapper import org.jetbrains.kotlin.load.kotlin.MetadataFinderFactory @@ -83,6 +84,9 @@ import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformAnalyzerServices import org.jetbrains.kotlin.utils.addToStdlib.runIf import java.io.File +private const val kotlinFileExtensionWithDot = ".${KotlinFileType.EXTENSION}" +private const val javaFileExtensionWithDot = ".${JavaFileType.DEFAULT_EXTENSION}" + fun compileModulesUsingFrontendIrAndLightTree( projectEnvironment: AbstractProjectEnvironment, compilerConfiguration: CompilerConfiguration, @@ -114,10 +118,33 @@ fun compileModulesUsingFrontendIrAndLightTree( val commonSources = linkedSetOf() // !! + + // TODO: the scripts checking should be part of the scripting plugin functionality, as it is implemented now in ScriptingProcessSourcesBeforeCompilingExtension + // TODO: implement in the next round of K2 scripting support + val skipScriptsInLtMode = compilerConfiguration.getBoolean(CommonConfigurationKeys.USE_FIR) && compilerConfiguration.getBoolean(CommonConfigurationKeys.USE_LIGHT_TREE) + var skipScriptsInLtModeWarning = false + compilerConfiguration.kotlinSourceRoots.forAllFiles(compilerConfiguration, projectEnvironment.project) { virtualFile, isCommon -> val file = KtVirtualFileSourceFile(virtualFile) - if (isCommon) commonSources.add(file) - else platformSources.add(file) + when { + file.path.endsWith(javaFileExtensionWithDot) -> {} + file.path.endsWith(kotlinFileExtensionWithDot) || !skipScriptsInLtMode -> { + if (isCommon) commonSources.add(file) + else platformSources.add(file) + } + else -> { + // temporarily assume it is a script, see the TODO above + skipScriptsInLtModeWarning = true + } + } + } + + if (skipScriptsInLtModeWarning) { + // TODO: remove then Scripts are supported in LT (probably different K2 extension should be written for handling the case properly) + messageCollector.report( + CompilerMessageSeverity.STRONG_WARNING, + "Scripts are not yet supported with K2 in LightTree mode, consider using K1 or disable LightTree mode with -XuseFirLT=false" + ) } val renderDiagnosticName = moduleConfiguration.getBoolean(CLIConfigurationKeys.RENDER_DIAGNOSTIC_INTERNAL_NAME)