Skip to content

Commit f2f55e8

Browse files
committed
Auto merge of rust-lang#90663 - ken-matsui:support-early-stopping-too-old-tidy-for-macos, r=Mark-Simulacrum
Support early stopping too old pre-installed `tidy` command for macOS in the HTML checker This PR brings early stopping the HTML checker before errors, which leave some macOS users confused, and suggesting installing a newer `tidy` command. The pre-installed `tidy` command on macOS is too old, released on 31 October 2006. Additionally, I can see the same date at [StackOverflow](https://stackoverflow.com/questions/22283382/overwrite-osx-tidy ) seven years ago. The `tidy` does not support two indispensable options: `--mute-id` and `--mute`. So, the `./x.py test` command fails with a bunch of errors due not to muting them. I could confirm the `./x.py test` command before installing a newer `tidy` failed and its command after the installation succeeded.
2 parents 8b09ba6 + f06a711 commit f2f55e8

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/tools/html-checker/main.rs

+23
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,34 @@ fn find_all_html_files(dir: &Path) -> (usize, usize) {
7979
(files_read, errors)
8080
}
8181

82+
/// Default `tidy` command for macOS is too old that it does not have `mute-id` and `mute` options.
83+
/// `tidy` on macOS Monterey was released on 31 October 2006, and the same date can be seen seven
84+
/// years ago at <https://stackoverflow.com/questions/22283382/overwrite-osx-tidy>. Accordingly,
85+
/// the macOS environment using pre-installed `tidy` should immediately suspend HTML checker process
86+
/// and show a hint to install a newer one.
87+
#[cfg(target_os = "macos")]
88+
fn check_tidy_version() -> Result<(), String> {
89+
let output = Command::new("tidy").arg("-v").output().expect("failed to run tidy command");
90+
let version = String::from_utf8(output.stdout).expect("failed to read version of tidy command");
91+
if version.contains("HTML Tidy for Mac OS X released on 31 October 2006") {
92+
eprintln!("The pre-installed HTML Tidy for macOS is not supported.");
93+
eprintln!("Consider installing a newer one and re-running.");
94+
eprintln!("If you're using Homebrew, you can install it by the following command:");
95+
eprintln!(" brew install tidy-html5");
96+
eprintln!();
97+
Err("HTML check failed: 1 error".to_string())
98+
} else {
99+
Ok(())
100+
}
101+
}
102+
82103
fn main() -> Result<(), String> {
83104
let args = env::args().collect::<Vec<_>>();
84105
if args.len() != 2 {
85106
return Err(format!("Usage: {} <doc folder>", args[0]));
86107
}
108+
#[cfg(target_os = "macos")]
109+
check_tidy_version()?;
87110

88111
println!("Running HTML checker...");
89112

0 commit comments

Comments
 (0)