Move from bash to rust

This commit is contained in:
Joshua Nelson 2020-11-20 22:58:46 -05:00
parent 4d44d77c4d
commit 25a3ffe5d4
2 changed files with 33 additions and 40 deletions

View File

@ -2390,22 +2390,39 @@ impl<'test> TestCx<'test> {
proc_res.fatal(Some("failed to run nightly rustdoc"), || ()); proc_res.fatal(Some("failed to run nightly rustdoc"), || ());
} }
// NOTE: this is fine since compiletest never runs out-of-tree #[rustfmt::skip]
let tidy = concat!(env!("CARGO_MANIFEST_DIR"), "/tidy-rustdoc.sh"); let tidy_args = [
// FIXME: this overwrites `out_dir` in place, maybe we should make a copy? "--indent", "yes",
let status = Command::new(tidy) "--indent-spaces", "2",
.arg(out_dir) "--wrap", "0",
.spawn() "--show-warnings", "no",
.expect("tidy-rustdoc not found") "--markup", "yes",
.wait() "--quiet", "yes",
.unwrap(); "-modify",
if !status.success() { ];
self.fatal("failed to run tidy - is it installed?"); let tidy_dir = |dir| {
} let tidy = |file: &_| {
let status = Command::new(tidy).arg(&compare_dir).spawn().unwrap().wait().unwrap(); Command::new("tidy")
if !status.success() { .args(&tidy_args)
self.fatal("failed to run tidy"); .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 pager = {
let output = Command::new("git").args(&["config", "--get", "core.pager"]).output().ok(); let output = Command::new("git").args(&["config", "--get", "core.pager"]).output().ok();

View File

@ -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