use std::{path::Path, process::Command};
fn main() {
let host = if let Ok(output) = Command::new("uname").arg("-mr").output() {
String::from_utf8_lossy(&output.stdout).trim().to_string()
} else {
"?".to_string()
};
println!("cargo:rustc-env=SYD_BUILDHOST={host}");
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
let root = root.join(".git");
let mut head = String::new();
if root.exists() {
if let Ok(output) = Command::new("git").arg("describe").output() {
head = String::from_utf8_lossy(&output.stdout).trim().to_string();
}
if head.is_empty() {
if let Ok(output) = Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
{
head = String::from_utf8_lossy(&output.stdout).trim().to_string();
}
}
if let Ok(output) = Command::new("git")
.args(["diff-index", "-m", "--name-only", "HEAD"])
.output()
{
let changes = String::from_utf8_lossy(&output.stdout);
if !changes.is_empty() {
head = format!("{head}-dirty");
}
}
}
println!("cargo:rustc-env=SYD_GITHEAD={head}");
}