Files
Firmament/buildSrc/src/lookupversion.kt
Linnea Gräf 63d0d32e46 Clean up reuse comments
[no changelog]
2024-08-08 01:15:43 +02:00

27 lines
754 B
Kotlin

fun execString(vararg args: String): String {
val pb = ProcessBuilder(*args)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.start()
pb.waitFor()
return pb.inputStream.readAllBytes().decodeToString().trim()
}
private val tag = "([0-9.]+)\\.0".toRegex()
private val tagOffset = "([0-9.]+)\\.0-([0-9]+)..+".toRegex()
inline fun <T> Regex.useMatcher(string: String, block: (MatchResult) -> T): T? {
return matchEntire(string)?.let(block)
}
fun getGitTagInfo(): String {
val str = execString("git", "describe", "--tags", "HEAD")
tag.useMatcher(str) {
return it.groupValues[0]
}
tagOffset.useMatcher(str) {
return it.groupValues[1] + "." + it.groupValues[2]
}
return "nogitversion"
}