[FE] Move utility of parsing plugin options to :compiler:frontend.common
This is needed to be able to use this utility inside FIR part of IDE plugin
This commit is contained in:
committed by
teamcity
parent
f587c02d38
commit
65e240679e
@@ -146,6 +146,7 @@ val commonCompilerModules = arrayOf(
|
|||||||
":compiler:frontend.common",
|
":compiler:frontend.common",
|
||||||
":compiler:util",
|
":compiler:util",
|
||||||
":compiler:config.jvm",
|
":compiler:config.jvm",
|
||||||
|
":compiler:cli-common",
|
||||||
":compiler:resolution.common",
|
":compiler:resolution.common",
|
||||||
":compiler:resolution.common.jvm",
|
":compiler:resolution.common.jvm",
|
||||||
":core:metadata",
|
":core:metadata",
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ dependencies {
|
|||||||
api(project(":compiler:config.jvm"))
|
api(project(":compiler:config.jvm"))
|
||||||
api(project(":js:js.config"))
|
api(project(":js:js.config"))
|
||||||
api(project(":native:kotlin-native-utils"))
|
api(project(":native:kotlin-native-utils"))
|
||||||
|
api(project(":compiler:plugin-api"))
|
||||||
compileOnly(project(":kotlin-reflect-api"))
|
compileOnly(project(":kotlin-reflect-api"))
|
||||||
compileOnly(intellijCore())
|
compileOnly(intellijCore())
|
||||||
compileOnly(commonDependency("com.google.guava:guava"))
|
compileOnly(commonDependency("com.google.guava:guava"))
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* 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.cli.plugins
|
||||||
|
|
||||||
|
import com.intellij.util.containers.MultiMap
|
||||||
|
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||||
|
import org.jetbrains.kotlin.compiler.plugin.*
|
||||||
|
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||||
|
|
||||||
|
fun processCompilerPluginsOptions(
|
||||||
|
configuration: CompilerConfiguration,
|
||||||
|
pluginOptions: Iterable<String>?,
|
||||||
|
commandLineProcessors: List<CommandLineProcessor>
|
||||||
|
) {
|
||||||
|
val optionValuesByPlugin = pluginOptions?.map(::parsePluginOption)?.groupBy {
|
||||||
|
if (it == null) throw CliOptionProcessingException("Wrong plugin option format: $it, should be ${CommonCompilerArguments.PLUGIN_OPTION_FORMAT}")
|
||||||
|
it.pluginId
|
||||||
|
} ?: mapOf()
|
||||||
|
|
||||||
|
for (processor in commandLineProcessors) {
|
||||||
|
val declaredOptions = processor.pluginOptions.associateBy { it.optionName }
|
||||||
|
val optionsToValues = MultiMap<AbstractCliOption, CliOptionValue>()
|
||||||
|
|
||||||
|
for (optionValue in optionValuesByPlugin[processor.pluginId].orEmpty()) {
|
||||||
|
val option = declaredOptions[optionValue!!.optionName]
|
||||||
|
?: throw CliOptionProcessingException("Unsupported plugin option: $optionValue")
|
||||||
|
optionsToValues.putValue(option, optionValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
for (option in processor.pluginOptions) {
|
||||||
|
val values = optionsToValues[option]
|
||||||
|
if (option.required && values.isEmpty()) {
|
||||||
|
throw PluginCliOptionProcessingException(
|
||||||
|
processor.pluginId,
|
||||||
|
processor.pluginOptions,
|
||||||
|
"Required plugin option not present: ${processor.pluginId}:${option.optionName}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (!option.allowMultipleOccurrences && values.size > 1) {
|
||||||
|
throw PluginCliOptionProcessingException(
|
||||||
|
processor.pluginId,
|
||||||
|
processor.pluginOptions,
|
||||||
|
"Multiple values are not allowed for plugin option ${processor.pluginId}:${option.optionName}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
for (value in values) {
|
||||||
|
processor.processOption(option, value.value, configuration)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR
|
|||||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.INFO
|
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.INFO
|
||||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.LOGGING
|
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.LOGGING
|
||||||
import org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser
|
import org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser
|
||||||
import org.jetbrains.kotlin.cli.jvm.plugins.processCompilerPluginsOptions
|
import org.jetbrains.kotlin.cli.plugins.processCompilerPluginsOptions
|
||||||
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
|
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
|
||||||
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
|
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
|
||||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||||
|
|||||||
@@ -16,12 +16,11 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.cli.jvm.plugins
|
package org.jetbrains.kotlin.cli.jvm.plugins
|
||||||
|
|
||||||
import com.intellij.util.containers.MultiMap
|
|
||||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
|
||||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollectorUtil
|
import org.jetbrains.kotlin.cli.common.messages.MessageCollectorUtil
|
||||||
|
import org.jetbrains.kotlin.cli.plugins.processCompilerPluginsOptions
|
||||||
import org.jetbrains.kotlin.compiler.plugin.*
|
import org.jetbrains.kotlin.compiler.plugin.*
|
||||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||||
import org.jetbrains.kotlin.util.ServiceLoaderLite
|
import org.jetbrains.kotlin.util.ServiceLoaderLite
|
||||||
@@ -88,47 +87,3 @@ object PluginCliParser {
|
|||||||
processCompilerPluginsOptions(configuration, pluginOptions, commandLineProcessors)
|
processCompilerPluginsOptions(configuration, pluginOptions, commandLineProcessors)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun processCompilerPluginsOptions(
|
|
||||||
configuration: CompilerConfiguration,
|
|
||||||
pluginOptions: Iterable<String>?,
|
|
||||||
commandLineProcessors: List<CommandLineProcessor>
|
|
||||||
) {
|
|
||||||
val optionValuesByPlugin = pluginOptions?.map(::parsePluginOption)?.groupBy {
|
|
||||||
if (it == null) throw CliOptionProcessingException("Wrong plugin option format: $it, should be ${CommonCompilerArguments.PLUGIN_OPTION_FORMAT}")
|
|
||||||
it.pluginId
|
|
||||||
} ?: mapOf()
|
|
||||||
|
|
||||||
for (processor in commandLineProcessors) {
|
|
||||||
val declaredOptions = processor.pluginOptions.associateBy { it.optionName }
|
|
||||||
val optionsToValues = MultiMap<AbstractCliOption, CliOptionValue>()
|
|
||||||
|
|
||||||
for (optionValue in optionValuesByPlugin[processor.pluginId].orEmpty()) {
|
|
||||||
val option = declaredOptions[optionValue!!.optionName]
|
|
||||||
?: throw CliOptionProcessingException("Unsupported plugin option: $optionValue")
|
|
||||||
optionsToValues.putValue(option, optionValue)
|
|
||||||
}
|
|
||||||
|
|
||||||
for (option in processor.pluginOptions) {
|
|
||||||
val values = optionsToValues[option]
|
|
||||||
if (option.required && values.isEmpty()) {
|
|
||||||
throw PluginCliOptionProcessingException(
|
|
||||||
processor.pluginId,
|
|
||||||
processor.pluginOptions,
|
|
||||||
"Required plugin option not present: ${processor.pluginId}:${option.optionName}"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (!option.allowMultipleOccurrences && values.size > 1) {
|
|
||||||
throw PluginCliOptionProcessingException(
|
|
||||||
processor.pluginId,
|
|
||||||
processor.pluginOptions,
|
|
||||||
"Multiple values are not allowed for plugin option ${processor.pluginId}:${option.optionName}"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
for (value in values) {
|
|
||||||
processor.processOption(option, value.value, configuration)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@
|
|||||||
package org.jetbrains.kotlin.scripting.compiler.plugin.impl
|
package org.jetbrains.kotlin.scripting.compiler.plugin.impl
|
||||||
|
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
||||||
import org.jetbrains.kotlin.cli.jvm.plugins.processCompilerPluginsOptions
|
import org.jetbrains.kotlin.cli.plugins.processCompilerPluginsOptions
|
||||||
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
|
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
|
||||||
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
|
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
|
||||||
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
|
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
|
||||||
|
|||||||
Reference in New Issue
Block a user