From dfcea4f12571306dc02e5a04f331e2faac8e5f7b Mon Sep 17 00:00:00 2001 From: Aaditya Dhingra Date: Fri, 23 Aug 2024 14:36:29 +0000 Subject: [PATCH] Bug 1894702 - "hg id --id" is called many times when building geckoview. r=gl,android-reviewers,pollymce,tthibaud Differential Revision: https://phabricator.services.mozilla.com/D217717 --- .../plugins/config/src/main/java/ConfigPlugin.kt | 7 ++++--- mobile/android/fenix/app/build.gradle | 2 +- mobile/android/focus-android/app/build.gradle | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/mobile/android/android-components/plugins/config/src/main/java/ConfigPlugin.kt b/mobile/android/android-components/plugins/config/src/main/java/ConfigPlugin.kt index 7261a093281b..3fe3ee11a6d7 100644 --- a/mobile/android/android-components/plugins/config/src/main/java/ConfigPlugin.kt +++ b/mobile/android/android-components/plugins/config/src/main/java/ConfigPlugin.kt @@ -18,6 +18,9 @@ class ConfigPlugin : Plugin { object Config { + @JvmStatic + val vcsHash by lazy { readVcsHash() } + @JvmStatic private fun generateDebugVersionName(): String { val today = Date() @@ -172,8 +175,7 @@ object Config { * Returns the git or hg hash of the currently checked out revision. If there are uncommitted changes, * a "+" will be appended to the hash, e.g. "c8ba05ad0+". */ - @JvmStatic - fun getVcsHash(): String { + private fun readVcsHash(): String { val gitRevision: String try { val revisionCmd = arrayOf("git", "rev-parse", "--short", "HEAD") @@ -189,7 +191,6 @@ object Config { val status = execReadStandardOutOrThrow(statusCmd) val hasUnstagedChanges = status.isNotBlank() val statusSuffix = if (hasUnstagedChanges) "+" else "" - return "git-$gitRevision$statusSuffix" } diff --git a/mobile/android/fenix/app/build.gradle b/mobile/android/fenix/app/build.gradle index 865ae6a0c11d..67a9330e1f84 100644 --- a/mobile/android/fenix/app/build.gradle +++ b/mobile/android/fenix/app/build.gradle @@ -125,7 +125,7 @@ android { if (gradle.ext.vcsHashFileContent) { buildConfigField "String", "VCS_HASH", "hg-\"${gradle.ext.vcsHashFileContent}\"" } else { - buildConfigField "String", "VCS_HASH", "\"${Config.getVcsHash()}\"" + buildConfigField "String", "VCS_HASH", "\"${Config.vcsHash}\"" } if (gradle.hasProperty("localProperties.autosignReleaseWithDebugKey")) { diff --git a/mobile/android/focus-android/app/build.gradle b/mobile/android/focus-android/app/build.gradle index 1f7ba7a3b166..cf7bf1533ea0 100644 --- a/mobile/android/focus-android/app/build.gradle +++ b/mobile/android/focus-android/app/build.gradle @@ -82,7 +82,7 @@ android { if (gradle.ext.vcsHashFileContent) { buildConfigField "String", "VCS_HASH", "hg-\"${gradle.ext.vcsHashFileContent}\"" } else { - buildConfigField "String", "VCS_HASH", "\"${Config.getVcsHash()}\"" + buildConfigField "String", "VCS_HASH", "\"${Config.vcsHash}\"" } if (gradle.hasProperty("localProperties.autosignReleaseWithDebugKey")) {