[K/N] Safe determining Kotlin/Native meta version
This commit is contained in:
@@ -20,12 +20,18 @@ interface KonanVersion : Serializable {
|
|||||||
// major.minor.patch-meta-build where patch, meta and build are optional.
|
// major.minor.patch-meta-build where patch, meta and build are optional.
|
||||||
private val versionPattern = "(\\d+)\\.(\\d+)(?:\\.(\\d+))?(?:-(\\p{Alpha}\\p{Alnum}*))?(?:-(\\d+))?".toRegex()
|
private val versionPattern = "(\\d+)\\.(\\d+)(?:\\.(\\d+))?(?:-(\\p{Alpha}\\p{Alnum}*))?(?:-(\\d+))?".toRegex()
|
||||||
|
|
||||||
fun fromString(version: String) : KonanVersion {
|
fun fromString(version: String): KonanVersion {
|
||||||
val (major, minor, maintenance, metaString, build) =
|
val (major, minor, maintenance, metaString, build) =
|
||||||
versionPattern.matchEntire(version)?.destructured ?:
|
versionPattern.matchEntire(version)?.destructured
|
||||||
throw IllegalArgumentException("Cannot parse Kotlin/Native version: $version")
|
?: throw IllegalArgumentException("Cannot parse Kotlin/Native version: $version")
|
||||||
val meta = metaString.ifEmpty { "release" }.let { MetaVersion.valueOf(it.toUpperCase()) }
|
|
||||||
return KonanVersionImpl(meta, major.toInt(), minor.toInt(), maintenance.toIntOrNull() ?: 0, build.toIntOrNull() ?: -1)
|
return KonanVersionImpl(
|
||||||
|
MetaVersion.findAppropriate(metaString),
|
||||||
|
major.toInt(),
|
||||||
|
minor.toInt(),
|
||||||
|
maintenance.toIntOrNull() ?: 0,
|
||||||
|
build.toIntOrNull() ?: -1
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,5 +17,13 @@ enum class MetaVersion(val metaString: String) {
|
|||||||
BETA("beta"),
|
BETA("beta"),
|
||||||
RC1("rc1"),
|
RC1("rc1"),
|
||||||
RC2("rc2"),
|
RC2("rc2"),
|
||||||
RELEASE("release")
|
RELEASE("release");
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
fun findAppropriate(metaString: String): MetaVersion {
|
||||||
|
return MetaVersion.values().find { it.metaString.equals(metaString, ignoreCase = true) }
|
||||||
|
?: if (metaString.isBlank()) RELEASE else error("Unknown meta version: $metaString")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user