build.rs: tell cargo to only rerun build.rs step if .git/HEAD changes

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2021-07-20 12:29:56 +02:00
parent 847c27fbee
commit 61a758f67d
1 changed files with 2 additions and 0 deletions

View File

@ -12,10 +12,12 @@ fn git_command(args: &[&str]) -> String {
} }
fn main() { fn main() {
let repo_path = git_command(&["rev-parse", "--show-toplevel"]);
let repoid = match env::var("REPOID") { let repoid = match env::var("REPOID") {
Ok(repoid) => repoid, Ok(repoid) => repoid,
Err(_) => git_command(&["rev-parse", "HEAD"]), Err(_) => git_command(&["rev-parse", "HEAD"]),
}; };
println!("cargo:rustc-env=REPOID={}", repoid); println!("cargo:rustc-env=REPOID={}", repoid);
println!("cargo:rerun-if-changed={}/.git/HEAD", repo_path);
} }