aboutsummaryrefslogtreecommitdiff
path: root/buildSrc/src/lookupversion.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-07-11 02:21:41 +0200
committerLinnea Gräf <nea@nea.moe>2024-07-11 02:21:41 +0200
commite683aa1e6c2e6efe2502e78f23c86fbb9d4b86fe (patch)
treeb867cc90b4a3cc9dfced6731fa9a189a302c4788 /buildSrc/src/lookupversion.kt
parentfeca9c937be40bfed255e6574dea70d640fdafea (diff)
downloadFirmament-e683aa1e6c2e6efe2502e78f23c86fbb9d4b86fe.tar.gz
Firmament-e683aa1e6c2e6efe2502e78f23c86fbb9d4b86fe.tar.bz2
Firmament-e683aa1e6c2e6efe2502e78f23c86fbb9d4b86fe.zip
Add auto version generator
[no changelog]
Diffstat (limited to 'buildSrc/src/lookupversion.kt')
-rw-r--r--buildSrc/src/lookupversion.kt31
1 files changed, 31 insertions, 0 deletions
diff --git a/buildSrc/src/lookupversion.kt b/buildSrc/src/lookupversion.kt
new file mode 100644
index 0000000..2fe9bb9
--- /dev/null
+++ b/buildSrc/src/lookupversion.kt
@@ -0,0 +1,31 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+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"
+}