diff options
| author | Eskil Queseth <eskilq@kth.se> | 2021-03-21 21:54:35 +0100 |
|---|---|---|
| committer | Eskil Queseth <eskilq@kth.se> | 2021-03-21 21:54:35 +0100 |
| commit | f9d1f57e2df87ebfaecccdad230feadc1dffd609 (patch) | |
| tree | 53b86c38155181b25ef1adea333a4312825f11a6 | |
| parent | f4f9df5ab9cc40c11164e7e696ed3a60dc7b8e34 (diff) | |
| download | mum-f9d1f57e2df87ebfaecccdad230feadc1dffd609.tar.gz | |
made more consistent output without git
| -rw-r--r-- | mumctl/build.rs | 14 | ||||
| -rw-r--r-- | mumd/build.rs | 15 | ||||
| -rw-r--r-- | 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<String> { 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<String> { 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; } |
