//! 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 { 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}"); } } }