@@ -8,21 +8,26 @@ fn main() {
8
8
// directory.
9
9
let out_dir = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
10
10
let dest = out_dir. join ( "error_codes.rs" ) ;
11
- let mut idx = 0 ;
12
- for entry in WalkDir :: new ( "../../../src" ) {
13
- let entry = entry. unwrap ( ) ;
14
- if entry. file_name ( ) == "error_codes.rs" {
15
- println ! ( "cargo:rerun-if-changed={}" , entry. path( ) . to_str( ) . unwrap( ) ) ;
16
- let file = fs:: read_to_string ( entry. path ( ) ) . unwrap ( )
17
- . replace ( "crate::register_diagnostics!" , "register_diagnostics!" )
18
- . replace ( ": include_str!(\" ./" ,
19
- ": include_str!(\" ../../../../../../../../src/librustc_error_codes/" ) ;
20
- let contents = format ! ( "(|| {{\n {}\n }})()" , file) ;
21
11
22
- fs:: write ( & out_dir. join ( & format ! ( "error_{}.rs" , idx) ) , & contents) . unwrap ( ) ;
12
+ let error_codes_path = "../../../src/librustc_error_codes/error_codes.rs" ;
13
+
14
+ println ! ( "cargo:rerun-if-changed={}" , error_codes_path) ;
15
+ let file = fs:: read_to_string ( error_codes_path) . unwrap ( )
16
+ . replace ( "crate::register_diagnostics!" , "register_diagnostics!" )
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 ( ) ;
23
20
24
- idx += 1 ;
21
+ // We copy the md files as well to the target directory.
22
+ for entry in WalkDir :: new ( "../../../src/librustc_error_codes/error_codes" ) {
23
+ let entry = entry. unwrap ( ) ;
24
+ match entry. path ( ) . extension ( ) {
25
+ Some ( s) if s == "md" => { }
26
+ _ => continue ,
25
27
}
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 ( ) ;
26
31
}
27
32
28
33
let mut all = String :: new ( ) ;
@@ -48,10 +53,7 @@ fn register_all() -> Vec<(&'static str, Option<&'static str>)> {
48
53
)
49
54
}
50
55
"### ) ;
51
- for idx in 0 ..idx {
52
- all. push_str ( & format ! ( r#"include!(concat!(env!("OUT_DIR"), "/error_{}.rs"));"# , idx) ) ;
53
- all. push_str ( "\n " ) ;
54
- }
56
+ all. push_str ( r#"include!(concat!(env!("OUT_DIR"), "/all_error_codes.rs"));"# ) ;
55
57
all. push_str ( "\n long_codes\n " ) ;
56
58
all. push_str ( "}\n " ) ;
57
59
0 commit comments