7 use std::process::Command;
12 let out_dir = env::var("OUT_DIR").unwrap();
13 let dest_path = Path::new(&out_dir).join("git_info.rs");
14 let mut f = File::create(&dest_path).unwrap();
17 "const COMMIT_HASH: Option<&'static str> = {:?};",
21 "const WORKTREE_CLEAN: Option<bool> = {:?};",
25 // cargo:rerun-if-changed requires one entry per individual file.
26 for entry in WalkDir::new("src") {
27 let entry = entry.unwrap();
28 println!("cargo:rerun-if-changed={}", entry.path().display());
32 // Returns `None` if git is not available.
33 fn git_head_sha1() -> Option<String> {
40 .and_then(|o| String::from_utf8(o.stdout).ok())
42 let len = s.trim_right().len();
48 // Returns `None` if git is not available.
49 fn git_tree_is_clean() -> Option<bool> {
53 .arg("--untracked-files=no")
56 .map(|o| o.stdout.is_empty())