瀏覽代碼

feat: make debug and release version name different (#288)

Reviewed-on: https://gitea.angry.im/PeterCxy/OpenEUICC/pulls/288
Co-authored-by: septs <github@septs.pw>
Co-committed-by: septs <github@septs.pw>
septs 1 月之前
父節點
當前提交
f17e171372
共有 1 個文件被更改,包括 17 次插入14 次删除
  1. 17 14
      buildSrc/src/main/kotlin/im/angry/openeuicc/build/Versioning.kt

+ 17 - 14
buildSrc/src/main/kotlin/im/angry/openeuicc/build/Versioning.kt

@@ -20,32 +20,35 @@ val Project.gitVersionCode: Int
             0
         }
 
-val Project.gitVersionName: String
-    get() =
-        try {
-            val stdout = ByteArrayOutputStream()
-            exec {
-                commandLine("git", "describe", "--always", "--tags", "--dirty")
-                standardOutput = stdout
-            }
-            stdout.toString("utf-8").trim('\n')
-        } catch (_: Exception) {
-            "Unknown"
+fun Project.getGitVersionName(vararg args: String): String =
+    try {
+        val stdout = ByteArrayOutputStream()
+        exec {
+            commandLine("git", "describe", "--always", "--tags", "--dirty", *args)
+            standardOutput = stdout
         }
+        stdout.toString("utf-8").trim('\n').removePrefix("unpriv-")
+    } catch (_: Exception) {
+        "Unknown"
+    }
+
 
 class MyVersioningPlugin : Plugin<Project> {
     override fun apply(target: Project) {
         target.configure<BaseAppModuleExtension> {
             defaultConfig {
                 versionCode = target.gitVersionCode
-                versionName = target.gitVersionName.removePrefix("unpriv-")
+                versionName = target.getGitVersionName()
             }
 
             applicationVariants.all {
                 if (name == "debug") {
                     outputs.forEach {
-                        (it as ApkVariantOutputImpl).versionCodeOverride =
-                            (System.currentTimeMillis() / 1000).toInt()
+                        with(it as ApkVariantOutputImpl) {
+                            versionCodeOverride = (System.currentTimeMillis() / 1000).toInt()
+                            // always keep the format: <tag>-<commits>-g<hash>[-dirty]
+                            versionNameOverride = target.getGitVersionName("--long")
+                        }
                     }
                 }
             }