Scripting: update scripts in source roots handling
#KT-52525 fixed related to #KT-52735
This commit is contained in:
+7
@@ -415,6 +415,9 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
|
||||
@Argument(value = "-Xrender-internal-diagnostic-names", description = "Render internal names of warnings and errors")
|
||||
var renderInternalDiagnosticNames: Boolean by FreezableVar(false)
|
||||
|
||||
@Argument(value = "-Xallow-any-scripts-in-source-roots", description = "Allow to compile any scripts along with regular Kotlin sources")
|
||||
var allowAnyScriptsInSourceRoots: Boolean by FreezableVar(false)
|
||||
|
||||
@OptIn(IDEAPluginsCompatibilityAPI::class)
|
||||
open fun configureAnalysisFlags(collector: MessageCollector, languageVersion: LanguageVersion): MutableMap<AnalysisFlag<*>, Any> {
|
||||
return HashMap<AnalysisFlag<*>, Any>().apply {
|
||||
@@ -508,6 +511,10 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
|
||||
}
|
||||
}
|
||||
|
||||
if (allowAnyScriptsInSourceRoots) {
|
||||
put(LanguageFeature.SkipStandaloneScriptsInSourceRoots, LanguageFeature.State.DISABLED)
|
||||
}
|
||||
|
||||
// Internal arguments should go last, because it may be useful to override
|
||||
// some feature state via -XX (even if some -X flags were passed)
|
||||
if (internalArguments.isNotEmpty()) {
|
||||
|
||||
@@ -28,6 +28,7 @@ fun <A : CommonCompilerArguments> CompilerConfiguration.setupCommonArguments(
|
||||
putIfNotNull(CLIConfigurationKeys.INTELLIJ_PLUGIN_ROOT, arguments.intellijPluginRoot)
|
||||
put(CommonConfigurationKeys.REPORT_OUTPUT_FILES, arguments.reportOutputFiles)
|
||||
put(CommonConfigurationKeys.INCREMENTAL_COMPILATION, incrementalCompilationIsEnabled(arguments))
|
||||
put(CommonConfigurationKeys.ALLOW_ANY_SCRIPTS_IN_SOURCE_ROOTS, arguments.allowAnyScriptsInSourceRoots)
|
||||
|
||||
val metadataVersionString = arguments.metadataVersion
|
||||
if (metadataVersionString != null) {
|
||||
|
||||
@@ -637,6 +637,7 @@ class KotlinCoreEnvironment private constructor(
|
||||
JsSyntheticTranslateExtension.registerExtensionPoint(project)
|
||||
CompilerConfigurationExtension.registerExtensionPoint(project)
|
||||
CollectAdditionalSourcesExtension.registerExtensionPoint(project)
|
||||
ProcessSourcesBeforeCompilingExtension.registerExtensionPoint(project)
|
||||
ExtraImportsProviderExtension.registerExtensionPoint(project)
|
||||
IrGenerationExtension.registerExtensionPoint(project)
|
||||
ScriptEvaluationExtension.registerExtensionPoint(project)
|
||||
|
||||
+6
-5
@@ -37,12 +37,10 @@ import org.jetbrains.kotlin.codegen.ClassBuilderFactories
|
||||
import org.jetbrains.kotlin.codegen.CodegenFactory
|
||||
import org.jetbrains.kotlin.codegen.DefaultCodegenFactory
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
||||
import org.jetbrains.kotlin.config.languageVersionSettings
|
||||
import org.jetbrains.kotlin.config.*
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporterFactory
|
||||
import org.jetbrains.kotlin.diagnostics.impl.BaseDiagnosticsCollector
|
||||
import org.jetbrains.kotlin.extensions.ProcessSourcesBeforeCompilingExtension
|
||||
import org.jetbrains.kotlin.ir.backend.jvm.jvmResolveLibraries
|
||||
import org.jetbrains.kotlin.load.kotlin.ModuleVisibilityManager
|
||||
import org.jetbrains.kotlin.modules.Module
|
||||
@@ -236,8 +234,11 @@ object KotlinToJVMBytecodeCompiler {
|
||||
}
|
||||
|
||||
fun analyze(environment: KotlinCoreEnvironment): AnalysisResult? {
|
||||
val sourceFiles = environment.getSourceFiles()
|
||||
val collector = environment.messageCollector
|
||||
val sourceFiles = ProcessSourcesBeforeCompilingExtension.getInstances(environment.project)
|
||||
.fold(environment.getSourceFiles() as Collection<KtFile>) { files, extension ->
|
||||
extension.processSources(files, environment.configuration)
|
||||
}
|
||||
|
||||
// Can be null for Scripts/REPL
|
||||
val performanceManager = environment.configuration.get(CLIConfigurationKeys.PERF_MANAGER)
|
||||
|
||||
@@ -74,6 +74,10 @@ object CommonConfigurationKeys {
|
||||
@JvmField
|
||||
val INCREMENTAL_COMPILATION =
|
||||
CompilerConfigurationKey.create<Boolean>("Enable incremental compilation")
|
||||
|
||||
@JvmField
|
||||
val ALLOW_ANY_SCRIPTS_IN_SOURCE_ROOTS =
|
||||
CompilerConfigurationKey.create<Boolean>("Allow to compile any scripts along with regular Kotlin sources")
|
||||
}
|
||||
|
||||
var CompilerConfiguration.languageVersionSettings: LanguageVersionSettings
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.extensions
|
||||
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
interface ProcessSourcesBeforeCompilingExtension {
|
||||
|
||||
companion object : ProjectExtensionDescriptor<ProcessSourcesBeforeCompilingExtension>(
|
||||
"org.jetbrains.kotlin.processSourcesBeforeCompilingExtension",
|
||||
ProcessSourcesBeforeCompilingExtension::class.java
|
||||
)
|
||||
|
||||
fun processSources(
|
||||
sources: Collection<KtFile>,
|
||||
configuration: CompilerConfiguration
|
||||
): Collection<KtFile>
|
||||
}
|
||||
+2
@@ -45,6 +45,8 @@ where advanced options include:
|
||||
Turn on range checks for the array access functions
|
||||
-Xwasm-enable-asserts Turn on asserts
|
||||
-Xwasm-kclass-fqn Enable support for FQ names in KClass
|
||||
-Xallow-any-scripts-in-source-roots
|
||||
Allow to compile any scripts along with regular Kotlin sources
|
||||
-Xallow-kotlin-package Allow compiling code in package 'kotlin' and allow not requiring kotlin.stdlib in module-info
|
||||
-Xallow-result-return-type Allow compiling code when `kotlin.Result` is used as a return type
|
||||
-Xbuiltins-from-sources Compile builtIns from sources
|
||||
|
||||
+2
@@ -150,6 +150,8 @@ where advanced options include:
|
||||
-Xuse-type-table Use type table in metadata serialization
|
||||
-Xvalidate-bytecode Validate generated JVM bytecode before and after optimizations
|
||||
-Xvalidate-ir Validate IR before and after lowering
|
||||
-Xallow-any-scripts-in-source-roots
|
||||
Allow to compile any scripts along with regular Kotlin sources
|
||||
-Xallow-kotlin-package Allow compiling code in package 'kotlin' and allow not requiring kotlin.stdlib in module-info
|
||||
-Xallow-result-return-type Allow compiling code when `kotlin.Result` is used as a return type
|
||||
-Xbuiltins-from-sources Compile builtIns from sources
|
||||
|
||||
@@ -299,7 +299,7 @@ println(42)
|
||||
expectedStderr = "error: unrecognized script type: noInline.myscript; Specify path to the script file as the first argument\n"
|
||||
)
|
||||
runProcess(
|
||||
"kotlin", "-howtorun", ".kts", "$testDataDirectory/noInline.myscript",
|
||||
"kotlin", "-Xallow-any-scripts-in-source-roots", "-howtorun", ".kts", "$testDataDirectory/noInline.myscript",
|
||||
expectedExitCode = 1, expectedStderr = """error: unresolved reference: CompilerOptions (noInline.myscript:1:7)
|
||||
compiler/testData/launcher/noInline.myscript:1:7: error: unresolved reference: CompilerOptions
|
||||
@file:CompilerOptions("-Xno-inline")
|
||||
|
||||
@@ -172,7 +172,7 @@ public class CompilerSmokeTest extends CompilerSmokeTestBase {
|
||||
public void testCompileScript() throws Exception {
|
||||
String jar = tmpdir.getAbsolutePath() + File.separator + "script.jar";
|
||||
|
||||
runCompiler("script", "script.kts", "-d", jar);
|
||||
runCompiler("script", "-Xallow-any-scripts-in-source-roots", "script.kts", "-d", jar);
|
||||
}
|
||||
|
||||
public void testInlineOnly() throws Exception {
|
||||
|
||||
@@ -278,6 +278,7 @@ enum class LanguageFeature(
|
||||
ForbidInferringTypeVariablesIntoEmptyIntersection(KOTLIN_1_9, kind = BUG_FIX), // KT-51221
|
||||
ForbidExtensionCallsOnInlineFunctionalParameters(KOTLIN_1_9, kind = BUG_FIX), // KT-52502
|
||||
ForbidInferringPostponedTypeVariableIntoDeclaredUpperBound(KOTLIN_1_9, kind = BUG_FIX), // KT-47986
|
||||
SkipStandaloneScriptsInSourceRoots(KOTLIN_1_9, kind = OTHER), // KT-52525
|
||||
|
||||
// Disabled for indefinite time. See KT-48535 and related discussion
|
||||
ApproximateIntegerLiteralTypesInReceiverPosition(sinceVersion = null),
|
||||
|
||||
Reference in New Issue
Block a user