From 2f2c0d427bee914cc79e8779fcd5b10524a9bd75 Mon Sep 17 00:00:00 2001 From: Hazel OHearn Date: Mon, 1 Nov 2021 20:51:19 -0600 Subject: [PATCH 1/3] Add commit hash to version info, if present --- helix-term/build.rs | 11 +++++++++++ helix-term/src/main.rs | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 helix-term/build.rs diff --git a/helix-term/build.rs b/helix-term/build.rs new file mode 100644 index 000000000000..7e59f3f4f97b --- /dev/null +++ b/helix-term/build.rs @@ -0,0 +1,11 @@ +use std::process::Command; +fn main() { + let git_hash = Command::new("git") + .args(&["describe", "--dirty"]) + .output() + .map(|x| String::from_utf8(x.stdout).ok()) + .ok() + .flatten() + .unwrap_or(String::from(env!("CARGO_PKG_VERSION"))); + println!("cargo:rustc-env=GIT_HASH={}", git_hash); +} diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs index f746895cfc83..0a2d24ecb9c4 100644 --- a/helix-term/src/main.rs +++ b/helix-term/src/main.rs @@ -66,7 +66,7 @@ FLAGS: -V, --version Prints version information ", env!("CARGO_PKG_NAME"), - env!("CARGO_PKG_VERSION"), + env!("GIT_HASH"), env!("CARGO_PKG_AUTHORS"), env!("CARGO_PKG_DESCRIPTION"), logpath.display(), @@ -81,7 +81,7 @@ FLAGS: } if args.display_version { - println!("helix {}", env!("CARGO_PKG_VERSION")); + println!("helix {}", env!("GIT_HASH")); std::process::exit(0); } From 577009a7e853463690b25fd79f122c886781b4c6 Mon Sep 17 00:00:00 2001 From: Hazel OHearn Date: Tue, 2 Nov 2021 00:14:13 -0600 Subject: [PATCH 2/3] Rename GIT_HASH to indicate that it includes version, fix linter error --- helix-term/build.rs | 4 ++-- helix-term/src/main.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/helix-term/build.rs b/helix-term/build.rs index 7e59f3f4f97b..ba6b0d22f78c 100644 --- a/helix-term/build.rs +++ b/helix-term/build.rs @@ -6,6 +6,6 @@ fn main() { .map(|x| String::from_utf8(x.stdout).ok()) .ok() .flatten() - .unwrap_or(String::from(env!("CARGO_PKG_VERSION"))); - println!("cargo:rustc-env=GIT_HASH={}", git_hash); + .unwrap_or_else(|| String::from(env!("CARGO_PKG_VERSION"))); + println!("cargo:rustc-env=VERSION_AND_GIT_HASH={}", git_hash); } diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs index 0a2d24ecb9c4..00c1e1b6bb82 100644 --- a/helix-term/src/main.rs +++ b/helix-term/src/main.rs @@ -66,7 +66,7 @@ FLAGS: -V, --version Prints version information ", env!("CARGO_PKG_NAME"), - env!("GIT_HASH"), + env!("VERSION_AND_GIT_HASH"), env!("CARGO_PKG_AUTHORS"), env!("CARGO_PKG_DESCRIPTION"), logpath.display(), @@ -81,7 +81,7 @@ FLAGS: } if args.display_version { - println!("helix {}", env!("GIT_HASH")); + println!("helix {}", env!("VERSION_AND_GIT_HASH")); std::process::exit(0); } From a690aac6a00e309f0d14220ca84e7126c88e5d67 Mon Sep 17 00:00:00 2001 From: Gygaxis Vainhardt <44003709+AloeareV@users.noreply.github.com> Date: Tue, 2 Nov 2021 14:53:48 -0300 Subject: [PATCH 3/3] Add whitespace after use statement Co-authored-by: Ivan Tham --- helix-term/build.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/helix-term/build.rs b/helix-term/build.rs index ba6b0d22f78c..61ffa6f4f30b 100644 --- a/helix-term/build.rs +++ b/helix-term/build.rs @@ -1,4 +1,5 @@ use std::process::Command; + fn main() { let git_hash = Command::new("git") .args(&["describe", "--dirty"])