use std::fmt::{Display, Formatter, Result as FmtResult};
include!(concat!(env!("OUT_DIR"), "/build_time.rs"));
#[derive(Debug, Clone)]
pub struct BuildInfo {
name: &'static str,
version: &'static str,
commit: &'static str,
build_time: &'static str,
}
impl BuildInfo {
pub fn new() -> Self {
Self {
name: env!("CARGO_PKG_NAME"),
version: env!("CARGO_PKG_VERSION"),
commit: option_env!("PEARL_COMMIT_HASH").unwrap_or("hash-undefined"),
build_time: BUILD_TIME,
}
}
pub fn name(&self) -> &'static str {
self.name
}
pub fn version(&self) -> &'static str {
self.version
}
pub fn commit(&self) -> &'static str {
self.commit
}
pub fn build_time(&self) -> &'static str {
self.build_time
}
}
impl Display for BuildInfo {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
writeln!(
f,
"{} {} (commit: {}, built on: {})",
self.name, self.version, self.commit, self.build_time
)
}
}
#[test]
fn print_build_info() {
println!("{}", BuildInfo::new());
}