summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar t8952024-01-13 18:06:33 -0500
committerGravatar t8952024-01-13 18:06:33 -0500
commit15d8a405296a0c1902cab1320d0894feb3129a2d (patch)
treea628268e7ae344a9f2c826abe427d079f7aeb484
parentMerge pull request #12605 from german77/abstract (diff)
downloadyuzu-15d8a405296a0c1902cab1320d0894feb3129a2d.tar.gz
yuzu-15d8a405296a0c1902cab1320d0894feb3129a2d.tar.xz
yuzu-15d8a405296a0c1902cab1320d0894feb3129a2d.zip
android: Clean up git commands in build.gradle
Diffstat (limited to '')
-rw-r--r--src/android/app/build.gradle.kts74
1 files changed, 18 insertions, 56 deletions
diff --git a/src/android/app/build.gradle.kts b/src/android/app/build.gradle.kts
index 53aafa08c..7318338fe 100644
--- a/src/android/app/build.gradle.kts
+++ b/src/android/app/build.gradle.kts
@@ -228,71 +228,33 @@ dependencies {
228 implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0") 228 implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0")
229} 229}
230 230
231fun getGitVersion(): String { 231fun runGitCommand(command: List<String>): String {
232 var versionName = "0.0" 232 return try {
233 233 ProcessBuilder(command)
234 try {
235 versionName = ProcessBuilder("git", "describe", "--always", "--long")
236 .directory(project.rootDir) 234 .directory(project.rootDir)
237 .redirectOutput(ProcessBuilder.Redirect.PIPE) 235 .redirectOutput(ProcessBuilder.Redirect.PIPE)
238 .redirectError(ProcessBuilder.Redirect.PIPE) 236 .redirectError(ProcessBuilder.Redirect.PIPE)
239 .start().inputStream.bufferedReader().use { it.readText() } 237 .start().inputStream.bufferedReader().use { it.readText() }
240 .trim() 238 .trim()
241 .replace(Regex("(-0)?-[^-]+$"), "")
242 } catch (e: Exception) { 239 } catch (e: Exception) {
243 logger.error("Cannot find git, defaulting to dummy version number") 240 logger.error("Cannot find git")
244 } 241 ""
245
246 if (System.getenv("GITHUB_ACTIONS") != null) {
247 val gitTag = System.getenv("GIT_TAG_NAME")
248 versionName = gitTag ?: versionName
249 } 242 }
250
251 return versionName
252} 243}
253 244
254fun getGitHash(): String { 245fun getGitVersion(): String {
255 try { 246 val versionName = if (System.getenv("GITHUB_ACTIONS") != null) {
256 val processBuilder = ProcessBuilder("git", "rev-parse", "--short", "HEAD") 247 val gitTag = System.getenv("GIT_TAG_NAME") ?: ""
257 processBuilder.directory(project.rootDir) 248 gitTag
258 val process = processBuilder.start() 249 } else {
259 val inputStream = process.inputStream 250 runGitCommand(listOf("git", "describe", "--always", "--long"))
260 val errorStream = process.errorStream 251 .replace(Regex("(-0)?-[^-]+$"), "")
261 process.waitFor()
262
263 return if (process.exitValue() == 0) {
264 inputStream.bufferedReader()
265 .use { it.readText().trim() } // return the value of gitHash
266 } else {
267 val errorMessage = errorStream.bufferedReader().use { it.readText().trim() }
268 logger.error("Error running git command: $errorMessage")
269 "dummy-hash" // return a dummy hash value in case of an error
270 }
271 } catch (e: Exception) {
272 logger.error("$e: Cannot find git, defaulting to dummy build hash")
273 return "dummy-hash" // return a dummy hash value in case of an error
274 } 252 }
253 return versionName.ifEmpty { "0.0" }
275} 254}
276 255
277fun getBranch(): String { 256fun getGitHash(): String =
278 try { 257 runGitCommand(listOf("git", "rev-parse", "--short", "HEAD")).ifEmpty { "dummy-hash" }
279 val processBuilder = ProcessBuilder("git", "rev-parse", "--abbrev-ref", "HEAD") 258
280 processBuilder.directory(project.rootDir) 259fun getBranch(): String =
281 val process = processBuilder.start() 260 runGitCommand(listOf("git", "rev-parse", "--abbrev-ref", "HEAD")).ifEmpty { "dummy-hash" }
282 val inputStream = process.inputStream
283 val errorStream = process.errorStream
284 process.waitFor()
285
286 return if (process.exitValue() == 0) {
287 inputStream.bufferedReader()
288 .use { it.readText().trim() } // return the value of gitHash
289 } else {
290 val errorMessage = errorStream.bufferedReader().use { it.readText().trim() }
291 logger.error("Error running git command: $errorMessage")
292 "dummy-hash" // return a dummy hash value in case of an error
293 }
294 } catch (e: Exception) {
295 logger.error("$e: Cannot find git, defaulting to dummy build hash")
296 return "dummy-hash" // return a dummy hash value in case of an error
297 }
298}