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} --- mumd/build.rs | 25 +++++++++++++++++++++++++ mumd/src/main.rs | 5 +++++ 2 files changed, 30 insertions(+) create mode 100644 mumd/build.rs (limited to 'mumd') diff --git a/mumd/build.rs b/mumd/build.rs new file mode 100644 index 0000000..45cfd4e --- /dev/null +++ b/mumd/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("???") + } +} diff --git a/mumd/src/main.rs b/mumd/src/main.rs index 0526930..e7b4bec 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -15,6 +15,11 @@ 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")); + return; + } + setup_logger(std::io::stderr(), true); notify::init(); -- cgit v1.2.1 From abbea6a4a20ed1562d99ce5942154352bc545eb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Sun, 21 Mar 2021 14:59:03 +0100 Subject: commit_hash returns option instead --- mumd/build.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'mumd') diff --git a/mumd/build.rs b/mumd/build.rs index 45cfd4e..f09b1c4 100644 --- a/mumd/build.rs +++ b/mumd/build.rs @@ -5,21 +5,17 @@ fn main() { "{} {}-{}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"), - commit_hash(), + commit_hash().unwrap_or_else(|| "???".to_string()), ); println!("cargo:rustc-env=VERSION={}", version); } -fn commit_hash() -> String { +fn commit_hash() -> Option { 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("???") - } + output.ok().map(|o| String::from_utf8_lossy(&o.stdout).to_string()) } -- cgit v1.2.1 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 +++++++-------- mumd/src/main.rs | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) (limited to 'mumd') 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 From a8e24b8f92e23bb8c64d8056ac1a5d882cb94de2 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Mon, 22 Mar 2021 00:20:33 +0100 Subject: inline variable --- mumd/build.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'mumd') diff --git a/mumd/build.rs b/mumd/build.rs index 78f279f..0a4f506 100644 --- a/mumd/build.rs +++ b/mumd/build.rs @@ -1,8 +1,7 @@ use std::process::Command; fn main() { - let maybe_hash = commit_hash(); - let version = match maybe_hash.as_deref() { + let version = match commit_hash().as_deref() { None | Some("") => format!("v{}", env!("CARGO_PKG_VERSION")), Some(version) => version.to_string(), }; -- cgit v1.2.1