Skip to content

Commit e35c630

Browse files
committed
Format version as calver automatically
1 parent d3047af commit e35c630

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/utils/mod.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,25 @@ pub fn version() -> String {
8383
return String::from(v);
8484
}
8585

86-
let version = env!("CARGO_PKG_VERSION");
86+
const MAJOR: &str = env!("CARGO_PKG_VERSION_MAJOR");
87+
const MINOR: &str = env!("CARGO_PKG_VERSION_MINOR");
88+
const PATCH: &str = env!("CARGO_PKG_VERSION_PATCH");
89+
90+
let minor_prefix = if MINOR.len() == 1 {
91+
// Print single-digit months in '0M' format.
92+
"0"
93+
} else {
94+
""
95+
};
96+
8797
let commit =
8898
option_env!("NIRI_BUILD_COMMIT").unwrap_or(git_version!(fallback = "unknown commit"));
8999

90-
format!("{version} ({commit})")
100+
if PATCH == "0" {
101+
format!("{MAJOR}.{minor_prefix}{MINOR} ({commit})")
102+
} else {
103+
format!("{MAJOR}.{minor_prefix}{MINOR}.{PATCH} ({commit})")
104+
}
91105
}
92106

93107
pub fn get_monotonic_time() -> Duration {

0 commit comments

Comments
 (0)