From dfe231a2b03efa31ae4ff9a43e469144560eec8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Sat, 16 Jan 2021 02:56:15 +0100 Subject: add a --version that includes commit hash to mum{ctl,d} --- mumctl/build.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 mumctl/build.rs (limited to 'mumctl/build.rs') diff --git a/mumctl/build.rs b/mumctl/build.rs new file mode 100644 index 0000000..45cfd4e --- /dev/null +++ b/mumctl/build.rs @@ -0,0 +1,25 @@ +use std::process::Command; + +fn main() { + let version = format!( + "{} {}-{}", + env!("CARGO_PKG_NAME"), + env!("CARGO_PKG_VERSION"), + commit_hash(), + ); + + println!("cargo:rustc-env=VERSION={}", version); +} + +fn commit_hash() -> String { + let output = Command::new("git") + .arg("show") + .arg("--pretty=format:%h") // abbrev hash + .current_dir(env!("CARGO_MANIFEST_DIR")) + .output(); + if let Ok(output) = output { + String::from_utf8_lossy(&output.stdout).to_string() + } else { + String::from("???") + } +} -- cgit v1.2.1