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 --- mumctl/build.rs | 14 +++++++------- mumd/build.rs | 15 +++++++-------- mumd/src/main.rs | 2 +- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/mumctl/build.rs b/mumctl/build.rs index 6ac9329..78f279f 100644 --- a/mumctl/build.rs +++ b/mumctl/build.rs @@ -1,19 +1,19 @@ use std::process::Command; fn main() { - let version = format!( - "{}-{}", - 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()) 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()) diff --git a/mumd/src/main.rs b/mumd/src/main.rs index e7b4bec..7c3745c 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -16,7 +16,7 @@ use tokio::task::spawn_blocking; #[tokio::main] async fn main() { if std::env::args().find(|s| s.as_str() == "--version").is_some() { - println!(env!("VERSION")); + println!("mumd {}", env!("VERSION")); return; } -- cgit v1.2.1