-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.rs
More file actions
30 lines (25 loc) · 1 KB
/
build.rs
File metadata and controls
30 lines (25 loc) · 1 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
use std::collections::HashSet;
use std::path::Path;
use std::fs::File;
pub fn main() {
// collect names
let mut names = HashSet::new();
let re = regex::Regex::new(r"name!\(([a-zA-Z0-9_]*)\)").unwrap();
for entry in walkdir::WalkDir::new("src")
.into_iter()
.filter_map(Result::ok)
.filter(|e| !e.file_type().is_dir()) {
let text = std::fs::read_to_string(entry.path()).unwrap();
for caps in re.captures_iter(&text) {
names.insert(caps.get(1).map(|m| m.as_str()).unwrap().to_string());
}
}
// update names.rs
let mut namestr = String::new();
for name in names {
namestr += &name;
namestr += ",\n ";
}
let namestr = format!("// don't modify this file by hand, it is automatically generated by build.rs, for nametag.\n\n#[macro_export] macro_rules! name {{ ($i:ident) => {{crate::names::$i}} }}\n\nnametag::setup_names! {{\n {}\n}}", namestr);
std::fs::write("src/names.rs", namestr).unwrap();
}