-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.rs
More file actions
32 lines (29 loc) · 897 Bytes
/
Copy pathbuild.rs
File metadata and controls
32 lines (29 loc) · 897 Bytes
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
use std::process::Command;
fn main() {
let sha = Command::new("git")
.args(["rev-parse", "--short=7", "HEAD"])
.output()
.ok()
.and_then(|o| {
o.status
.success()
.then(|| String::from_utf8(o.stdout).ok())
.flatten()
})
.map(|s| s.trim().to_string())
.unwrap_or_else(|| "unknown".to_string());
let dirty = Command::new("git")
.args(["status", "--porcelain"])
.output()
.map(|o| !o.stdout.is_empty())
.unwrap_or(false);
let suffix = if dirty && sha != "unknown" {
format!("{sha}-dirty")
} else {
sha
};
println!("cargo:rustc-env=UTTER_GIT_SHA={suffix}");
println!("cargo:rerun-if-changed=.git/HEAD");
println!("cargo:rerun-if-changed=.git/index");
println!("cargo:rerun-if-changed=build.rs");
}