diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-01-16 02:56:15 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-03-21 14:49:43 +0100 |
| commit | dfe231a2b03efa31ae4ff9a43e469144560eec8f (patch) | |
| tree | add668ef2daf5f0f9b550eb96e951140e6407644 | |
| parent | d6348155f3420e9c01f805f0bb3a520cbd1d4c1c (diff) | |
| download | mum-dfe231a2b03efa31ae4ff9a43e469144560eec8f.tar.gz | |
add a --version that includes commit hash to mum{ctl,d}
| -rw-r--r-- | mumctl/build.rs | 25 | ||||
| -rw-r--r-- | mumctl/src/main.rs | 5 | ||||
| -rw-r--r-- | mumd/build.rs | 25 | ||||
| -rw-r--r-- | mumd/src/main.rs | 5 |
4 files changed, 60 insertions, 0 deletions
diff --git a/mumctl/build.rs b/mumctl/build.rs new file mode 100644 index 0000000..45cfd4e --- /dev/null +++ b/mumctl/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/mumctl/src/main.rs b/mumctl/src/main.rs index d43ff4f..12de262 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -47,6 +47,11 @@ impl log::Log for SimpleLogger { static LOGGER: SimpleLogger = SimpleLogger; fn main() { + if std::env::args().find(|s| s.as_str() == "--version").is_some() { + println!(env!("VERSION")); + return; + } + log::set_logger(&LOGGER) .map(|()| log::set_max_level(LevelFilter::Info)).unwrap(); let mut config = config::read_default_cfg(); 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(); |
