Scripting: support compiler plugins in hosted script compiler
Now the plugin-related compiler arguments are respected then used in the compiler configuration (only in the static part, not supported if set in a refinement callback) Note that the "embeddable" version of the plugin should be used if embeddable compiler is used. #KT-54095 fixed
This commit is contained in:
+18
-7
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
import org.jetbrains.kotlin.cli.common.reportArgumentParseProblems
|
||||
import org.jetbrains.kotlin.cli.common.setupCommonArguments
|
||||
import org.jetbrains.kotlin.cli.common.checkPluginsArguments
|
||||
import org.jetbrains.kotlin.cli.jvm.*
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
@@ -23,6 +24,7 @@ import org.jetbrains.kotlin.cli.jvm.config.JvmClasspathRoot
|
||||
import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoots
|
||||
import org.jetbrains.kotlin.cli.jvm.config.configureJdkClasspathRoots
|
||||
import org.jetbrains.kotlin.cli.jvm.config.jvmClasspathRoots
|
||||
import org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser
|
||||
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
|
||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
@@ -199,13 +201,6 @@ internal fun createInitialConfigurations(
|
||||
val initialScriptCompilationConfiguration =
|
||||
scriptCompilationConfiguration.withUpdatesFromCompilerConfiguration(kotlinCompilerConfiguration)
|
||||
|
||||
kotlinCompilerConfiguration.add(
|
||||
ScriptingConfigurationKeys.SCRIPT_DEFINITIONS,
|
||||
ScriptDefinition.FromConfigurations(hostConfiguration, scriptCompilationConfiguration, null)
|
||||
)
|
||||
|
||||
kotlinCompilerConfiguration.loadPlugins()
|
||||
|
||||
initialScriptCompilationConfiguration[ScriptCompilationConfiguration.compilerOptions]?.let { compilerOptions ->
|
||||
kotlinCompilerConfiguration.updateWithCompilerOptions(compilerOptions, messageCollector, ignoredOptionsReportingState, false)
|
||||
}
|
||||
@@ -339,6 +334,22 @@ private fun createInitialCompilerConfiguration(
|
||||
configureJdkClasspathRoots()
|
||||
|
||||
put(JVMConfigurationKeys.USE_FAST_JAR_FILE_SYSTEM, true)
|
||||
|
||||
add(
|
||||
ScriptingConfigurationKeys.SCRIPT_DEFINITIONS,
|
||||
ScriptDefinition.FromConfigurations(hostConfiguration, scriptCompilationConfiguration, null)
|
||||
)
|
||||
|
||||
val pluginClasspaths = baseArguments.pluginClasspaths?.asList().orEmpty()
|
||||
val pluginOptions = baseArguments.pluginOptions?.asList().orEmpty()
|
||||
val pluginConfigurations = baseArguments.pluginConfigurations.orEmpty().toMutableList()
|
||||
|
||||
checkPluginsArguments(messageCollector, false, pluginClasspaths, pluginOptions, pluginConfigurations)
|
||||
if (pluginClasspaths.isNotEmpty() || pluginConfigurations.isNotEmpty()) {
|
||||
PluginCliParser.loadPluginsSafe(pluginClasspaths, pluginOptions, pluginConfigurations, this)
|
||||
} else {
|
||||
loadPlugins()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -160,7 +160,6 @@ internal fun reportArgumentsIgnoredGenerally(
|
||||
K2JVMCompilerArguments::disableStandardScript,
|
||||
K2JVMCompilerArguments::defaultScriptExtension,
|
||||
K2JVMCompilerArguments::disableDefaultScriptingPlugin,
|
||||
K2JVMCompilerArguments::pluginClasspaths,
|
||||
K2JVMCompilerArguments::useJavac,
|
||||
K2JVMCompilerArguments::compileJava,
|
||||
K2JVMCompilerArguments::reportPerf,
|
||||
@@ -181,7 +180,10 @@ internal fun reportArgumentsIgnoredFromRefinement(
|
||||
K2JVMCompilerArguments::javaModulePath,
|
||||
K2JVMCompilerArguments::classpath,
|
||||
K2JVMCompilerArguments::noStdlib,
|
||||
K2JVMCompilerArguments::noReflect
|
||||
K2JVMCompilerArguments::noReflect,
|
||||
K2JVMCompilerArguments::pluginClasspaths,
|
||||
K2JVMCompilerArguments::pluginOptions,
|
||||
K2JVMCompilerArguments::pluginConfigurations,
|
||||
)
|
||||
|
||||
|
||||
|
||||
+1
-2
@@ -30,8 +30,7 @@ private val scriptCompilationDisabledCommandlineProcessors =
|
||||
ScriptingCommandLineProcessor::class.java.name
|
||||
)
|
||||
|
||||
internal fun CompilerConfiguration.loadPlugins() {
|
||||
val classLoader = CompilerConfiguration::class.java.classLoader
|
||||
internal fun CompilerConfiguration.loadPlugins(classLoader: ClassLoader = CompilerConfiguration::class.java.classLoader) {
|
||||
val registrars =
|
||||
classLoader.loadServices<ComponentRegistrar>(scriptCompilationDisabledPlugins, SCRIPT_COMPILATION_DISABLE_PLUGINS_PROPERTY)
|
||||
addAll(ComponentRegistrar.PLUGIN_COMPONENT_REGISTRARS, registrars)
|
||||
|
||||
Reference in New Issue
Block a user