2021-05-06 11:00:03 +00:00
|
|
|
// build.rs
|
|
|
|
use std::env;
|
|
|
|
use std::process::Command;
|
|
|
|
|
2021-07-20 10:29:23 +00:00
|
|
|
fn git_command(args: &[&str]) -> String {
|
|
|
|
match Command::new("git").args(args).output() {
|
|
|
|
Ok(output) => String::from_utf8(output.stdout).unwrap().trim_end().to_string(),
|
|
|
|
Err(err) => {
|
|
|
|
panic!("git {:?} failed: {}", args, err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-06 11:00:03 +00:00
|
|
|
fn main() {
|
2021-07-20 10:29:56 +00:00
|
|
|
let repo_path = git_command(&["rev-parse", "--show-toplevel"]);
|
2021-05-06 11:00:03 +00:00
|
|
|
let repoid = match env::var("REPOID") {
|
|
|
|
Ok(repoid) => repoid,
|
2021-07-20 10:29:23 +00:00
|
|
|
Err(_) => git_command(&["rev-parse", "HEAD"]),
|
2021-05-06 11:00:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
println!("cargo:rustc-env=REPOID={}", repoid);
|
2021-07-20 10:29:56 +00:00
|
|
|
println!("cargo:rerun-if-changed={}/.git/HEAD", repo_path);
|
2021-05-06 11:00:03 +00:00
|
|
|
}
|