2019-08-20 00:04:25 +02:00
|
|
|
use std::path::PathBuf;
|
|
|
|
use std::{env, fs};
|
2019-12-22 23:42:04 +01:00
|
|
|
use walkdir::WalkDir;
|
2019-08-20 00:04:25 +02:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// The src directory (we are in src/tools/error_index_generator)
|
|
|
|
// Note that we could skip one of the .. but this ensures we at least loosely find the right
|
|
|
|
// directory.
|
|
|
|
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
|
|
|
|
let dest = out_dir.join("error_codes.rs");
|
|
|
|
|
2020-08-28 05:58:48 +02:00
|
|
|
let error_codes_path = "../../../compiler/rustc_error_codes/src/error_codes.rs";
|
2019-11-13 15:27:59 +01:00
|
|
|
|
|
|
|
println!("cargo:rerun-if-changed={}", error_codes_path);
|
2019-12-22 23:42:04 +01:00
|
|
|
let file = fs::read_to_string(error_codes_path)
|
|
|
|
.unwrap()
|
|
|
|
.replace(": include_str!(\"./error_codes/", ": include_str!(\"./");
|
2019-11-13 15:27:59 +01:00
|
|
|
let contents = format!("(|| {{\n{}\n}})()", file);
|
|
|
|
fs::write(&out_dir.join("all_error_codes.rs"), &contents).unwrap();
|
2019-08-20 00:04:25 +02:00
|
|
|
|
2019-11-13 15:27:59 +01:00
|
|
|
// We copy the md files as well to the target directory.
|
2020-08-28 05:58:48 +02:00
|
|
|
for entry in WalkDir::new("../../../compiler/rustc_error_codes/src/error_codes") {
|
2019-11-13 15:27:59 +01:00
|
|
|
let entry = entry.unwrap();
|
|
|
|
match entry.path().extension() {
|
|
|
|
Some(s) if s == "md" => {}
|
|
|
|
_ => continue,
|
2019-08-20 00:04:25 +02:00
|
|
|
}
|
2019-11-13 15:27:59 +01:00
|
|
|
println!("cargo:rerun-if-changed={}", entry.path().to_str().unwrap());
|
|
|
|
let md_content = fs::read_to_string(entry.path()).unwrap();
|
|
|
|
fs::write(&out_dir.join(entry.file_name()), &md_content).unwrap();
|
2019-08-20 00:04:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
let mut all = String::new();
|
2019-12-22 23:42:04 +01:00
|
|
|
all.push_str(
|
|
|
|
r###"
|
2019-09-04 04:04:01 +02:00
|
|
|
fn register_all() -> Vec<(&'static str, Option<&'static str>)> {
|
|
|
|
let mut long_codes: Vec<(&'static str, Option<&'static str>)> = Vec::new();
|
|
|
|
macro_rules! register_diagnostics {
|
|
|
|
($($ecode:ident: $message:expr,)*) => (
|
|
|
|
register_diagnostics!{$($ecode:$message,)* ;}
|
|
|
|
);
|
2019-08-20 00:04:25 +02:00
|
|
|
|
2019-09-04 04:04:01 +02:00
|
|
|
($($ecode:ident: $message:expr,)* ; $($code:ident,)*) => (
|
|
|
|
$(
|
|
|
|
{long_codes.extend([
|
2019-09-13 12:37:29 +02:00
|
|
|
(stringify!($ecode), Some($message)),
|
2019-09-04 04:04:01 +02:00
|
|
|
].iter());}
|
|
|
|
)*
|
|
|
|
$(
|
|
|
|
{long_codes.extend([
|
|
|
|
stringify!($code),
|
|
|
|
].iter().cloned().map(|s| (s, None)).collect::<Vec<_>>());}
|
|
|
|
)*
|
|
|
|
)
|
2019-08-20 00:04:25 +02:00
|
|
|
}
|
2019-12-22 23:42:04 +01:00
|
|
|
"###,
|
|
|
|
);
|
2019-11-13 15:27:59 +01:00
|
|
|
all.push_str(r#"include!(concat!(env!("OUT_DIR"), "/all_error_codes.rs"));"#);
|
2019-08-20 00:04:25 +02:00
|
|
|
all.push_str("\nlong_codes\n");
|
|
|
|
all.push_str("}\n");
|
|
|
|
|
|
|
|
fs::write(&dest, all).unwrap();
|
|
|
|
}
|