24 lines
811 B
Rust
24 lines
811 B
Rust
use std::{fs, path::PathBuf, process::Command};
|
|
|
|
// https://stackoverflow.com/a/44407625
|
|
fn main() {
|
|
let output = Command::new("git")
|
|
.args(&["rev-parse", "HEAD"])
|
|
.output()
|
|
.unwrap();
|
|
let git_hash = String::from_utf8(output.stdout).unwrap();
|
|
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:rerun-if-changed={}", path);
|
|
}
|
|
}
|
|
Err(err) => {
|
|
println!("cargo::warning=Failed to read .git/HEAD: {}", err);
|
|
}
|
|
}
|
|
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
|
|
}
|