-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
35 lines (29 loc) · 1.1 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
// https://stackoverflow.com/questions/43753491/include-git-commit-hash-as-string-into-rust-program/44407625#44407625
use std::process::Command;
fn main() {
// note: add error checking yourself.
let output = Command::new("git").args(&["rev-parse", "HEAD"]).env("LC_ALL", "C.UTF-8").output().unwrap();
if output.status.success() {
let git_hash = String::from_utf8(output.stdout).expect("git should have output an UTF8 encoded string");
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
}
else{
println!("cargo:warning=Failed to get git commit id");
}
let output = Command::new("git")
.args(["status", "--untracked-files=no", "--porcelain"])
.output().expect("git should be executed");
if output.status.success() {
println!("cargo:rustc-env=GIT_DIRTY={}",
if output.stdout.len() == 0 {
"false"
}else {
"true"
}
);
}
else {
println!("cargo:warning=Failed to check if git working tree is dirty");
}
}
// git status --untracked-files=no --porcelain