Fix git build script
This commit is contained in:
parent
b7e33dc4b4
commit
320fcdca43
@ -1,4 +1,4 @@
|
||||
use std::process::Command;
|
||||
use std::{fs, path::PathBuf, process::Command};
|
||||
|
||||
// https://stackoverflow.com/a/44407625
|
||||
fn main() {
|
||||
@ -7,6 +7,17 @@ fn main() {
|
||||
.output()
|
||||
.unwrap();
|
||||
let git_hash = String::from_utf8(output.stdout).unwrap();
|
||||
println!("cargo:rustc-rerun-if-changed=.git/HEAD");
|
||||
match fs::read_to_string("../.git/HEAD") {
|
||||
Ok(contents) => {
|
||||
if let Some(branch_path) = contents.split(" ").skip(1).next() {
|
||||
let path = PathBuf::from(".git").join(branch_path);
|
||||
let path = path.to_str().unwrap_or(".git/HEAD");
|
||||
println!("cargo:rustc-rerun-if-changed={}", path);
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
println!("cargo::warning=Failed to read .git/HEAD: {}", err);
|
||||
}
|
||||
}
|
||||
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user