Fix runGit to use ProcessBuilder for AGP 9 compatibility
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.android.application)
|
||||
alias(libs.plugins.kotlin.compose)
|
||||
@@ -9,6 +7,14 @@ plugins {
|
||||
}
|
||||
|
||||
// ── Git-based versioning ────────────────────────────────────
|
||||
fun runGit(vararg args: String): String = try {
|
||||
val proc = ProcessBuilder("git", *args)
|
||||
.directory(rootProject.projectDir)
|
||||
.redirectErrorStream(true)
|
||||
.start()
|
||||
proc.inputStream.bufferedReader().readText().trim().also { proc.waitFor() }
|
||||
} catch (_: Exception) { "" }
|
||||
|
||||
// Version name from latest git tag (e.g. v0.1.0 -> "0.1.0")
|
||||
fun gitVersionName(): String = runGit("describe", "--tags", "--abbrev=0")
|
||||
.removePrefix("v")
|
||||
@@ -23,23 +29,8 @@ fun buildNumber(): Int {
|
||||
fun gitShortHash(): String = runGit("rev-parse", "--short", "HEAD")
|
||||
.ifEmpty { "unknown" }
|
||||
|
||||
// Display: "0.1.0+6.abc1234"
|
||||
fun gitDisplayVersion(): String {
|
||||
val base = gitVersionName()
|
||||
val build = buildNumber()
|
||||
val hash = gitShortHash()
|
||||
return "$base+$build.$hash"
|
||||
}
|
||||
|
||||
fun runGit(vararg args: String): String = try {
|
||||
val out = ByteArrayOutputStream()
|
||||
project.exec {
|
||||
commandLine("git", *args)
|
||||
standardOutput = out
|
||||
isIgnoreExitValue = true
|
||||
}
|
||||
out.toString().trim()
|
||||
} catch (_: Exception) { "" }
|
||||
// Display: "0.1.0+7.abc1234"
|
||||
fun gitDisplayVersion(): String = "${gitVersionName()}+${buildNumber()}.${gitShortHash()}"
|
||||
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
Reference in New Issue
Block a user