use std::process::Command;
fn main() {
let calver = Command::new("git")
.args(["describe", "--tags", "--abbrev=0"])
.output()
.ok()
.and_then(|o| {
if o.status.success() {
String::from_utf8(o.stdout).ok()
} else {
None
}
})
.map(|s| s.trim().to_string())
.unwrap_or_else(|| "dev".to_string());
let commit = Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
.ok()
.and_then(|o| {
if o.status.success() {
String::from_utf8(o.stdout).ok()
} else {
None
}
})
.map(|s| s.trim().to_string())
.unwrap_or_else(|| "unknown".to_string());
let dirty = Command::new("git")
.args(["status", "--porcelain"])
.output()
.ok()
.map(|o| !o.stdout.is_empty())
.unwrap_or(false);
let dirty_suffix = if dirty { "-dirty" } else { "" };
println!("cargo:rustc-env=SENTINEL_CALVER={}", calver);
println!("cargo:rustc-env=SENTINEL_COMMIT={}{}", commit, dirty_suffix);
println!("cargo:rerun-if-changed=.git/HEAD");
println!("cargo:rerun-if-changed=.git/refs/tags");
}