diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2025-01-10 16:37:36 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2025-01-10 16:37:46 +0300 |
| commit | e35c630c1d2fe9621cc43dd86596aaaca8a56d2e (patch) | |
| tree | d2fec63e07f707c5d3f8efdb4ebf666b37b7eaeb /src/utils | |
| parent | d3047afa7f0255b6735a775f752f96c6ca0385ab (diff) | |
| download | niri-e35c630c1d2fe9621cc43dd86596aaaca8a56d2e.tar.gz niri-e35c630c1d2fe9621cc43dd86596aaaca8a56d2e.tar.bz2 niri-e35c630c1d2fe9621cc43dd86596aaaca8a56d2e.zip | |
Format version as calver automatically
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/mod.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/utils/mod.rs b/src/utils/mod.rs index e5516506..b213205b 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -83,11 +83,25 @@ pub fn version() -> String { return String::from(v); } - let version = env!("CARGO_PKG_VERSION"); + const MAJOR: &str = env!("CARGO_PKG_VERSION_MAJOR"); + const MINOR: &str = env!("CARGO_PKG_VERSION_MINOR"); + const PATCH: &str = env!("CARGO_PKG_VERSION_PATCH"); + + let minor_prefix = if MINOR.len() == 1 { + // Print single-digit months in '0M' format. + "0" + } else { + "" + }; + let commit = option_env!("NIRI_BUILD_COMMIT").unwrap_or(git_version!(fallback = "unknown commit")); - format!("{version} ({commit})") + if PATCH == "0" { + format!("{MAJOR}.{minor_prefix}{MINOR} ({commit})") + } else { + format!("{MAJOR}.{minor_prefix}{MINOR}.{PATCH} ({commit})") + } } pub fn get_monotonic_time() -> Duration { |
