forked from rakaly/ck3save
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
31 lines (27 loc) · 1.08 KB
/
build.rs
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
use std::env;
use std::fs::File;
use std::io::{BufRead, BufReader, BufWriter, Write};
use std::path::Path;
fn main() {
let out_path = Path::new(&env::var("OUT_DIR").unwrap()).join("gen_tokens.rs");
let mut writer = BufWriter::new(File::create(&out_path).unwrap());
writeln!(writer, "match token {{").unwrap();
println!("cargo:rerun-if-env-changed=CK3_IRONMAN_TOKENS");
match env::var("CK3_IRONMAN_TOKENS") {
Ok(v) if !v.is_empty() => {
println!("cargo:rustc-cfg=ironman");
println!("cargo:rerun-if-changed={}", v);
let file = File::open(&v).unwrap();
let mut reader = BufReader::new(file);
let mut line = String::new();
while reader.read_line(&mut line).unwrap() != 0 {
let (token_val, token_s) = line.split_once(' ').unwrap();
writeln!(writer, "{} => Some(\"{}\"),", token_val, token_s.trim()).unwrap();
line.clear();
}
}
_ => {}
}
writeln!(writer, "_ => None,").unwrap();
writeln!(writer, "}}").unwrap();
}