Merge pull request #12823 from JosJuice/android-new-version-code

Android: Adopt a new versionCode scheme
This commit is contained in:
OatmealDome 2024-07-01 22:04:18 -04:00 committed by GitHub
commit 1bec2b6484
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -170,7 +170,7 @@ fun getGitVersion(): String {
fun getBuildVersionCode(): Int {
try {
return Integer.valueOf(
val commitCount = Integer.valueOf(
ProcessBuilder("git", "rev-list", "--first-parent", "--count", "HEAD")
.directory(project.rootDir)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
@ -178,6 +178,15 @@ fun getBuildVersionCode(): Int {
.start().inputStream.bufferedReader().use { it.readText() }
.trim()
)
val isRelease = ProcessBuilder("git", "describe", "--exact-match", "HEAD")
.directory(project.rootDir)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectError(ProcessBuilder.Redirect.PIPE)
.start()
.waitFor() == 0
return commitCount * 2 + (if (isRelease) 0 else 1)
} catch (e: Exception) {
logger.error("Cannot find git, defaulting to dummy version code")
}