X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=build.rs;h=13e88935e09967310a9cf8da3005f521faddc68a;hb=4bc8f24d3e899462e43621aab981f6383a370365;hp=0542fef11b498d75ed6d0264a503373d0f9993bd;hpb=2732539e8548fd0db65ad51ceb049f23d2f3b931;p=cargo.git diff --git a/build.rs b/build.rs index 0542fef11..13e88935e 100644 --- a/build.rs +++ b/build.rs @@ -2,9 +2,15 @@ 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={}", + std::env::var("TARGET").unwrap() + ); } fn compress_man() { @@ -14,10 +20,15 @@ fn compress_man() { .filename("man.tar") .write(dst, Compression::best()); let mut ar = tar::Builder::new(encoder); + ar.mode(tar::HeaderMode::Deterministic); let mut add_files = |dir, extension| { - for entry in fs::read_dir(dir).unwrap() { - let path = entry.unwrap().path(); + let mut files = fs::read_dir(dir) + .unwrap() + .map(|e| e.unwrap().path()) + .collect::>(); + files.sort(); + for path in files { if path.extension() != Some(extension) { continue; } @@ -32,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()) +}