-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbuild.rs
More file actions
30 lines (27 loc) · 1.11 KB
/
Copy pathbuild.rs
File metadata and controls
30 lines (27 loc) · 1.11 KB
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
use std::process::Command;
fn main() {
// Git short hash — so `octoscode --version` identifies the exact build
// (a branch/dev build reports e.g. `0.2.2-rc.7 (94e43fd …)`), mirroring the
// octos server. Without it, an unreleased branch build is indistinguishable
// from the published release of the same Cargo version.
let hash = Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
.ok()
.filter(|o| o.status.success())
.map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string())
.unwrap_or_default();
println!("cargo:rustc-env=OCTOSCODE_GIT_HASH={hash}");
// Build date (YYYY-MM-DD)
let date = Command::new("date")
.arg("+%Y-%m-%d")
.output()
.ok()
.filter(|o| o.status.success())
.map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string())
.unwrap_or_default();
println!("cargo:rustc-env=OCTOSCODE_BUILD_DATE={date}");
// Re-run if git HEAD changes.
println!("cargo:rerun-if-changed=.git/HEAD");
println!("cargo:rerun-if-changed=.git/refs/heads/");
}