Rework usage of Choice options
This commit is contained in:
committed by
Stanislav Erokhin
parent
cb642bca69
commit
f88d38314e
+10
-7
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.native.interop.tool
|
||||
import kotlinx.cli.ArgParser
|
||||
import kotlinx.cli.ArgType
|
||||
import kotlinx.cli.*
|
||||
import org.jetbrains.kotlin.native.interop.gen.jvm.GenerationMode
|
||||
|
||||
const val HEADER_FILTER_ADDITIONAL_SEARCH_PREFIX = "headerFilterAdditionalSearchPrefix"
|
||||
const val NODEFAULTLIBS_DEPRECATED = "nodefaultlibs"
|
||||
@@ -46,7 +47,7 @@ open class CommonInteropArguments(val argParser: ArgParser) {
|
||||
.multiple()
|
||||
val repo by argParser.option(ArgType.String, shortName = "r", description = "repository to resolve dependencies")
|
||||
.multiple()
|
||||
val mode by argParser.option(ArgType.Choice(listOf(MODE_METADATA, MODE_SOURCECODE)), description = "the way interop library is generated")
|
||||
val mode by argParser.option(ArgType.Choice<GenerationMode>(), description = "the way interop library is generated")
|
||||
.default(DEFAULT_MODE)
|
||||
val nodefaultlibs by argParser.option(ArgType.Boolean, NODEFAULTLIBS,
|
||||
description = "don't link the libraries from dist/klib automatically").default(false)
|
||||
@@ -65,10 +66,7 @@ open class CommonInteropArguments(val argParser: ArgParser) {
|
||||
description = "additional kotlinc compiler option").multiple()
|
||||
|
||||
companion object {
|
||||
const val MODE_SOURCECODE = "sourcecode"
|
||||
const val MODE_METADATA = "metadata"
|
||||
|
||||
const val DEFAULT_MODE = MODE_METADATA
|
||||
val DEFAULT_MODE = GenerationMode.METADATA
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,8 +125,13 @@ open class CInteropArguments(argParser: ArgParser =
|
||||
|
||||
class JSInteropArguments(argParser: ArgParser = ArgParser("jsinterop",
|
||||
prefixStyle = ArgParser.OptionPrefixStyle.JVM)): CommonInteropArguments(argParser) {
|
||||
val target by argParser.option(ArgType.Choice(listOf("wasm32")),
|
||||
description = "wasm target to compile to").default("wasm32")
|
||||
enum class TargetType {
|
||||
WASM32;
|
||||
|
||||
override fun toString() = name.toLowerCase()
|
||||
}
|
||||
val target by argParser.option(ArgType.Choice<TargetType>(),
|
||||
description = "wasm target to compile to").default(TargetType.WASM32)
|
||||
}
|
||||
|
||||
internal fun warn(msg: String) {
|
||||
|
||||
+4
-9
@@ -1,13 +1,8 @@
|
||||
package org.jetbrains.kotlin.native.interop.gen.jvm
|
||||
|
||||
import org.jetbrains.kotlin.native.interop.tool.CommonInteropArguments
|
||||
enum class GenerationMode(val modeName: String) {
|
||||
SOURCE_CODE("sourcecode"),
|
||||
METADATA("metadata");
|
||||
|
||||
enum class GenerationMode {
|
||||
SOURCE_CODE, METADATA
|
||||
}
|
||||
|
||||
fun parseGenerationMode(mode: String): GenerationMode? = when(mode) {
|
||||
CommonInteropArguments.MODE_METADATA -> GenerationMode.METADATA
|
||||
CommonInteropArguments.MODE_SOURCECODE -> GenerationMode.SOURCE_CODE
|
||||
else -> null
|
||||
override fun toString(): String = modeName
|
||||
}
|
||||
+7
-8
@@ -50,8 +50,8 @@ data class InternalInteropOptions(val generated: String, val natives: String, va
|
||||
fun main(args: Array<String>) {
|
||||
// Adding flavor option for interop plugin.
|
||||
class FullCInteropArguments: CInteropArguments() {
|
||||
val flavor by argParser.option(ArgType.Choice(listOf("jvm", "native", "wasm")), description = "Interop target")
|
||||
.default("jvm")
|
||||
val flavor by argParser.option(ArgType.Choice<KotlinPlatform>(), description = "Interop target")
|
||||
.default(KotlinPlatform.JVM)
|
||||
val generated by argParser.option(ArgType.String, description = "place generated bindings to the directory")
|
||||
.required()
|
||||
val natives by argParser.option(ArgType.String, description = "where to put the built native files")
|
||||
@@ -70,7 +70,8 @@ fun interop(
|
||||
"jvm", "native" -> {
|
||||
val cinteropArguments = CInteropArguments()
|
||||
cinteropArguments.argParser.parse(args)
|
||||
processCLib(flavor, cinteropArguments, additionalArgs)
|
||||
val platform = KotlinPlatform.values().single { it.name.equals(flavor, ignoreCase = true) }
|
||||
processCLib(platform, cinteropArguments, additionalArgs)
|
||||
}
|
||||
"wasm" -> processIdlLib(args, additionalArgs)
|
||||
else -> error("Unexpected flavor")
|
||||
@@ -192,11 +193,10 @@ private fun findFilesByGlobs(roots: List<Path>, globs: List<String>): Map<Path,
|
||||
return relativeToRoot
|
||||
}
|
||||
|
||||
private fun processCLib(flavorName: String, cinteropArguments: CInteropArguments,
|
||||
private fun processCLib(flavor: KotlinPlatform, cinteropArguments: CInteropArguments,
|
||||
additionalArgs: InternalInteropOptions): Array<String>? {
|
||||
val ktGenRoot = additionalArgs.generated
|
||||
val nativeLibsDir = additionalArgs.natives
|
||||
val flavor = KotlinPlatform.values().single { it.name.equals(flavorName, ignoreCase = true) }
|
||||
val defFile = cinteropArguments.def?.let { File(it) }
|
||||
val manifestAddend = additionalArgs.manifest?.let { File(it) }
|
||||
|
||||
@@ -210,7 +210,7 @@ private fun processCLib(flavorName: String, cinteropArguments: CInteropArguments
|
||||
val isLinkerOptsSetByUser = (cinteropArguments.linkerOpts.valueOrigin == ArgParser.ValueOrigin.SET_BY_USER) ||
|
||||
(cinteropArguments.linkerOptions.valueOrigin == ArgParser.ValueOrigin.SET_BY_USER) ||
|
||||
(cinteropArguments.linkerOption.valueOrigin == ArgParser.ValueOrigin.SET_BY_USER)
|
||||
if (flavorName == "native" && isLinkerOptsSetByUser) {
|
||||
if (flavor == KotlinPlatform.NATIVE && isLinkerOptsSetByUser) {
|
||||
warn("-linker-option(s)/-linkerOpts option is not supported by cinterop. Please add linker options to .def file or binary compilation instead.")
|
||||
}
|
||||
|
||||
@@ -238,8 +238,7 @@ private fun processCLib(flavorName: String, cinteropArguments: CInteropArguments
|
||||
val outKtPkg = fqParts.joinToString(".")
|
||||
|
||||
val mode = run {
|
||||
val providedMode = parseGenerationMode(cinteropArguments.mode)
|
||||
?: error ("Unexpected interop generation mode: ${cinteropArguments.mode}")
|
||||
val providedMode = cinteropArguments.mode
|
||||
|
||||
if (providedMode == GenerationMode.METADATA && flavor == KotlinPlatform.JVM) {
|
||||
warn("Metadata mode isn't supported for Kotlin/JVM! Falling back to sourcecode.")
|
||||
|
||||
Reference in New Issue
Block a user