use std::process::Command;
fn main() {
let describe = Command::new("git")
.args([
"-c",
"safe.directory=*",
"-c",
"core.checkStat=minimal",
"-c",
"filter.lfs.required=false",
"-c",
"filter.lfs.process=",
"-c",
"filter.lfs.clean=",
"-c",
"filter.lfs.smudge=",
"describe",
"--tags",
"--always",
"--dirty=-modified",
"--abbrev=7",
])
.output()
.ok()
.filter(|o| o.status.success())
.map(|o| String::from_utf8_lossy(&o.stdout).trim().to_owned())
.filter(|s| !s.is_empty());
let mut inputs: Vec<(&str, String)> = Vec::new();
if let Some(d) = &describe {
inputs.push(("source-commit", d.clone()));
}
match gunnar_recipe::emit::write_receipt(&inputs) {
Ok(emitted) => {
if let Some(variant) = emitted.attribution.variant() {
println!("cargo:rustc-env=GUNNAR_BUILD_VARIANT={}", variant.name);
}
}
Err(e) => panic!(
"the build-thing receipt was refused: {e:#}\n\
This is a defect in gunnar-build-thing's declaration, not in this build. \
A binary that ships with a receipt its own audit would reject is worse than \
one with none, so the build stops here."
),
}
for what in ["HEAD", "refs"] {
let path = Command::new("git")
.args(["rev-parse", "--git-path", what])
.output()
.ok()
.filter(|o| o.status.success())
.map(|o| String::from_utf8_lossy(&o.stdout).trim().to_owned())
.filter(|s| !s.is_empty());
if let Some(path) = path {
if std::path::Path::new(&path).exists() {
println!("cargo:rerun-if-changed={path}");
}
}
}
}