about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2019-11-13 15:27:59 +0100
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2019-11-14 13:05:56 +0100
commit356da40db5ad56ed9efbf6c2757422a9fd2fd3d2 (patch)
tree1cbddf7fa23b9679cb8dd044721154d471f76490 /src/tools
parentec50a750f96164e588adcc9ef5d47b8ac89869d1 (diff)
Adapt error index generator to the new format
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/error_index_generator/build.rs34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/tools/error_index_generator/build.rs b/src/tools/error_index_generator/build.rs
index 3261bf5a98b..b04aff4939b 100644
--- a/src/tools/error_index_generator/build.rs
+++ b/src/tools/error_index_generator/build.rs
@@ -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 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();
+    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();
 
-            idx += 1;
+    // 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();
+        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");