blob: 1fdedfbb7a000939e74f5dcdfcd3c55ab0dc45d1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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());
}
}
|