use std::env;
use std::fs;
use std::path::Path;
use std::process::Command;
fn main()
{
let out_dir= env::var_os("OUT_DIR").unwrap();
let git_describe=Command::new("git")
.arg("describe")
.arg("--dirty")
.arg("--always")
.arg("--all")
.output();
let git_rev=Command::new("git")
.arg("rev-parse")
.arg("--verify")
.arg("HEAD")
.output();
let id_str=vec![git_describe,git_rev].iter().filter_map(|x|match x{
Ok(output) => Some(String::from_utf8_lossy(&output.stdout).trim().to_string()),
Err(_) => None,
}).collect::<Vec<String>>().join("-");
let git_id_path = Path::new(&out_dir).join("generated_git_id");
fs::write(&git_id_path,id_str).expect("failed to write git_id");
}