2 use std::path::PathBuf;
6 // The src directory (we are in src/tools/error_index_generator)
7 // Note that we could skip one of the .. but this ensures we at least loosely find the right
9 let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
10 let dest = out_dir.join("error_codes.rs");
12 for entry in WalkDir::new("../../../src") {
13 let entry = entry.unwrap();
14 if entry.file_name() == "error_codes.rs" {
15 println!("cargo:rerun-if-changed={}", entry.path().to_str().unwrap());
16 let file = fs::read_to_string(entry.path()).unwrap()
17 .replace("syntax::register_diagnostics!", "register_diagnostics!");
18 let contents = format!("(|| {{\n{}\n}})()", file);
20 fs::write(&out_dir.join(&format!("error_{}.rs", idx)), &contents).unwrap();
26 let mut all = String::new();
28 fn register_all() -> Vec<(&'static str, Option<&'static str>)> {
29 let mut long_codes: Vec<(&'static str, Option<&'static str>)> = Vec::new();
30 macro_rules! register_diagnostics {
31 ($($ecode:ident: $message:expr,)*) => (
32 register_diagnostics!{$($ecode:$message,)* ;}
35 ($($ecode:ident: $message:expr,)* ; $($code:ident,)*) => (
38 (stringify!($ecode), Some($message)),
44 ].iter().cloned().map(|s| (s, None)).collect::<Vec<_>>());}
50 all.push_str(&format!(r#"include!(concat!(env!("OUT_DIR"), "/error_{}.rs"));"#, idx));
53 all.push_str("\nlong_codes\n");
56 fs::write(&dest, all).unwrap();