Remove "tidy" tool for tests/rustdoc testsuite · rust-lang/rust@4d697d2 (original) (raw)
1
1
`use std::borrow::Cow;
`
2
2
`use std::collections::{HashMap, HashSet};
`
3
3
`use std::ffi::OsString;
`
4
``
`-
use std::fs::{self, File, create_dir_all};
`
``
4
`+
use std::fs::{self, create_dir_all};
`
5
5
`use std::hash::{DefaultHasher, Hash, Hasher};
`
6
6
`use std::io::prelude::*;
`
7
``
`-
use std::io::{self, BufReader};
`
8
7
`use std::process::{Child, Command, ExitStatus, Output, Stdio};
`
9
``
`-
use std::{env, fmt, iter, str};
`
``
8
`+
use std::{env, fmt, io, iter, str};
`
10
9
``
11
10
`use build_helper::fs::remove_and_create_dir_all;
`
12
11
`use camino::{Utf8Path, Utf8PathBuf};
`
`@@ -23,9 +22,9 @@ use crate::directives::TestProps;
`
23
22
`use crate::errors::{Error, ErrorKind, load_errors};
`
24
23
`use crate::output_capture::ConsoleOut;
`
25
24
`use crate::read2::{Truncated, read2_abbreviated};
`
26
``
`-
use crate::runtest::compute_diff::{DiffLine, make_diff, write_diff, write_filtered_diff};
`
``
25
`+
use crate::runtest::compute_diff::{DiffLine, make_diff, write_diff};
`
27
26
`use crate::util::{Utf8PathBufExt, add_dylib_path, static_regex};
`
28
``
`-
use crate::{ColorConfig, help, json, stamp_file_path, warning};
`
``
27
`+
use crate::{json, stamp_file_path};
`
29
28
``
30
29
`// Helper modules that implement test running logic for each test suite.
`
31
30
`// tidy-alphabetical-start
`
`@@ -2162,161 +2161,6 @@ impl<'test> TestCx<'test> {
`
2162
2161
`if cfg!(target_os = "freebsd") { "ISO-8859-1" } else { "UTF-8" }
`
2163
2162
`}
`
2164
2163
``
2165
``
`-
fn compare_to_default_rustdoc(&self, out_dir: &Utf8Path) {
`
2166
``
`-
if !self.config.has_html_tidy {
`
2167
``
`-
return;
`
2168
``
`-
}
`
2169
``
`-
writeln!(self.stdout, "info: generating a diff against nightly rustdoc");
`
2170
``
-
2171
``
`-
let suffix =
`
2172
``
`-
self.safe_revision().map_or("nightly".into(), |path| path.to_owned() + "-nightly");
`
2173
``
`-
let compare_dir = output_base_dir(self.config, self.testpaths, Some(&suffix));
`
2174
``
`-
remove_and_create_dir_all(&compare_dir).unwrap_or_else(|e| {
`
2175
``
`` -
panic!("failed to remove and recreate output directory {compare_dir}: {e}")
``
2176
``
`-
});
`
2177
``
-
2178
``
`` -
// We need to create a new struct for the lifetimes on config to work.
``
2179
``
`-
let new_rustdoc = TestCx {
`
2180
``
`-
config: &Config {
`
2181
``
`-
// FIXME: use beta or a user-specified rustdoc instead of
`
2182
``
`-
// hardcoding the default toolchain
`
2183
``
`-
rustdoc_path: Some("rustdoc".into()),
`
2184
``
`-
// Needed for building auxiliary docs below
`
2185
``
`-
rustc_path: "rustc".into(),
`
2186
``
`-
..self.config.clone()
`
2187
``
`-
},
`
2188
``
`-
..*self
`
2189
``
`-
};
`
2190
``
-
2191
``
`-
let output_file = TargetLocation::ThisDirectory(new_rustdoc.aux_output_dir_name());
`
2192
``
`-
let mut rustc = new_rustdoc.make_compile_args(
`
2193
``
`-
&new_rustdoc.testpaths.file,
`
2194
``
`-
output_file,
`
2195
``
`-
Emit::None,
`
2196
``
`-
AllowUnused::Yes,
`
2197
``
`-
LinkToAux::Yes,
`
2198
``
`-
Vec::new(),
`
2199
``
`-
);
`
2200
``
`-
let aux_dir = new_rustdoc.aux_output_dir();
`
2201
``
`-
new_rustdoc.build_all_auxiliary(&aux_dir, &mut rustc);
`
2202
``
-
2203
``
`-
let proc_res = new_rustdoc.document(&compare_dir, DocKind::Html);
`
2204
``
`-
if !proc_res.status.success() {
`
2205
``
`-
writeln!(self.stderr, "failed to run nightly rustdoc");
`
2206
``
`-
return;
`
2207
``
`-
}
`
2208
``
-
2209
``
`-
#[rustfmt::skip]
`
2210
``
`-
let tidy_args = [
`
2211
``
`-
"--new-blocklevel-tags", "rustdoc-search,rustdoc-toolbar,rustdoc-topbar",
`
2212
``
`-
"--indent", "yes",
`
2213
``
`-
"--indent-spaces", "2",
`
2214
``
`-
"--wrap", "0",
`
2215
``
`-
"--show-warnings", "no",
`
2216
``
`-
"--markup", "yes",
`
2217
``
`-
"--quiet", "yes",
`
2218
``
`-
"-modify",
`
2219
``
`-
];
`
2220
``
`-
let tidy_dir = |dir| {
`
2221
``
`-
for entry in walkdir::WalkDir::new(dir) {
`
2222
``
`-
let entry = entry.expect("failed to read file");
`
2223
``
`-
if entry.file_type().is_file()
`
2224
``
`-
&& entry.path().extension().and_then(|p| p.to_str()) == Some("html")
`
2225
``
`-
{
`
2226
``
`-
let status =
`
2227
``
`-
Command::new("tidy").args(&tidy_args).arg(entry.path()).status().unwrap();
`
2228
``
`` -
// tidy returns 1 if it modified the file.
``
2229
``
`-
assert!(status.success() || status.code() == Some(1));
`
2230
``
`-
}
`
2231
``
`-
}
`
2232
``
`-
};
`
2233
``
`-
tidy_dir(out_dir);
`
2234
``
`-
tidy_dir(&compare_dir);
`
2235
``
-
2236
``
`-
let pager = {
`
2237
``
`-
let output = Command::new("git").args(&["config", "--get", "core.pager"]).output().ok();
`
2238
``
`-
output.and_then(|out| {
`
2239
``
`-
if out.status.success() {
`
2240
``
`-
Some(String::from_utf8(out.stdout).expect("invalid UTF8 in git pager"))
`
2241
``
`-
} else {
`
2242
``
`-
None
`
2243
``
`-
}
`
2244
``
`-
})
`
2245
``
`-
};
`
2246
``
-
2247
``
`-
let diff_filename = format!("build/tmp/rustdoc-compare-{}.diff", std::process::id());
`
2248
``
-
2249
``
`-
if !write_filtered_diff(
`
2250
``
`-
self,
`
2251
``
`-
&diff_filename,
`
2252
``
`-
out_dir,
`
2253
``
`-
&compare_dir,
`
2254
``
`-
self.config.verbose,
`
2255
``
`-
|file_type, extension| {
`
2256
``
`-
file_type.is_file() && (extension == Some("html") || extension == Some("js"))
`
2257
``
`-
},
`
2258
``
`-
) {
`
2259
``
`-
return;
`
2260
``
`-
}
`
2261
``
-
2262
``
`-
match self.config.color {
`
2263
``
`-
ColorConfig::AlwaysColor => colored::control::set_override(true),
`
2264
``
`-
ColorConfig::NeverColor => colored::control::set_override(false),
`
2265
``
`-
_ => {}
`
2266
``
`-
}
`
2267
``
-
2268
``
`-
if let Some(pager) = pager {
`
2269
``
`-
let pager = pager.trim();
`
2270
``
`-
if self.config.verbose {
`
2271
``
`-
writeln!(self.stderr, "using pager {}", pager);
`
2272
``
`-
}
`
2273
``
`-
let output = Command::new(pager)
`
2274
``
`-
// disable paging; we want this to be non-interactive
`
2275
``
`-
.env("PAGER", "")
`
2276
``
`-
.stdin(File::open(&diff_filename).unwrap())
`
2277
``
`-
// Capture output and print it explicitly so it will in turn be
`
2278
``
`-
// captured by output-capture.
`
2279
``
`-
.output()
`
2280
``
`-
.unwrap();
`
2281
``
`-
assert!(output.status.success());
`
2282
``
`-
writeln!(self.stdout, "{}", String::from_utf8_lossy(&output.stdout));
`
2283
``
`-
writeln!(self.stderr, "{}", String::from_utf8_lossy(&output.stderr));
`
2284
``
`-
} else {
`
2285
``
`-
warning!("no pager configured, falling back to unified diff");
`
2286
``
`-
help!(
`
2287
``
`` -
"try configuring a git pager (e.g. delta) with \
``
2288
``
`` -
git config --global core.pager delta"
``
2289
``
`-
);
`
2290
``
`-
let mut out = io::stdout();
`
2291
``
`-
let mut diff = BufReader::new(File::open(&diff_filename).unwrap());
`
2292
``
`-
let mut line = Vec::new();
`
2293
``
`-
loop {
`
2294
``
`-
line.truncate(0);
`
2295
``
`-
match diff.read_until(b'\n', &mut line) {
`
2296
``
`-
Ok(0) => break,
`
2297
``
`-
Ok(_) => {}
`
2298
``
`-
Err(e) => writeln!(self.stderr, "ERROR: {:?}", e),
`
2299
``
`-
}
`
2300
``
`-
match String::from_utf8(line.clone()) {
`
2301
``
`-
Ok(line) => {
`
2302
``
`-
if line.starts_with('+') {
`
2303
``
`-
write!(&mut out, "{}", line.green()).unwrap();
`
2304
``
`-
} else if line.starts_with('-') {
`
2305
``
`-
write!(&mut out, "{}", line.red()).unwrap();
`
2306
``
`-
} else if line.starts_with('@') {
`
2307
``
`-
write!(&mut out, "{}", line.blue()).unwrap();
`
2308
``
`-
} else {
`
2309
``
`-
out.write_all(line.as_bytes()).unwrap();
`
2310
``
`-
}
`
2311
``
`-
}
`
2312
``
`-
Err(_) => {
`
2313
``
`-
write!(&mut out, "{}", String::from_utf8_lossy(&line).reversed()).unwrap();
`
2314
``
`-
}
`
2315
``
`-
}
`
2316
``
`-
}
`
2317
``
`-
};
`
2318
``
`-
}
`
2319
``
-
2320
2164
`fn get_lines(&self, path: &Utf8Path, mut other_files: Option<&mut Vec>) -> Vec {
`
2321
2165
`let content = fs::read_to_string(path.as_std_path()).unwrap();
`
2322
2166
`let mut ignore = false;
`