-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
39 lines (33 loc) · 1.01 KB
/
build.rs
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
use std::process::Command;
fn main() {
let mut version = format!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
let git_available = matches!(
Command::new("git")
.arg("-v")
.status()
.map(|status| status.success()),
Ok(true)
);
if git_available {
let sha = Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
.expect("git rev-parse")
.stdout;
let sha = String::from_utf8(sha).unwrap();
let sha = sha.trim();
let dirty = Command::new("git")
.args(["status", "--porcelain"])
.output()
.expect("git status")
.stdout;
let dirty = String::from_utf8(dirty).unwrap();
let dirty = if dirty.trim().is_empty() {
""
} else {
"-dirty"
};
version.push_str(&format!(" ({sha}{dirty})"));
}
println!("cargo:rustc-env=BBL2CSV_VERSION={version}");
}