[Commonizer] move commonizer setting keys to the commonizer-cli module
Get rid of `OptionAlias` as unnecessary; keys will be used directly
This commit is contained in:
@@ -5,19 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.commonizer
|
||||
|
||||
interface CommonizerSettings {
|
||||
|
||||
sealed class Key<T : Any> {
|
||||
abstract val defaultValue: T
|
||||
}
|
||||
|
||||
fun <T : Any> getSetting(key: Key<T>): T
|
||||
}
|
||||
|
||||
object OptimisticNumberCommonizationEnabledKey : CommonizerSettings.Key<Boolean>() {
|
||||
override val defaultValue: Boolean = true
|
||||
}
|
||||
|
||||
internal object DefaultCommonizerSettings : CommonizerSettings {
|
||||
override fun <T : Any> getSetting(key: CommonizerSettings.Key<T>): T {
|
||||
return key.defaultValue
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
package org.jetbrains.kotlin.commonizer.cli
|
||||
|
||||
internal class BooleanOptionType(
|
||||
alias: OptionAlias,
|
||||
alias: String,
|
||||
description: String,
|
||||
mandatory: Boolean
|
||||
) : OptionType<Boolean>(alias, description, mandatory) {
|
||||
|
||||
+2
-3
@@ -8,11 +8,10 @@ package org.jetbrains.kotlin.commonizer.cli
|
||||
import org.jetbrains.kotlin.commonizer.CommonizerSettings
|
||||
|
||||
internal sealed class CommonizerSettingOptionType<T : Any>(
|
||||
alias: OptionAlias,
|
||||
val commonizerSettingKey: CommonizerSettings.Key<T>,
|
||||
description: String,
|
||||
val commonizerSettingKey: CommonizerSettings.Key<T>
|
||||
) : OptionType<T>(
|
||||
alias,
|
||||
commonizerSettingKey.alias,
|
||||
description,
|
||||
mandatory = false,
|
||||
)
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.commonizer.parseCommonizerDependency
|
||||
|
||||
internal abstract class DependenciesLibrariesSetOptionType(
|
||||
mandatory: Boolean,
|
||||
alias: OptionAlias,
|
||||
alias: String,
|
||||
description: String
|
||||
) : OptionType<List<CommonizerDependency>>(
|
||||
mandatory = mandatory,
|
||||
|
||||
+1
-1
@@ -7,6 +7,6 @@ package org.jetbrains.kotlin.commonizer.cli
|
||||
|
||||
internal object DependencyLibrariesOptionType : DependenciesLibrariesSetOptionType(
|
||||
mandatory = false,
|
||||
alias = DEPENDENCY_LIBRARIES_OPTION_ALIAS,
|
||||
alias = DEPENDENCY_LIBRARIES_ALIAS,
|
||||
description = "';' separated list of klib file paths that can be used as dependency"
|
||||
)
|
||||
|
||||
+1
-1
@@ -7,6 +7,6 @@ package org.jetbrains.kotlin.commonizer.cli
|
||||
|
||||
internal object InputLibrariesOptionType : LibrariesSetOptionType(
|
||||
mandatory = true,
|
||||
alias = INPUT_LIBRARIES_OPTION_ALIAS,
|
||||
alias = INPUT_LIBRARIES_ALIAS,
|
||||
description = "';' separated list of klib file paths that will get commonized"
|
||||
)
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.io.File
|
||||
|
||||
internal abstract class LibrariesSetOptionType(
|
||||
mandatory: Boolean,
|
||||
alias: OptionAlias,
|
||||
alias: String,
|
||||
description: String
|
||||
) : OptionType<List<File>>(
|
||||
mandatory = mandatory,
|
||||
|
||||
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.commonizer.cli
|
||||
|
||||
import org.jetbrains.kotlin.commonizer.CommonizerLogLevel
|
||||
|
||||
internal object LogLevelOptionType : OptionType<CommonizerLogLevel>(LOG_LEVEL_OPTION_ALIAS, "{quiet, info}", false) {
|
||||
internal object LogLevelOptionType : OptionType<CommonizerLogLevel>(LOG_LEVEL_ALIAS, "{quiet, info}", false) {
|
||||
override fun parse(rawValue: String, onError: (reason: String) -> Nothing): Option<CommonizerLogLevel> {
|
||||
return when (rawValue.lowercase().trim()) {
|
||||
"quiet" -> Option(this, CommonizerLogLevel.Quiet)
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.commonizer.cli
|
||||
|
||||
import java.io.File
|
||||
|
||||
internal object NativeDistributionOptionType : OptionType<File>(NATIVE_DISTRIBUTION_OPTION_ALIAS, "Path to the Kotlin/Native distribution") {
|
||||
internal object NativeDistributionOptionType : OptionType<File>(NATIVE_DISTRIBUTION_PATH_ALIAS, "Path to the Kotlin/Native distribution") {
|
||||
override fun parse(rawValue: String, onError: (reason: String) -> Nothing): Option<File> {
|
||||
val file = File(rawValue)
|
||||
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget.Companion.predefinedTargets
|
||||
|
||||
internal object NativeTargetsOptionType : OptionType<List<KonanTarget>>(
|
||||
NATIVE_TARGETS_OPTION_ALIAS, "Comma-separated list of hardware targets", mandatory = false
|
||||
NATIVE_TARGETS_ALIAS, "Comma-separated list of hardware targets", mandatory = false
|
||||
) {
|
||||
override fun parse(rawValue: String, onError: (reason: String) -> Nothing): Option<List<KonanTarget>> {
|
||||
val targetNames = rawValue.split(',')
|
||||
|
||||
+1
-2
@@ -8,9 +8,8 @@ package org.jetbrains.kotlin.commonizer.cli
|
||||
import org.jetbrains.kotlin.commonizer.OptimisticNumberCommonizationEnabledKey
|
||||
|
||||
internal object OptimisticNumberCommonizationOptionType : CommonizerSettingOptionType<Boolean>(
|
||||
OPTIMISTIC_NUMBER_COMMONIZATION_ENABLED_OPTION_ALIAS,
|
||||
"Boolean (default true)\nEnable commonization of integer types with different bit width to the most narrow among them",
|
||||
OptimisticNumberCommonizationEnabledKey,
|
||||
"Boolean (default true)\nEnable commonization of integer types with different bit width to the most narrow among them",
|
||||
) {
|
||||
override fun parse(rawValue: String, onError: (reason: String) -> Nothing): Option<Boolean> =
|
||||
Option(this, parseBoolean(rawValue, onError))
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
package org.jetbrains.kotlin.commonizer.cli
|
||||
|
||||
internal abstract class OptionType<T>(
|
||||
val alias: OptionAlias,
|
||||
val alias: String,
|
||||
val description: String,
|
||||
val mandatory: Boolean = true
|
||||
) {
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.commonizer.SharedCommonizerTarget
|
||||
import org.jetbrains.kotlin.commonizer.parseCommonizerTarget
|
||||
|
||||
internal object OutputCommonizerTargetsOptionType : OptionType<Set<SharedCommonizerTarget>>(
|
||||
alias = OUTPUT_COMMONIZER_TARGET_OPTION_ALIAS,
|
||||
alias = OUTPUT_COMMONIZER_TARGETS_ALIAS,
|
||||
description = "All output targets separated with ';'",
|
||||
mandatory = true
|
||||
) {
|
||||
|
||||
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.commonizer.cli
|
||||
|
||||
import java.io.File
|
||||
|
||||
internal object OutputOptionType : OptionType<File>(OUTPUT_OPTION_ALIAS, "Destination for commonized libraries") {
|
||||
internal object OutputOptionType : OptionType<File>(OUTPUT_PATH_ALIAS, "Destination for commonized libraries") {
|
||||
override fun parse(rawValue: String, onError: (reason: String) -> Nothing): Option<File> {
|
||||
val file = File(rawValue)
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.commonizer.cli
|
||||
|
||||
import org.jetbrains.kotlin.commonizer.stats.StatsType
|
||||
|
||||
internal object StatsTypeOptionType : OptionType<StatsType>(STATS_TYPE_OPTION_ALIAS, DESCRIPTION, mandatory = false) {
|
||||
internal object StatsTypeOptionType : OptionType<StatsType>(STATS_TYPE_ALIAS, DESCRIPTION, mandatory = false) {
|
||||
override fun parse(rawValue: String, onError: (reason: String) -> Nothing): Option<StatsType> {
|
||||
val value = StatsType.values().firstOrNull { it.name.equals(rawValue, ignoreCase = true) }
|
||||
?: onError("Invalid stats type: $rawValue")
|
||||
|
||||
@@ -30,7 +30,7 @@ internal abstract class Task(private val options: Collection<Option<*>>) : Compa
|
||||
abstract fun execute(logPrefix: String = "")
|
||||
|
||||
protected inline fun <reified T, reified O : OptionType<T>> getMandatory(nameFilter: (String) -> Boolean = { true }): T {
|
||||
val option = options.filter { it.type is O }.single { nameFilter(it.type.alias.aliasString) }
|
||||
val option = options.filter { it.type is O }.single { nameFilter(it.type.alias) }
|
||||
check(option.type.mandatory)
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@@ -38,7 +38,7 @@ internal abstract class Task(private val options: Collection<Option<*>>) : Compa
|
||||
}
|
||||
|
||||
internal inline fun <reified T, reified O : OptionType<T>> getOptional(nameFilter: (String) -> Boolean = { true }): T? {
|
||||
val option = options.filter { it.type is O }.singleOrNull { nameFilter(it.type.alias.aliasString) }
|
||||
val option = options.filter { it.type is O }.singleOrNull { nameFilter(it.type.alias) }
|
||||
if (option != null) check(!option.type.mandatory)
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
|
||||
@@ -20,12 +20,12 @@ internal enum class TaskType(
|
||||
NativeTargetsOptionType,
|
||||
OutputCommonizerTargetsOptionType,
|
||||
BooleanOptionType(
|
||||
COPY_STDLIB_OPTION_ALIAS,
|
||||
COPY_STDLIB_ALIAS,
|
||||
"Boolean (default false);\nwhether to copy Kotlin/Native endorsed libraries to the destination",
|
||||
mandatory = false
|
||||
),
|
||||
BooleanOptionType(
|
||||
COPY_ENDORSED_LIBS_OPTION_ALIAS,
|
||||
COPY_ENDORSED_LIBS_ALIAS,
|
||||
"Boolean (default false);\nwhether to copy Kotlin/Native endorsed libraries to the destination",
|
||||
mandatory = false
|
||||
),
|
||||
|
||||
@@ -46,7 +46,7 @@ private fun parseTask(
|
||||
tasks: MutableList<Task>
|
||||
): String? {
|
||||
val taskType = TaskType.getByAlias(taskAlias) ?: printUsageAndExit("Unknown task $taskAlias")
|
||||
val optionTypes = taskType.optionTypes.associateBy { it.alias.aliasString }
|
||||
val optionTypes = taskType.optionTypes.associateBy { it.alias }
|
||||
val options = mutableMapOf<String, Option<*>>()
|
||||
|
||||
fun buildOngoingTask() {
|
||||
@@ -117,7 +117,7 @@ private fun printUsageAndExit(errorMessage: String? = null): Nothing {
|
||||
println(formatLeft(1, if (taskType.optionTypes.isNotEmpty()) "Options:" else "No options."))
|
||||
for (optionType in taskType.optionTypes) {
|
||||
val lines = optionType.description.split('\n')
|
||||
println(formatBoth(2, "-${optionType.alias.aliasString}", lines.first()))
|
||||
println(formatBoth(2, "-${optionType.alias}", lines.first()))
|
||||
lines.drop(1).forEach { println(StringBuilder().formatRight(it)) }
|
||||
}
|
||||
println()
|
||||
|
||||
Reference in New Issue
Block a user