-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.rs
More file actions
48 lines (44 loc) · 1.6 KB
/
Copy pathbuild.rs
File metadata and controls
48 lines (44 loc) · 1.6 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
//! Embeds every YAML scheme under `assets/themes/base16/` into the binary.
//! Runtime converts each via `theme_import::import_base16_str` so build.rs
//! stays free of project deps beyond the std fs walk.
use std::env;
use std::fs;
use std::path::PathBuf;
fn main() {
let dir: PathBuf = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("assets")
.join("themes")
.join("base16");
println!("cargo:rerun-if-changed={}", dir.display());
let mut entries: Vec<(String, String)> = Vec::new();
if let Ok(rd) = fs::read_dir(&dir) {
for e in rd.flatten() {
let p = e.path();
let ext = p.extension().and_then(|s| s.to_str()).unwrap_or("");
if ext != "yaml" && ext != "yml" {
continue;
}
let stem = p
.file_stem()
.and_then(|s| s.to_str())
.unwrap_or("scheme")
.to_string();
let body = fs::read_to_string(&p).expect("read theme yaml");
entries.push((stem, body));
}
}
entries.sort_by(|a, b| a.0.cmp(&b.0));
let out_dir = env::var_os("OUT_DIR").expect("OUT_DIR");
let out = PathBuf::from(out_dir).join("bundled_themes.rs");
let mut src = String::new();
src.push_str("pub const BUNDLED_BASE16: &[(&str, &str)] = &[\n");
for (stem, body) in &entries {
src.push_str(" (\"");
src.push_str(stem);
src.push_str("\", r####\"");
src.push_str(body);
src.push_str("\"####),\n");
}
src.push_str("];\n");
fs::write(out, src).expect("write generated");
}