From f9d1f57e2df87ebfaecccdad230feadc1dffd609 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sun, 21 Mar 2021 21:54:35 +0100 Subject: made more consistent output without git --- mumd/build.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'mumd/build.rs') diff --git a/mumd/build.rs b/mumd/build.rs index f09b1c4..78f279f 100644 --- a/mumd/build.rs +++ b/mumd/build.rs @@ -1,20 +1,19 @@ use std::process::Command; fn main() { - let version = format!( - "{} {}-{}", - env!("CARGO_PKG_NAME"), - env!("CARGO_PKG_VERSION"), - commit_hash().unwrap_or_else(|| "???".to_string()), - ); + let maybe_hash = commit_hash(); + let version = match maybe_hash.as_deref() { + None | Some("") => format!("v{}", env!("CARGO_PKG_VERSION")), + Some(version) => version.to_string(), + }; println!("cargo:rustc-env=VERSION={}", version); } fn commit_hash() -> Option { let output = Command::new("git") - .arg("show") - .arg("--pretty=format:%h") // abbrev hash + .arg("describe") + .arg("--tags") .current_dir(env!("CARGO_MANIFEST_DIR")) .output(); output.ok().map(|o| String::from_utf8_lossy(&o.stdout).to_string()) -- cgit v1.2.1