Fix custom script definition cashing and script validity check:
- reorder initialization logic, so that script definitions are requested only after plugins loading - clear definitions cache after adding explicit definitions or sources #KT-32206 fixed #KT-32169 fixed Note: any of these modification fix the problem alone, but the second may prevent other similar problems, while the first fixes actual logic of the script validity checks as well.
This commit is contained in:
+6
-5
@@ -40,6 +40,12 @@ class JvmCliScriptEvaluationExtension : ScriptEvaluationExtension {
|
||||
return COMPILATION_ERROR
|
||||
}
|
||||
val sourcePath = arguments.freeArgs.first()
|
||||
|
||||
configuration.addKotlinSourceRoot(sourcePath)
|
||||
configuration.put(JVMConfigurationKeys.RETAIN_OUTPUT_IN_MEMORY, true)
|
||||
val coreEnvironment =
|
||||
KotlinCoreEnvironment.createForProduction(projectEnvironment, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
||||
|
||||
val scriptFile = File(sourcePath)
|
||||
if (scriptFile.isDirectory || !scriptDefinitionProvider.isScript(scriptFile.name)) {
|
||||
val extensionHint =
|
||||
@@ -48,14 +54,9 @@ class JvmCliScriptEvaluationExtension : ScriptEvaluationExtension {
|
||||
messageCollector.report(ERROR, "Specify path to the script file$extensionHint as the first argument")
|
||||
return COMPILATION_ERROR
|
||||
}
|
||||
configuration.addKotlinSourceRoot(sourcePath)
|
||||
configuration.put(JVMConfigurationKeys.RETAIN_OUTPUT_IN_MEMORY, true)
|
||||
|
||||
val scriptArgs = arguments.freeArgs.subList(1, arguments.freeArgs.size)
|
||||
|
||||
val coreEnvironment =
|
||||
KotlinCoreEnvironment.createForProduction(projectEnvironment, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
||||
|
||||
return KotlinToJVMBytecodeCompiler.compileAndExecuteScript(coreEnvironment, scriptArgs)
|
||||
}
|
||||
}
|
||||
+2
@@ -28,6 +28,7 @@ open class CliScriptDefinitionProvider : LazyScriptDefinitionProvider() {
|
||||
definitions.addAll(withoutStdDef)
|
||||
// TODO: consider reporting an error when several default definitions are supplied
|
||||
defaultDefinition = stdDef.firstOrNull()
|
||||
clearCache()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +38,7 @@ open class CliScriptDefinitionProvider : LazyScriptDefinitionProvider() {
|
||||
for (it in newSources) {
|
||||
definitionsFromSources.add(it.definitions.constrainOnce())
|
||||
}
|
||||
clearCache()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user