]>
Commit | Line | Data |
---|---|---|
0e26eae5 EH |
1 | use flate2::{Compression, GzBuilder}; |
2 | use std::ffi::OsStr; | |
3 | use std::fs; | |
4 | use std::path::Path; | |
5 | ||
6 | fn main() { | |
7 | compress_man(); | |
c5318a17 EH |
8 | println!( |
9 | "cargo:rustc-env=RUST_HOST_TARGET={}", | |
10 | std::env::var("TARGET").unwrap() | |
11 | ); | |
0e26eae5 EH |
12 | } |
13 | ||
14 | fn compress_man() { | |
15 | let out_path = Path::new(&std::env::var("OUT_DIR").unwrap()).join("man.tgz"); | |
16 | let dst = fs::File::create(out_path).unwrap(); | |
17 | let encoder = GzBuilder::new() | |
18 | .filename("man.tar") | |
19 | .write(dst, Compression::best()); | |
20 | let mut ar = tar::Builder::new(encoder); | |
624acc8e | 21 | ar.mode(tar::HeaderMode::Deterministic); |
0e26eae5 EH |
22 | |
23 | let mut add_files = |dir, extension| { | |
624acc8e AC |
24 | let mut files = fs::read_dir(dir) |
25 | .unwrap() | |
26 | .map(|e| e.unwrap().path()) | |
27 | .collect::<Vec<_>>(); | |
28 | files.sort(); | |
29 | for path in files { | |
0e26eae5 EH |
30 | if path.extension() != Some(extension) { |
31 | continue; | |
32 | } | |
33 | println!("cargo:rerun-if-changed={}", path.display()); | |
34 | ar.append_path_with_name(&path, path.file_name().unwrap()) | |
35 | .unwrap(); | |
36 | } | |
37 | }; | |
38 | ||
39 | add_files(Path::new("src/etc/man"), OsStr::new("1")); | |
40 | add_files(Path::new("src/doc/man/generated_txt"), OsStr::new("txt")); | |
41 | let encoder = ar.into_inner().unwrap(); | |
42 | encoder.finish().unwrap(); | |
43 | } |