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
87
88
89
90
//! Compile-time build-info helpers shared by the three projector binaries
//! (`cellos-projector`, `cellos-state-server`, `cellos-audit-justification`).
//!
//! P4-03 introduces a uniform `--version` / `-V` handler across CellOS
//! binaries with the format:
//!
//! ```text
//! <binary-name> <semver> (<short-build-sha>)
//! ```
//!
//! The binary name is supplied by the caller (each `main.rs` knows its own
//! `[[bin]]` name); semver comes from `CARGO_PKG_VERSION`; the short SHA
//! falls back to `unknown` for local dev builds where the release pipeline
//! has not exported a commit stamp.
/// Build SHA stamped at compile time. Prefer `VERGEN_GIT_SHA` (set by a
/// `vergen`-style build script when present); fall back to the `GIT_COMMIT`
/// env var the release pipeline already exports. `unknown` is fine for local
/// dev builds — release attestation hits the env-var path.
pub const BUILD_SHA: &str = match option_env! ;
/// Truncate the build SHA to the conventional 7-character short form.
/// Inputs shorter than 7 chars (including `unknown`) are returned unchanged.
/// Format the standard P4-03 version line for a given binary name.
///
/// ```text
/// <binary> <semver> (<short-sha>)
/// ```
///
/// `binary` is taken as a parameter rather than read from `argv[0]` so the
/// format is stable regardless of how the binary was invoked (path, symlink,
/// `busybox`-style multi-call dispatch).
/// Inspect `argv[1]` for `--version` / `-V`; if present, print the version
/// line for `binary` (using `CARGO_PKG_VERSION` of the calling crate, passed
/// in as `semver`) and return `true`. Returns `false` (and prints nothing)
/// when no version flag is present.
///
/// `semver` is supplied by the caller because `env!("CARGO_PKG_VERSION")`
/// resolves at the *call site* — that's the calling binary's version, which
/// is what we want, not the library crate's version.