From 92b277332a4d85a2cacad8f1df0fd058520088c5 Mon Sep 17 00:00:00 2001 From: Samer Afach Date: Mon, 5 Feb 2024 16:46:52 +0400 Subject: [PATCH 1/3] Tolerate not having git installed for wallet version --- wallet/src/version.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/wallet/src/version.rs b/wallet/src/version.rs index e00cb2516c..b5c6ab8688 100644 --- a/wallet/src/version.rs +++ b/wallet/src/version.rs @@ -13,13 +13,20 @@ // 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 = env!("GIT_HEAD_HASH"); - let git_tree_clean = env!("GIT_TREE_CLEAN"); - let version = env!("CARGO_PKG_VERSION"); - - let version_string = version; + 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"); // 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() { From 665b87d05fcdb7ec249a3d643b4312f01740501b Mon Sep 17 00:00:00 2001 From: Samer Afach Date: Mon, 5 Feb 2024 21:25:58 +0400 Subject: [PATCH 2/3] 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() { From 7a928b1db3b995cd2c6383134992bb9eb32f8086 Mon Sep 17 00:00:00 2001 From: Samer Afach Date: Tue, 6 Feb 2024 13:01:11 +0400 Subject: [PATCH 3/3] Minor improvement --- wallet/build.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/wallet/build.rs b/wallet/build.rs index cf9252f767..3cf1cd2cad 100644 --- a/wallet/build.rs +++ b/wallet/build.rs @@ -26,14 +26,12 @@ fn main() { .output() .map(|out| String::from_utf8_lossy(&out.stdout).trim().to_string()); - 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="); - } + println!( + "cargo:rustc-env=GIT_HEAD_HASH={}", + git_head_hash.unwrap_or("".to_string()) + ); + println!( + "cargo:rustc-env=GIT_TREE_CLEAN={}", + git_tree_clean.unwrap_or("".to_string()) + ); }