Add a project property for Kotlin/Native version overriding
This commit is contained in:
committed by
Ilya Matveev
parent
80bec0898f
commit
ccd4bc1bff
@@ -16,7 +16,18 @@ interface KonanVersion : Serializable {
|
||||
|
||||
fun toString(showMeta: Boolean, showBuild: Boolean): String
|
||||
|
||||
companion object
|
||||
companion object {
|
||||
// major.minor.patch-meta-build where patch, meta and build are optional.
|
||||
private val versionPattern = "(\\d+)\\.(\\d+)(?:\\.(\\d+))?(?:-(\\p{Alpha}\\p{Alnum}*))?(?:-(\\d+))?".toRegex()
|
||||
|
||||
fun fromString(version: String) : KonanVersion {
|
||||
val (major, minor, maintenance, metaString, build) =
|
||||
versionPattern.matchEntire(version)?.destructured ?:
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class KonanVersionImpl(
|
||||
|
||||
Reference in New Issue
Block a user