Files
OpenFUT/openfut-blaze-host/build.rs
T
funman300 468b006008 blaze-host: scope the dirty-tree check to the crates the binary is built from
A whole-repo check read DIRTY permanently, because unrelated submodules carry
pre-existing modifications. A warning that is always on is a warning nobody
reads, which defeats the point: the flag exists so a mutated build announces
itself before it can be mistaken for parity evidence.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-11 01:55:20 +00:00

62 lines
2.3 KiB
Rust

//! Stamp build identity into the binary.
//!
//! A live FIFA trace has to be attributable to an exact binary. During the
//! mutation runs for the previous step, four sidecars were left listening —
//! two of them serving deliberately broken builds — and nothing in their output
//! said so. A later A/B against one of those would have read as a genuine
//! parity failure.
//!
//! So the host prints its commit, working-tree cleanliness and profile at
//! startup, and `dirty` is the important one: a mutation-tested build is a
//! dirty build, and now it announces itself.
use std::process::Command;
fn git(args: &[&str]) -> Option<String> {
let out = Command::new("git").args(args).output().ok()?;
if !out.status.success() {
return None;
}
Some(String::from_utf8_lossy(&out.stdout).trim().to_string())
}
fn main() {
let commit = git(&["rev-parse", "--short=7", "HEAD"]).unwrap_or_else(|| "unknown".into());
// Scoped to the crates this binary is actually built from.
//
// A whole-repo check reads DIRTY permanently here, because unrelated
// submodules carry pre-existing modifications. A warning that is always on
// is a warning nobody reads — which would defeat the point, since the whole
// job of this flag is to make a mutated build announce itself.
//
// Untracked files are excluded: scratch output is not a build difference,
// but an edited source file certainly is.
let dirty = match git(&[
"status",
"--porcelain",
"--untracked-files=no",
"--",
"openfut-blaze-host",
"openfut-adapter-fifa17",
"openfut-protocol-blaze",
]) {
Some(s) if !s.is_empty() => "DIRTY",
Some(_) => "clean",
None => "unknown",
};
println!("cargo:rustc-env=OPENFUT_BUILD_COMMIT={commit}");
println!("cargo:rustc-env=OPENFUT_BUILD_DIRTY={dirty}");
// Re-stamp when HEAD moves. Working-tree edits are not tracked by cargo's
// dependency graph, so `dirty` can go stale until something forces a
// rebuild — the startup banner says which commit it was stamped from, and
// the sidecar script re-checks the working tree independently at launch.
for p in ["../.git/HEAD", "../.git/index"] {
if std::path::Path::new(p).exists() {
println!("cargo:rerun-if-changed={p}");
}
}
}