Scripting: switch default definition to new scheme
also correctly pass externaly provided configuration on compilation and evaluation. Fixes REPL evaluation with dependencies passed via compilation classpath.
This commit is contained in:
+2
-2
@@ -104,7 +104,7 @@ open class KJvmReplCompilerBase<AnalyzerT : ReplCodeAnalyzerBase>(
|
||||
// executing it on every snippet needs to be evaluated first
|
||||
if (state.history.isEmpty()) {
|
||||
val updatedConfiguration = ScriptDependenciesProvider.getInstance(context.environment.project)
|
||||
?.getScriptConfiguration(snippetKtFile)?.configuration
|
||||
?.getScriptConfigurationResult(snippetKtFile, context.baseScriptCompilationConfiguration)?.valueOrNull()?.configuration
|
||||
?: context.baseScriptCompilationConfiguration
|
||||
registerPackageFragmentProvidersIfNeeded(
|
||||
updatedConfiguration,
|
||||
@@ -166,7 +166,7 @@ open class KJvmReplCompilerBase<AnalyzerT : ReplCodeAnalyzerBase>(
|
||||
sourceFiles.first(),
|
||||
sourceDependencies
|
||||
) { ktFile ->
|
||||
dependenciesProvider?.getScriptConfiguration(ktFile)?.configuration
|
||||
dependenciesProvider?.getScriptConfigurationResult(ktFile, context.baseScriptCompilationConfiguration)?.valueOrNull()?.configuration
|
||||
?: context.baseScriptCompilationConfiguration
|
||||
}.onSuccess { compiledScript ->
|
||||
|
||||
|
||||
+17
-15
@@ -135,23 +135,25 @@ private fun compileImpl(
|
||||
|
||||
val dependenciesProvider = ScriptDependenciesProvider.getInstance(context.environment.project)
|
||||
val getScriptConfiguration = { ktFile: KtFile ->
|
||||
(dependenciesProvider?.getScriptConfiguration(ktFile)?.configuration ?: context.baseScriptCompilationConfiguration)
|
||||
.with {
|
||||
// Adjust definitions so all compiler dependencies are saved in the resulting compilation configuration, so evaluation
|
||||
// performed with the expected classpath
|
||||
// TODO: make this logic obsolete by injecting classpath earlier in the pipeline
|
||||
val depsFromConfiguration = get(dependencies)?.flatMapTo(HashSet()) { (it as? JvmDependency)?.classpath ?: emptyList() }
|
||||
val depsFromCompiler = context.environment.configuration.getList(CLIConfigurationKeys.CONTENT_ROOTS)
|
||||
.mapNotNull { if (it is JvmClasspathRoot && !it.isSdkRoot) it.file else null }
|
||||
if (!depsFromConfiguration.isNullOrEmpty()) {
|
||||
val missingDeps = depsFromCompiler.filter { !depsFromConfiguration.contains(it) }
|
||||
if (missingDeps.isNotEmpty()) {
|
||||
dependencies.append(JvmDependency(missingDeps))
|
||||
}
|
||||
} else {
|
||||
dependencies.append(JvmDependency(depsFromCompiler))
|
||||
val refinedConfiguration =
|
||||
dependenciesProvider?.getScriptConfigurationResult(ktFile, context.baseScriptCompilationConfiguration)
|
||||
?.valueOrNull()?.configuration ?: context.baseScriptCompilationConfiguration
|
||||
refinedConfiguration.with {
|
||||
// Adjust definitions so all compiler dependencies are saved in the resulting compilation configuration, so evaluation
|
||||
// performed with the expected classpath
|
||||
// TODO: make this logic obsolete by injecting classpath earlier in the pipeline
|
||||
val depsFromConfiguration = get(dependencies)?.flatMapTo(HashSet()) { (it as? JvmDependency)?.classpath ?: emptyList() }
|
||||
val depsFromCompiler = context.environment.configuration.getList(CLIConfigurationKeys.CONTENT_ROOTS)
|
||||
.mapNotNull { if (it is JvmClasspathRoot && !it.isSdkRoot) it.file else null }
|
||||
if (!depsFromConfiguration.isNullOrEmpty()) {
|
||||
val missingDeps = depsFromCompiler.filter { !depsFromConfiguration.contains(it) }
|
||||
if (missingDeps.isNotEmpty()) {
|
||||
dependencies.append(JvmDependency(missingDeps))
|
||||
}
|
||||
} else {
|
||||
dependencies.append(JvmDependency(depsFromCompiler))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return doCompile(context, script, sourceFiles, sourceDependencies, messageCollector, getScriptConfiguration)
|
||||
|
||||
Reference in New Issue
Block a user