-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathbuild.rs
More file actions
38 lines (33 loc) · 1.3 KB
/
build.rs
File metadata and controls
38 lines (33 loc) · 1.3 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
31
32
33
34
35
36
37
38
use std::process::Command;
fn main() {
if std::env::var_os("LIBLOOT_REVISION").is_some() {
return;
}
println!("cargo:rerun-if-changed=.git/HEAD");
println!("cargo:rerun-if-changed=build.rs");
let Ok(git_rev_parse_output) = Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
else {
println!("cargo:warning=Calling git rev-parse failed, LIBLOOT_REVISION will be unset!");
return;
};
if let Ok(git_hash) = String::from_utf8(git_rev_parse_output.stdout) {
println!("cargo:rustc-env=LIBLOOT_REVISION={git_hash}");
} else {
println!(
"cargo:warning=Could not convert git rev-parse output to a UTF-8 string, LIBLOOT_REVISION will be unset!"
);
}
// Don't warn if this errors, as it will error if HEAD points directly to a commit.
if let Ok(git_symbolic_ref_output) = Command::new("git").args(["symbolic-ref", "HEAD"]).output()
{
if let Ok(symbolic_ref) = String::from_utf8(git_symbolic_ref_output.stdout) {
println!("cargo:rerun-if-changed=.git/{symbolic_ref}");
} else {
println!(
"cargo:warning=Could not convert git symbolic-ref output to a UTF-8 string, LIBLOOT_REVISION may become stale!"
);
}
}
}