]> git.proxmox.com Git - rustc.git/blame - src/tools/error_index_generator/build.rs
New upstream version 1.62.1+dfsg1
[rustc.git] / src / tools / error_index_generator / build.rs
CommitLineData
e1599b0c
XL
1use std::path::PathBuf;
2use std::{env, fs};
dfeec247 3use walkdir::WalkDir;
e1599b0c
XL
4
5fn main() {
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
8 // directory.
9 let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
e1599b0c 10
1b1a35ee 11 let error_codes_path = "../../../compiler/rustc_error_codes/src/error_codes.rs";
60c5eb7d
XL
12
13 println!("cargo:rerun-if-changed={}", error_codes_path);
dfeec247
XL
14 let file = fs::read_to_string(error_codes_path)
15 .unwrap()
16 .replace(": include_str!(\"./error_codes/", ": include_str!(\"./");
60c5eb7d
XL
17 let contents = format!("(|| {{\n{}\n}})()", file);
18 fs::write(&out_dir.join("all_error_codes.rs"), &contents).unwrap();
e1599b0c 19
60c5eb7d 20 // We copy the md files as well to the target directory.
1b1a35ee 21 for entry in WalkDir::new("../../../compiler/rustc_error_codes/src/error_codes") {
60c5eb7d
XL
22 let entry = entry.unwrap();
23 match entry.path().extension() {
24 Some(s) if s == "md" => {}
25 _ => continue,
e1599b0c 26 }
60c5eb7d
XL
27 println!("cargo:rerun-if-changed={}", entry.path().to_str().unwrap());
28 let md_content = fs::read_to_string(entry.path()).unwrap();
29 fs::write(&out_dir.join(entry.file_name()), &md_content).unwrap();
e1599b0c 30 }
e1599b0c 31}