2020-08-04 07:44:53 +00:00
|
|
|
use git_version::git_version;
|
|
|
|
use target_info::Target;
|
|
|
|
|
|
|
|
/// Returns the current version of this build of Lighthouse.
|
|
|
|
///
|
|
|
|
/// A plus-sign (`+`) is appended to the git commit if the tree is dirty.
|
2022-05-04 23:30:36 +00:00
|
|
|
/// Commit hash is omitted if the sources don't include git information.
|
2020-08-04 07:44:53 +00:00
|
|
|
///
|
|
|
|
/// ## Example
|
|
|
|
///
|
2021-09-03 23:28:21 +00:00
|
|
|
/// `Lighthouse/v1.5.1-67da032+`
|
2020-08-04 07:44:53 +00:00
|
|
|
pub const VERSION: &str = git_version!(
|
2021-02-24 23:51:05 +00:00
|
|
|
args = [
|
|
|
|
"--always",
|
|
|
|
"--dirty=+",
|
|
|
|
"--abbrev=7",
|
|
|
|
// NOTE: using --match instead of --exclude for compatibility with old Git
|
|
|
|
"--match=thiswillnevermatchlol"
|
|
|
|
],
|
2023-01-11 03:27:08 +00:00
|
|
|
prefix = "Lighthouse/v3.4.0-",
|
|
|
|
fallback = "Lighthouse/v3.4.0"
|
2020-08-04 07:44:53 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
/// Returns `VERSION`, but with platform information appended to the end.
|
|
|
|
///
|
|
|
|
/// ## Example
|
|
|
|
///
|
2021-09-03 23:28:21 +00:00
|
|
|
/// `Lighthouse/v1.5.1-67da032+/x86_64-linux`
|
2020-08-04 07:44:53 +00:00
|
|
|
pub fn version_with_platform() -> String {
|
|
|
|
format!("{}/{}-{}", VERSION, Target::arch(), Target::os())
|
|
|
|
}
|
2021-02-23 23:31:37 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use super::*;
|
|
|
|
use regex::Regex;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn version_formatting() {
|
2022-08-11 07:50:32 +00:00
|
|
|
let re =
|
|
|
|
Regex::new(r"^Lighthouse/v[0-9]+\.[0-9]+\.[0-9]+(-rc.[0-9])?(-[[:xdigit:]]{7})?\+?$")
|
|
|
|
.unwrap();
|
2021-03-26 04:53:57 +00:00
|
|
|
assert!(
|
|
|
|
re.is_match(VERSION),
|
|
|
|
"version doesn't match regex: {}",
|
|
|
|
VERSION
|
|
|
|
);
|
2021-02-23 23:31:37 +00:00
|
|
|
}
|
|
|
|
}
|