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