|
1 | 1 | use crate::clippy_project_root;
|
| 2 | +use itertools::Itertools; |
2 | 3 | use shell_escape::escape;
|
3 |
| -use std::ffi::OsStr; |
| 4 | +use std::ffi::{OsStr, OsString}; |
4 | 5 | use std::path::Path;
|
5 | 6 | use std::process::{self, Command};
|
6 | 7 | use std::{fs, io};
|
@@ -56,15 +57,22 @@ pub fn run(check: bool, verbose: bool) {
|
56 | 57 | success &= cargo_fmt(context, &project_root.join("rustc_tools_util"))?;
|
57 | 58 | success &= cargo_fmt(context, &project_root.join("lintcheck"))?;
|
58 | 59 |
|
59 |
| - for entry in WalkDir::new(project_root.join("tests")) { |
60 |
| - let entry = entry?; |
61 |
| - let path = entry.path(); |
62 |
| - |
63 |
| - if path.extension() != Some("rs".as_ref()) || entry.file_name() == "ice-3891.rs" { |
64 |
| - continue; |
65 |
| - } |
66 |
| - |
67 |
| - success &= rustfmt(context, path)?; |
| 60 | + let chunks = WalkDir::new(project_root.join("tests")) |
| 61 | + .into_iter() |
| 62 | + .filter_map(|entry| { |
| 63 | + let entry = entry.expect("failed to find tests"); |
| 64 | + let path = entry.path(); |
| 65 | + |
| 66 | + if path.extension() != Some("rs".as_ref()) || entry.file_name() == "ice-3891.rs" { |
| 67 | + None |
| 68 | + } else { |
| 69 | + Some(entry.into_path().into_os_string()) |
| 70 | + } |
| 71 | + }) |
| 72 | + .chunks(250); |
| 73 | + |
| 74 | + for chunk in &chunks { |
| 75 | + success &= rustfmt(context, chunk)?; |
68 | 76 | }
|
69 | 77 |
|
70 | 78 | Ok(success)
|
@@ -185,14 +193,14 @@ fn rustfmt_test(context: &FmtContext) -> Result<(), CliError> {
|
185 | 193 | }
|
186 | 194 | }
|
187 | 195 |
|
188 |
| -fn rustfmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> { |
189 |
| - let mut args = vec![path.as_os_str()]; |
| 196 | +fn rustfmt(context: &FmtContext, paths: impl Iterator<Item = OsString>) -> Result<bool, CliError> { |
| 197 | + let mut args = Vec::new(); |
190 | 198 | if context.check {
|
191 |
| - args.push("--check".as_ref()); |
| 199 | + args.push(OsString::from("--check")); |
192 | 200 | }
|
| 201 | + args.extend(paths); |
| 202 | + |
193 | 203 | let success = exec(context, "rustfmt", std::env::current_dir()?, &args)?;
|
194 |
| - if !success { |
195 |
| - eprintln!("rustfmt failed on {}", path.display()); |
196 |
| - } |
| 204 | + |
197 | 205 | Ok(success)
|
198 | 206 | }
|
0 commit comments