Skip to content

Commit

Permalink
Update build.rs file for the wallet to tolerate git not being present
Browse files Browse the repository at this point in the history
  • Loading branch information
TheQuantumPhysicist committed Feb 5, 2024
1 parent c5837f6 commit 4502b1e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
4 changes: 4 additions & 0 deletions wallet/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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=");
}
}
17 changes: 5 additions & 12 deletions wallet/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 4502b1e

Please sign in to comment.