Skip to content

Commit

Permalink
[error index] Move some logic from build.rs to main.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
jyn514 committed Mar 27, 2022
1 parent 37b55c8 commit 02af015
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 33 deletions.
32 changes: 0 additions & 32 deletions src/tools/error_index_generator/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ fn main() {
// 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");

let error_codes_path = "../../../compiler/rustc_error_codes/src/error_codes.rs";

Expand All @@ -29,35 +28,4 @@ fn main() {
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();
all.push_str(
r###"
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,)* ;}
);
($($ecode:ident: $message:expr,)* ; $($code:ident,)*) => (
$(
{long_codes.extend([
(stringify!($ecode), Some($message)),
].iter());}
)*
$(
{long_codes.extend([
stringify!($code),
].iter().cloned().map(|s| (s, None)).collect::<Vec<_>>());}
)*
)
}
"###,
);
all.push_str(r#"include!(concat!(env!("OUT_DIR"), "/all_error_codes.rs"));"#);
all.push_str("\nlong_codes\n");
all.push_str("}\n");

fs::write(&dest, all).unwrap();
}
24 changes: 23 additions & 1 deletion src/tools/error_index_generator/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,26 @@ fn main() {
}
}

include!(concat!(env!("OUT_DIR"), "/error_codes.rs"));
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,)* ;}
);

($($ecode:ident: $message:expr,)* ; $($code:ident,)*) => (
$(
{long_codes.extend([
(stringify!($ecode), Some($message)),
].iter());}
)*
$(
{long_codes.extend([
stringify!($code),
].iter().cloned().map(|s| (s, None)).collect::<Vec<_>>());}
)*
)
}
include!(concat!(env!("OUT_DIR"), "/all_error_codes.rs"));
long_codes
}

0 comments on commit 02af015

Please sign in to comment.