]>
git.proxmox.com Git - rustc.git/blob - src/tools/error_index_generator/build.rs
1 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 let error_codes_path
= "../../../compiler/rustc_error_codes/src/error_codes.rs";
14 println
!("cargo:rerun-if-changed={}", error_codes_path
);
15 let file
= fs
::read_to_string(error_codes_path
)
17 .replace(": include_str!(\"./error_codes/", ": include_str!(\"./");
18 let contents
= format
!("(|| {{\n{}\n}})()", file
);
19 fs
::write(&out_dir
.join("all_error_codes.rs"), &contents
).unwrap();
21 // We copy the md files as well to the target directory.
22 for entry
in WalkDir
::new("../../../compiler/rustc_error_codes/src/error_codes") {
23 let entry
= entry
.unwrap();
24 match entry
.path().extension() {
25 Some(s
) if s
== "md" => {}
28 println
!("cargo:rerun-if-changed={}", entry
.path().to_str().unwrap());
29 let md_content
= fs
::read_to_string(entry
.path()).unwrap();
30 fs
::write(&out_dir
.join(entry
.file_name()), &md_content
).unwrap();
33 let mut all
= String
::new();
36 fn register_all() -> Vec<(&'static str, Option<&'static str>)> {
37 let mut long_codes: Vec<(&'static str, Option<&'static str>)> = Vec::new();
38 macro_rules! register_diagnostics {
39 ($($ecode:ident: $message:expr,)*) => (
40 register_diagnostics!{$($ecode:$message,)* ;}
43 ($($ecode:ident: $message:expr,)* ; $($code:ident,)*) => (
46 (stringify!($ecode), Some($message)),
52 ].iter().cloned().map(|s| (s, None)).collect::<Vec<_>>());}
58 all
.push_str(r
#"include!(concat!(env!("OUT_DIR"), "/all_error_codes.rs"));"#);
59 all
.push_str("\nlong_codes\n");
62 fs
::write(&dest
, all
).unwrap();