diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-02 21:48:02 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-02 21:48:02 +0300 |
| commit | b751d102f158968aab681cb663d27b4c32197f62 (patch) | |
| tree | 85d03609314559df7705c2cb0ab4e37ab6d9715f /src/build_info.rs | |
| parent | 295b09ca25edbccac65401ee84fa420dd3888aad (diff) | |
feat: add preview update channel
Diffstat (limited to 'src/build_info.rs')
| -rw-r--r-- | src/build_info.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/build_info.rs b/src/build_info.rs new file mode 100644 index 00000000..1fdedfbb --- /dev/null +++ b/src/build_info.rs @@ -0,0 +1,44 @@ +//! Build identity helpers. + +pub const BASE_VERSION: &str = env!("CARGO_PKG_VERSION"); + +pub fn channel() -> &'static str { + non_empty(option_env!("HERDR_BUILD_CHANNEL")).unwrap_or("stable") +} + +pub fn build_id() -> Option<&'static str> { + non_empty(option_env!("HERDR_BUILD_ID")) +} + +pub fn version() -> String { + match channel() { + "stable" => BASE_VERSION.to_string(), + channel => match build_id() { + Some(build_id) => format!("{BASE_VERSION}-{channel}.{build_id}"), + None => format!("{BASE_VERSION}-{channel}"), + }, + } +} + +pub fn is_preview() -> bool { + channel() == "preview" +} + +fn non_empty(value: Option<&'static str>) -> Option<&'static str> { + value.and_then(|value| { + let trimmed = value.trim(); + if trimmed.is_empty() { + None + } else { + Some(trimmed) + } + }) +} + +#[cfg(test)] +mod tests { + #[test] + fn stable_version_defaults_to_cargo_version() { + assert!(!super::version().is_empty()); + } +} |
