diff --git a/CHANGELOG.md b/CHANGELOG.md index 14740cd..305b7e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,12 +7,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## Unreleased ### Added - AIFF (Audio Interchange File Format, a PCM audio format like WAV) detection to [`infer`] +- `--version` output now includes the (short) hash of the git commit fif was built from ### Other -- Refactoring - split fif into main.rs and lib.rs, moved file-related functionality (directory scanning, etc.) into +- Refactoring - split fif into `main.rs` and `lib.rs`, moved file-related functionality (directory scanning, etc.) into files module, removed string module, etc. - Changelog "refactoring": - Based on the somewhat popular [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) guide, splitting the previous - "Features" heading into "Added" and "Changed" sections, renaming "Bugfixes" to "Fixed", and removing the + "Features" heading into "Added" and "Changed" sections, renaming "Bugfixes" to "Fixed", and removing the headings that (pointlessly?) previously divided the changelog into v0.3, v0.2, and v0.1 - A few minor grammar tweaks and reorganisations diff --git a/build.rs b/build.rs index cdea0ba..a6f498a 100644 --- a/build.rs +++ b/build.rs @@ -1,3 +1,5 @@ +use std::process::Command; + #[allow(unreachable_code, clippy::pedantic)] fn main() -> Result<(), String> { #[cfg(all(feature = "infer-backend", feature = "xdg-mime-backend"))] @@ -6,5 +8,21 @@ fn main() -> Result<(), String> { "fif cannot be compiled with multiple backends set - please enable only one, or use the default.", )); + // a more robust way of doing this would be to use vergen (https://github.com/rustyhorde/vergen), but it pulls in a + // whole bunch of extra dependencies (including chrono and git2), and also blocks compilation on the current MSRV. + // this method is less clever and robust, but it works! + let git = Command::new("git").args(&["rev-parse", "--short", "HEAD"]).output(); + let hash = match git { + Ok(output) => String::from_utf8_lossy(&*output.stdout).into(), + Err(_) => { + // git not being present (or failing) shouldn't block compilation + println!("cargo:warning=Failed to retrieve git commit hash"); + String::from("???") + } + }; + + println!("cargo:rustc-env=GIT_SHA={}", hash); + println!("cargo:rustc-rerun-if-changed=.git/HEAD"); + Ok(()) } diff --git a/src/utils.rs b/src/utils.rs index 226fd40..c0f3473 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -30,7 +30,15 @@ pub fn clap_version() -> &'static str { CLAP_VERSION.get_or_init(|| String::from /// Sets [`CLAP_LONG_VERSION`] to be similar to [`CLAP_VERSION`], followed by the chosen backend in parentheses (e.g. /// "v0.3.1 (XDG-Mime backend)"), then returns it as a String. pub fn clap_long_version() -> &'static str { - CLAP_LONG_VERSION.get_or_init(|| format!("v{} ({} backend)", VERSION.unwrap_or("???"), BACKEND).into()) + CLAP_LONG_VERSION.get_or_init(|| { + format!( + "v{} ({} backend, commit #{})", + VERSION.unwrap_or("???"), + BACKEND, + option_env!("GIT_SHA").unwrap_or("???") + ) + .into() + }) } /// Returns the name of the target operating system with proper casing, like "Windows" or "macOS".