2020-07-06 01:15:07 +00:00
|
|
|
use flate2::{Compression, GzBuilder};
|
|
|
|
use std::ffi::OsStr;
|
|
|
|
use std::fs;
|
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
compress_man();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn compress_man() {
|
|
|
|
let out_path = Path::new(&std::env::var("OUT_DIR").unwrap()).join("man.tgz");
|
|
|
|
let dst = fs::File::create(out_path).unwrap();
|
|
|
|
let encoder = GzBuilder::new()
|
|
|
|
.filename("man.tar")
|
|
|
|
.write(dst, Compression::best());
|
|
|
|
let mut ar = tar::Builder::new(encoder);
|
2020-08-07 21:46:15 +00:00
|
|
|
ar.mode(tar::HeaderMode::Deterministic);
|
2020-07-06 01:15:07 +00:00
|
|
|
|
|
|
|
let mut add_files = |dir, extension| {
|
2020-08-07 21:46:15 +00:00
|
|
|
let mut files = fs::read_dir(dir)
|
|
|
|
.unwrap()
|
|
|
|
.map(|e| e.unwrap().path())
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
files.sort();
|
|
|
|
for path in files {
|
2020-07-06 01:15:07 +00:00
|
|
|
if path.extension() != Some(extension) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
println!("cargo:rerun-if-changed={}", path.display());
|
|
|
|
ar.append_path_with_name(&path, path.file_name().unwrap())
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
add_files(Path::new("src/etc/man"), OsStr::new("1"));
|
|
|
|
add_files(Path::new("src/doc/man/generated_txt"), OsStr::new("txt"));
|
|
|
|
let encoder = ar.into_inner().unwrap();
|
|
|
|
encoder.finish().unwrap();
|
|
|
|
}
|