mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-22 09:58:08 +00:00
Simplify running git in gradle
This commit is contained in:
parent
95b4c08605
commit
e10f2496de
@ -28,23 +28,10 @@ plugins {
|
|||||||
|
|
||||||
val licenseResDir = File("$projectDir/build/dependency-license-res")
|
val licenseResDir = File("$projectDir/build/dependency-license-res")
|
||||||
|
|
||||||
fun String.runCommand(
|
val hashProvider = project.providers.exec {
|
||||||
workingDir: File = File("."),
|
workingDir = rootDir
|
||||||
timeoutAmount: Long = 60,
|
commandLine("git", "rev-parse", "--short", "HEAD")
|
||||||
timeoutUnit: TimeUnit = TimeUnit.SECONDS
|
}.standardOutput.asText.map { it.trim() }
|
||||||
): String = ProcessBuilder(split("\\s(?=(?:[^'\"`]*(['\"`])[^'\"`]*\\1)*[^'\"`]*$)".toRegex()))
|
|
||||||
.directory(workingDir)
|
|
||||||
.redirectOutput(ProcessBuilder.Redirect.PIPE)
|
|
||||||
.redirectError(ProcessBuilder.Redirect.PIPE)
|
|
||||||
.start()
|
|
||||||
.apply { waitFor(timeoutAmount, timeoutUnit) }
|
|
||||||
.run {
|
|
||||||
val error = errorStream.bufferedReader().readText().trim()
|
|
||||||
if (error.isNotEmpty()) {
|
|
||||||
throw Exception(error)
|
|
||||||
}
|
|
||||||
inputStream.bufferedReader().readText().trim()
|
|
||||||
}
|
|
||||||
|
|
||||||
android {
|
android {
|
||||||
namespace = "org.kde.kdeconnect_tp"
|
namespace = "org.kde.kdeconnect_tp"
|
||||||
@ -134,8 +121,7 @@ android {
|
|||||||
// Default output filename is "${project.name}-${v.name}.apk". We want
|
// Default output filename is "${project.name}-${v.name}.apk". We want
|
||||||
// the Git commit short-hash to be added onto that default filename.
|
// the Git commit short-hash to be added onto that default filename.
|
||||||
try {
|
try {
|
||||||
val hash = "git rev-parse --short HEAD".runCommand(workingDir = rootDir)
|
val newName = "${project.name}-${variant.name}-${hashProvider.get()}.apk"
|
||||||
val newName = "${project.name}-${variant.name}-${hash}.apk"
|
|
||||||
logger.quiet(" Found an output file ${output.outputFile.name}, renaming to $newName")
|
logger.quiet(" Found an output file ${output.outputFile.name}, renaming to $newName")
|
||||||
output.outputFileName = newName
|
output.outputFileName = newName
|
||||||
} catch (ignored: Exception) {
|
} catch (ignored: Exception) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user