From 4502b1e693323122f07df992faaf500514de776c Mon Sep 17 00:00:00 2001 From: Samer Afach Date: Mon, 5 Feb 2024 21:25:58 +0400 Subject: [PATCH] Update build.rs file for the wallet to tolerate git not being present --- wallet/build.rs | 4 ++++ wallet/src/version.rs | 17 +++++------------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/wallet/build.rs b/wallet/build.rs index 62f8f0cf36..cf9252f767 100644 --- a/wallet/build.rs +++ b/wallet/build.rs @@ -28,8 +28,12 @@ fn main() { if let Ok(git_hash) = git_head_hash { println!("cargo:rustc-env=GIT_HEAD_HASH={}", git_hash); + } else { + println!("cargo:rustc-env=GIT_HEAD_HASH="); } if let Ok(git_tree_clean) = git_tree_clean { println!("cargo:rustc-env=GIT_TREE_CLEAN={}", git_tree_clean); + } else { + println!("cargo:rustc-env=GIT_TREE_CLEAN="); } } diff --git a/wallet/src/version.rs b/wallet/src/version.rs index b5c6ab8688..e00cb2516c 100644 --- a/wallet/src/version.rs +++ b/wallet/src/version.rs @@ -13,20 +13,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -fn stdout_or_empty(command: &str, args: &[&str]) -> String { - let res = std::process::Command::new(command) - .args(args) - .output() - .map(|o| o.stdout) - .unwrap_or_default(); - String::from_utf8_lossy(res.as_ref()).as_ref().trim().to_string() -} - /// Get the Wallet version and optionally git hash pub fn get_version() -> String { - let git_head_hash = stdout_or_empty("git", &["rev-parse", "HEAD"]); - let git_tree_clean = stdout_or_empty("git", &["status", "-s"]); - let version_string = env!("CARGO_PKG_VERSION"); + let git_head_hash = env!("GIT_HEAD_HASH"); + let git_tree_clean = env!("GIT_TREE_CLEAN"); + let version = env!("CARGO_PKG_VERSION"); + + let version_string = version; // If the git hash is not available, we don't want to print anything let git_hash_string = if git_head_hash.trim().is_empty() {