//! Stamps the build with the commit it came from. //! //! The crate version alone cannot tell a stale install from a fresh build: it is //! pinned at 0.1.0 and nobody bumps it per install, so both binaries claim the //! same thing. The short sha is what makes `worklane --version` able to answer //! "is this the binary with the fix in it". //! //! Absent a git directory, as when installing from a published crate, the sha is //! "unknown" rather than a build failure. use std::process::Command; fn main() { // Without these, an incremental build keeps stamping the sha it first saw. println!("cargo:rerun-if-changed=.git/HEAD"); println!("cargo:rerun-if-changed=.git/refs"); println!("cargo:rustc-env=WORKLANE_GIT_SHA={}", git_sha()); } fn git_sha() -> String { let output = Command::new("git") .args(["rev-parse", "--short", "HEAD"]) .output(); let sha = match output { Ok(output) if output.status.success() => { String::from_utf8_lossy(&output.stdout).trim().to_string() } _ => String::new(), }; if sha.is_empty() { "unknown".to_string() } else { sha } }