use std::process::Command;
fn main() {
for rel in ["HEAD", "refs"] {
if let Some(path) = git_path(rel) {
println!("cargo:rerun-if-changed={path}");
}
}
let version = describe().unwrap_or_else(cargo_version);
println!("cargo:rustc-env=TEAMCTL_BUILD_VERSION={version}");
}
fn describe() -> Option<String> {
let out = Command::new("git")
.args(["describe", "--tags", "--always", "--dirty"])
.output()
.ok()?;
if !out.status.success() {
return None;
}
let raw = String::from_utf8(out.stdout).ok()?;
let trimmed = raw.trim();
let version = trimmed.strip_prefix('v').unwrap_or(trimmed).to_string();
version.contains('.').then_some(version)
}
fn git_path(rel: &str) -> Option<String> {
let out = Command::new("git")
.args(["rev-parse", "--git-path", rel])
.output()
.ok()?;
if !out.status.success() {
return None;
}
let path = String::from_utf8(out.stdout).ok()?.trim().to_string();
(!path.is_empty()).then_some(path)
}
fn cargo_version() -> String {
std::env::var("CARGO_PKG_VERSION").unwrap_or_else(|_| "unknown".to_string())
}