If tidy isn't installed, only give one error, not many

This commit is contained in:
Joshua Nelson 2020-11-26 14:05:54 -05:00
parent 409382dd3c
commit 804b72af4a
3 changed files with 22 additions and 19 deletions

View File

@ -327,6 +327,9 @@ pub struct Config {
/// created in `/<build_base>/rustfix_missing_coverage.txt` /// created in `/<build_base>/rustfix_missing_coverage.txt`
pub rustfix_coverage: bool, pub rustfix_coverage: bool,
/// whether to run `tidy` when a rustdoc test fails
pub has_tidy: bool,
// Configuration for various run-make tests frobbing things like C compilers // Configuration for various run-make tests frobbing things like C compilers
// or querying about various LLVM component information. // or querying about various LLVM component information.
pub cc: String, pub cc: String,

View File

@ -14,7 +14,7 @@ use std::ffi::OsString;
use std::fs; use std::fs;
use std::io::{self, ErrorKind}; use std::io::{self, ErrorKind};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process::Command; use std::process::{Command, Stdio};
use std::time::SystemTime; use std::time::SystemTime;
use test::ColorConfig; use test::ColorConfig;
use tracing::*; use tracing::*;
@ -43,6 +43,10 @@ fn main() {
panic!("Can't find Valgrind to run Valgrind tests"); panic!("Can't find Valgrind to run Valgrind tests");
} }
if !config.has_tidy && config.mode == Mode::Rustdoc {
eprintln!("warning: `tidy` is not installed; generated diffs will be harder to read");
}
log_config(&config); log_config(&config);
run_tests(config); run_tests(config);
} }
@ -189,6 +193,11 @@ pub fn parse_config(args: Vec<String>) -> Config {
let src_base = opt_path(matches, "src-base"); let src_base = opt_path(matches, "src-base");
let run_ignored = matches.opt_present("ignored"); let run_ignored = matches.opt_present("ignored");
let has_tidy = Command::new("tidy")
.arg("--version")
.stdout(Stdio::null())
.status()
.map_or(false, |status| status.success());
Config { Config {
bless: matches.opt_present("bless"), bless: matches.opt_present("bless"),
compile_lib_path: make_absolute(opt_path(matches, "compile-lib-path")), compile_lib_path: make_absolute(opt_path(matches, "compile-lib-path")),
@ -244,6 +253,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
remote_test_client: matches.opt_str("remote-test-client").map(PathBuf::from), remote_test_client: matches.opt_str("remote-test-client").map(PathBuf::from),
compare_mode: matches.opt_str("compare-mode").map(CompareMode::parse), compare_mode: matches.opt_str("compare-mode").map(CompareMode::parse),
rustfix_coverage: matches.opt_present("rustfix-coverage"), rustfix_coverage: matches.opt_present("rustfix-coverage"),
has_tidy,
cc: matches.opt_str("cc").unwrap(), cc: matches.opt_str("cc").unwrap(),
cxx: matches.opt_str("cxx").unwrap(), cxx: matches.opt_str("cxx").unwrap(),

View File

@ -2409,32 +2409,22 @@ impl<'test> TestCx<'test> {
"-modify", "-modify",
]; ];
let tidy_dir = |dir| { let tidy_dir = |dir| {
let tidy = |file: &_| {
let tidy_proc = Command::new("tidy").args(&tidy_args).arg(file).spawn();
match tidy_proc {
Ok(mut proc) => {
proc.wait().unwrap();
true
}
Err(err) => {
eprintln!("failed to run tidy - is it installed? - {}", err);
false
}
}
};
for entry in walkdir::WalkDir::new(dir) { for entry in walkdir::WalkDir::new(dir) {
let entry = entry.expect("failed to read file"); let entry = entry.expect("failed to read file");
if entry.file_type().is_file() if entry.file_type().is_file()
&& entry.path().extension().and_then(|p| p.to_str()) == Some("html".into()) && entry.path().extension().and_then(|p| p.to_str()) == Some("html".into())
{ {
if !tidy(entry.path()) { let status =
return; Command::new("tidy").args(&tidy_args).arg(entry.path()).status().unwrap();
} // `tidy` returns 1 if it modified the file.
assert!(status.success() || status.code() == Some(1));
} }
} }
}; };
tidy_dir(out_dir); if self.config.has_tidy {
tidy_dir(&compare_dir); 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();