-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathbuild.rs
More file actions
65 lines (47 loc) · 1.67 KB
/
build.rs
File metadata and controls
65 lines (47 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use clap::CommandFactory;
use clap_mangen::Man;
use std::env;
use std::fs::File;
use std::io::Error;
use std::io::Write;
use std::path::Path;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let out_dir = env::var("OUT_DIR").unwrap();
// Bundling files as resources in Whamm for library usage!
let out_path = Path::new(&out_dir).join("bundled.rs");
let mut out_file = File::create(&out_path).unwrap();
// -- bundle the provider definitions
let defs_dir = "./";
bundle_defs(defs_dir, &mut out_file, "DEF_YAMLS");
// Build the CLI manual.
println!("cargo:rerun-if-changed=src/cli.rs");
println!("cargo:rerun-if-changed=man");
// Create `target/assets/` folder.
let cli_out_path = Path::new(&out_dir).join("assets");
fs::create_dir_all(&cli_out_path).unwrap();
build_man(&cli_out_path)?;
Ok(())
}
// ================================
// ====== Bundling Resources ======
// ================================
include!("src/parser/yml_processor.rs");
fn bundle_defs(base_dir: &str, out_file: &mut File, var_name: &str) {
let defs = pull_all_yml_files(base_dir);
writeln!(out_file, "pub static {var_name}: &[&str] = &[").unwrap();
for def in defs.iter() {
writeln!(out_file, " {:?},", def).unwrap();
}
writeln!(out_file, "];").unwrap();
}
// ==================================
// ====== Build the CLI Manual ======
// ==================================
include!("src/cli.rs");
fn build_man(out_dir: &Path) -> Result<(), Error> {
let app = WhammCli::command();
let file = Path::new(&out_dir).join("example.1");
let mut file = File::create(file)?;
Man::new(app).render(&mut file)?;
Ok(())
}