Adapt error index generator to the new format

This commit is contained in:
Guillaume Gomez 2019-11-13 15:27:59 +01:00
parent ec50a750f9
commit 356da40db5
3 changed files with 21 additions and 18 deletions

View File

@ -3120,6 +3120,7 @@ dependencies = [
"graphviz",
"jobserver",
"log",
"measureme",
"num_cpus",
"parking_lot 0.9.0",
"polonius-engine",

View File

@ -1,4 +1,4 @@
er [RFC 401][rfc401], if you have a function declaration `foo`:
Per [RFC 401][rfc401], if you have a function declaration `foo`:
```
// For the purposes of this explanation, all of these

View File

@ -8,21 +8,26 @@ fn main() {
// directory.
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let dest = out_dir.join("error_codes.rs");
let mut idx = 0;
for entry in WalkDir::new("../../../src") {
let error_codes_path = "../../../src/librustc_error_codes/error_codes.rs";
println!("cargo:rerun-if-changed={}", error_codes_path);
let file = fs::read_to_string(error_codes_path).unwrap()
.replace("crate::register_diagnostics!", "register_diagnostics!")
.replace(": include_str!(\"./error_codes/", ": include_str!(\"./");
let contents = format!("(|| {{\n{}\n}})()", file);
fs::write(&out_dir.join("all_error_codes.rs"), &contents).unwrap();
// We copy the md files as well to the target directory.
for entry in WalkDir::new("../../../src/librustc_error_codes/error_codes") {
let entry = entry.unwrap();
if entry.file_name() == "error_codes.rs" {
println!("cargo:rerun-if-changed={}", entry.path().to_str().unwrap());
let file = fs::read_to_string(entry.path()).unwrap()
.replace("crate::register_diagnostics!", "register_diagnostics!")
.replace(": include_str!(\"./",
": include_str!(\"../../../../../../../../src/librustc_error_codes/");
let contents = format!("(|| {{\n{}\n}})()", file);
fs::write(&out_dir.join(&format!("error_{}.rs", idx)), &contents).unwrap();
idx += 1;
match entry.path().extension() {
Some(s) if s == "md" => {}
_ => continue,
}
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();
}
let mut all = String::new();
@ -48,10 +53,7 @@ fn register_all() -> Vec<(&'static str, Option<&'static str>)> {
)
}
"###);
for idx in 0..idx {
all.push_str(&format!(r#"include!(concat!(env!("OUT_DIR"), "/error_{}.rs"));"#, idx));
all.push_str("\n");
}
all.push_str(r#"include!(concat!(env!("OUT_DIR"), "/all_error_codes.rs"));"#);
all.push_str("\nlong_codes\n");
all.push_str("}\n");