]> git.proxmox.com Git - cargo.git/blobdiff - build.rs
Auto merge of #11257 - arlosi:build-deadlock-1.65.0, r=weihanglo
[cargo.git] / build.rs
index 68865b58fcf91ce7fea46e6907506ad77df2c804..13e88935e09967310a9cf8da3005f521faddc68a 100644 (file)
--- a/build.rs
+++ b/build.rs
@@ -2,8 +2,10 @@ use flate2::{Compression, GzBuilder};
 use std::ffi::OsStr;
 use std::fs;
 use std::path::Path;
+use std::process::Command;
 
 fn main() {
+    commit_info();
     compress_man();
     println!(
         "cargo:rustc-env=RUST_HOST_TARGET={}",
@@ -41,3 +43,26 @@ fn compress_man() {
     let encoder = ar.into_inner().unwrap();
     encoder.finish().unwrap();
 }
+
+fn commit_info() {
+    if !Path::new(".git").exists() {
+        return;
+    }
+    let output = match Command::new("git")
+        .arg("log")
+        .arg("-1")
+        .arg("--date=short")
+        .arg("--format=%H %h %cd")
+        .arg("--abbrev=9")
+        .output()
+    {
+        Ok(output) if output.status.success() => output,
+        _ => return,
+    };
+    let stdout = String::from_utf8(output.stdout).unwrap();
+    let mut parts = stdout.split_whitespace();
+    let mut next = || parts.next().unwrap();
+    println!("cargo:rustc-env=CARGO_COMMIT_HASH={}", next());
+    println!("cargo:rustc-env=CARGO_COMMIT_SHORT_HASH={}", next());
+    println!("cargo:rustc-env=CARGO_COMMIT_DATE={}", next())
+}