anki/rslib/src/version.rs

38 lines
989 B
Rust
Raw Normal View History

2020-05-26 09:18:50 +02:00
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use std::env;
2020-05-26 09:18:50 +02:00
use lazy_static::lazy_static;
fn buildinfo(key: &str) -> &'static str {
let buildinfo = include_str!(env!("BUILDINFO"));
2020-11-05 02:21:27 +01:00
for line in buildinfo.split('\n') {
let mut it = line.split(' ');
if it.next().unwrap() == key {
return it.next().unwrap();
}
}
unreachable!("{} not found", key);
}
2020-05-26 09:18:50 +02:00
pub fn version() -> &'static str {
buildinfo("STABLE_VERSION")
2020-05-26 09:18:50 +02:00
}
pub fn buildhash() -> &'static str {
buildinfo("STABLE_BUILDHASH")
2020-05-26 09:18:50 +02:00
}
pub(crate) fn sync_client_version() -> &'static str {
lazy_static! {
static ref VER: String = format!(
"anki,{version} ({buildhash}),{platform}",
version = version(),
buildhash = buildhash(),
platform = env::var("PLATFORM").unwrap_or_else(|_| env::consts::OS.to_string())
2020-05-26 09:18:50 +02:00
);
}
&VER
}