1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//! Build-time provenance embedding (D-20, Phase 17d; CR-02 fix, 17-11).
//!
//! Shells out to `git` to capture the commit and dirty flag, then embeds
//! them as compile-time env vars via `cargo:rustc-env` so
//! `crates/devflow-cli/src` can read them with `env!(...)` at runtime
//! (consumed by `workflow_started`'s payload and the staleness check).
//!
//! Hand-rolled per D-20 — no `[build-dependencies]` (no `vergen`, `git2`,
//! `chrono`/`time`). Must never fail the build when git metadata is
//! unavailable (e.g. a `cargo install` from crates.io with no `.git`
//! present) — absence of provenance is not staleness.
//!
//! **Always re-runs (CR-02).** `git status --porcelain` (the whole working
//! tree) and `SystemTime::now()` are inputs cargo cannot fingerprint by
//! path — no `rerun-if-changed` path expresses "the working tree changed"
//! or "time passed". The previous version watched only `HEAD`/`refs`/
//! `packed-refs`, so editing a tracked source file without moving a ref
//! left the build script's cached output stale: `DEVFLOW_BUILD_DIRTY`
//! stayed `false` after an edit that should have flipped it `true`. It was
//! masked on a developer machine by accident — `.git/packed-refs` doesn't
//! exist locally, and cargo treats a missing `rerun-if-changed` path as
//! *always rerun* — but any `git gc` or CI checkout (which packs refs)
//! exposed it (17-REVIEW.md CR-02).
//!
//! The fix: declare a single sentinel path that can never exist, so cargo
//! always reruns this script. That alone would recompile `devflow-cli` on
//! every build if the embedded `rustc-env` values changed every run — but
//! the previous version's per-second `DEVFLOW_BUILD_TIMESTAMP` was the only
//! thing that did that. Dropping it (see below) means `rustc-env` only
//! changes when the commit or the dirty flag actually changes, so
//! always-rerunning this script (a few cheap git calls) does not cause
//! spurious recompiles of the crate it builds for.
use ;
use Command;
/// Shell out to `git` with an argv-array `Command` (never `sh -c` string
/// interpolation). Returns `None` on any failure — missing `git` binary,
/// non-git directory, non-zero exit — so the build never panics or fails
/// when git metadata is unavailable.