about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJoshua Nelson <jyn514@gmail.com>2020-11-20 22:58:46 -0500
committerJoshua Nelson <jyn514@gmail.com>2020-11-20 23:00:56 -0500
commit25a3ffe5d4768e37fe98c9637db84af4714549d4 (patch)
tree2f2653a302d701be8832efc5e5cb1b61ff39b67d
parent4d44d77c4d97f46bbfd184e3995e0278b8c3d096 (diff)
downloadrust-25a3ffe5d4768e37fe98c9637db84af4714549d4.tar.gz
rust-25a3ffe5d4768e37fe98c9637db84af4714549d4.zip
Move from bash to rust
-rw-r--r--src/tools/compiletest/src/runtest.rs49
-rwxr-xr-xsrc/tools/compiletest/tidy-rustdoc.sh24
2 files changed, 33 insertions, 40 deletions
diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs
index 46bf007c649..ca9fad41b56 100644
--- a/src/tools/compiletest/src/runtest.rs
+++ b/src/tools/compiletest/src/runtest.rs
@@ -2390,22 +2390,39 @@ impl<'test> TestCx<'test> {
             proc_res.fatal(Some("failed to run nightly rustdoc"), || ());
         }
 
-        // NOTE: this is fine since compiletest never runs out-of-tree
-        let tidy = concat!(env!("CARGO_MANIFEST_DIR"), "/tidy-rustdoc.sh");
-        // FIXME: this overwrites `out_dir` in place, maybe we should make a copy?
-        let status = Command::new(tidy)
-            .arg(out_dir)
-            .spawn()
-            .expect("tidy-rustdoc not found")
-            .wait()
-            .unwrap();
-        if !status.success() {
-            self.fatal("failed to run tidy - is it installed?");
-        }
-        let status = Command::new(tidy).arg(&compare_dir).spawn().unwrap().wait().unwrap();
-        if !status.success() {
-            self.fatal("failed to run tidy");
-        }
+        #[rustfmt::skip]
+        let tidy_args = [
+            "--indent", "yes",
+            "--indent-spaces", "2",
+            "--wrap", "0",
+            "--show-warnings", "no",
+            "--markup", "yes",
+            "--quiet", "yes",
+            "-modify",
+        ];
+        let tidy_dir = |dir| {
+            let tidy = |file: &_| {
+                Command::new("tidy")
+                    .args(&tidy_args)
+                    .arg(file)
+                    .spawn()
+                    .unwrap_or_else(|err| {
+                        self.fatal(&format!("failed to run tidy - is it installed? - {}", err))
+                    })
+                    .wait()
+                    .unwrap()
+            };
+            for entry in walkdir::WalkDir::new(dir) {
+                let entry = entry.expect("failed to read file");
+                if entry.file_type().is_file()
+                    && entry.path().extension().and_then(|p| p.to_str()) == Some("html".into())
+                {
+                    tidy(entry.path());
+                }
+            }
+        };
+        tidy_dir(out_dir);
+        tidy_dir(&compare_dir);
 
         let pager = {
             let output = Command::new("git").args(&["config", "--get", "core.pager"]).output().ok();
diff --git a/src/tools/compiletest/tidy-rustdoc.sh b/src/tools/compiletest/tidy-rustdoc.sh
deleted file mode 100755
index 407e9169af5..00000000000
--- a/src/tools/compiletest/tidy-rustdoc.sh
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env bash
-
-set -euo pipefail
-
-indir="${1:?Missing argument 1: input directory}"
-
-tidy () {
-  command tidy \
-      --indent yes \
-      --indent-spaces 2 \
-      --wrap 0 \
-      --show-warnings no \
-      --markup yes \
-      --quiet yes \
-      "$@" \
-      >/dev/null \
-  || [ $? -eq 1 ] # tidy exits with code 1 if there were any warnings
-}
-
-find "$indir" -type f -name '*.html' -print0 \
-| while IFS= read -d '' -r file
-do
-  tidy -modify "$file"
-done