Debian Codegraph @

build.rs

raw
1 use std::{path::Path, process::Command};
2
3 fn main() {
4 println!("cargo:rerun-if-changed=build.rs");
5
6 commit_info();
7 }
8
9 fn commit_info() {
10 if !Path::new(".git").exists() {
11 return;
12 }
13 let output = match Command::new("git")
14 .arg("log")
15 .arg("-1")
16 .arg("--date=short")
17 .arg("--format=%H %h %cd")
18 .arg("--abbrev=9")
19 .output()
20 {
21 Ok(output) if output.status.success() => output,
22 _ => return,
23 };
24 let stdout = String::from_utf8(output.stdout).unwrap();
25 let mut parts = stdout.split_whitespace();
26 let mut next = || parts.next().unwrap();
27 println!("cargo:rustc-env=CARGO_GIT_HASH={}", next());
28 println!(
29 "cargo:rustc-env=CARGO_VERSION_INFO={} ({} {})",
30 env!("CARGO_PKG_VERSION"),
31 next(),
32 next()
33 );
34 }