]>
git.proxmox.com Git - cargo.git/blob - build.rs
1 use flate2
::{Compression, GzBuilder}
;
5 use std
::process
::Command
;
11 "cargo:rustc-env=RUST_HOST_TARGET={}",
12 std
::env
::var("TARGET").unwrap()
17 let out_path
= Path
::new(&std
::env
::var("OUT_DIR").unwrap()).join("man.tgz");
18 let dst
= fs
::File
::create(out_path
).unwrap();
19 let encoder
= GzBuilder
::new()
21 .write(dst
, Compression
::best());
22 let mut ar
= tar
::Builder
::new(encoder
);
23 ar
.mode(tar
::HeaderMode
::Deterministic
);
25 let mut add_files
= |dir
, extension
| {
26 let mut files
= fs
::read_dir(dir
)
28 .map(|e
| e
.unwrap().path())
32 if path
.extension() != Some(extension
) {
35 println
!("cargo:rerun-if-changed={}", path
.display());
36 ar
.append_path_with_name(&path
, path
.file_name().unwrap())
41 add_files(Path
::new("src/etc/man"), OsStr
::new("1"));
42 add_files(Path
::new("src/doc/man/generated_txt"), OsStr
::new("txt"));
43 let encoder
= ar
.into_inner().unwrap();
44 encoder
.finish().unwrap();
48 if !Path
::new(".git").exists() {
51 let output
= match Command
::new("git")
55 .arg("--format=%H %h %cd")
59 Ok(output
) if output
.status
.success() => output
,
62 let stdout
= String
::from_utf8(output
.stdout
).unwrap();
63 let mut parts
= stdout
.split_whitespace();
64 let mut next
= || parts
.next().unwrap();
65 println
!("cargo:rustc-env=CARGO_COMMIT_HASH={}", next());
66 println
!("cargo:rustc-env=CARGO_COMMIT_SHORT_HASH={}", next());
67 println
!("cargo:rustc-env=CARGO_COMMIT_DATE={}", next())