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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//! Two independent, unconditional jobs: guarantee the dashboard asset folder
//! exists before the `ui` feature's embed macro runs, and stamp the build
//! with the source commit `GET /v1/capabilities` reports.
//!
//! ## The dashboard asset shim
//!
//! rust-embed's derive requires its `folder` to exist at compile time. A fresh
//! checkout that has not run `salvor build` yet has no `bridge/dist` tree, and
//! a build with the `ui` feature would then fail to compile at all. Creating
//! the folder here keeps that build honest: an empty folder embeds no files, so
//! the server answers `/` with the plain-text "built without the dashboard"
//! note instead of failing to build.
//!
//! This half runs only when the `ui` feature is active (Cargo sets
//! `CARGO_FEATURE_UI`); a headless build touches nothing.
//!
//! ## The commit stamp
//!
//! `lib.rs`'s capabilities handler wants a short commit hash alongside
//! `env!("CARGO_PKG_VERSION")`, but a version number is compile-time-constant
//! for a crate while a commit hash is a fact about the CHECKOUT, not the
//! crate, so it has to be shelled out for and threaded through as an
//! environment variable (`SALVOR_SERVER_GIT_COMMIT`) the handler reads with
//! `option_env!`. This runs unconditionally (not gated on the `ui` feature):
//! the version/commit stamp is a headless-server fact too.
//!
//! Degrades honestly: a source tarball with no `.git`, or a checkout with no
//! `git` on PATH, sets no environment variable at all, so
//! `option_env!("SALVOR_SERVER_GIT_COMMIT")` is `None` and the handler omits
//! the `commit` key entirely rather than printing a placeholder like
//! `"unknown"`. A non-clean working tree at build time (`git status
//! --porcelain` prints anything at all: modified tracked files, staged
//! changes, OR untracked files sitting in the tree) appends `-dirty` to the
//! hash; this is a snapshot taken when the build script last ran, not a live
//! fact, because Cargo only reruns a build script when its declared
//! `rerun-if-changed` inputs change — here, `.git/HEAD` and `.git/index`
//! (checkouts, commits, and staged/unstaged
//! changes to already-tracked files all touch one of the two). Editing a
//! tracked file without staging it will not by itself trigger a rerun; this
//! is the same staleness every git-describe-based version stamp accepts.
use Path;
use Command;