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"), || ());
}
// 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();

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