mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
It only does so if git is on the PATH and `git rev-parse --short HEAD` produces a UTF-8 string, but the script should never fail.
39 lines
1.3 KiB
Rust
39 lines
1.3 KiB
Rust
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!"
|
|
);
|
|
}
|
|
}
|
|
}
|