Skip to content

Commit a2c0097

Browse files
authored
Rollup merge of rust-lang#123889 - onur-ozkan:improve-tidy, r=Mark-Simulacrum
reduce tidy overheads in run-make checks This change makes tidy to handle run-make checks with a single iteration, avoiding the need for multiple iterations and copying.
2 parents e297869 + c6002f1 commit a2c0097

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

src/tools/tidy/src/run_make_tests.rs

+24-9
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,26 @@ use std::io::Write;
66
use std::path::{Path, PathBuf};
77

88
pub fn check(tests_path: &Path, src_path: &Path, bless: bool, bad: &mut bool) {
9+
let mut is_sorted = true;
10+
911
let allowed_makefiles = {
10-
let allowed_makefiles = include_str!("allowed_run_make_makefiles.txt");
11-
let allowed_makefiles = allowed_makefiles.lines().collect::<Vec<_>>();
12-
let is_sorted = allowed_makefiles.windows(2).all(|w| w[0] < w[1]);
12+
let mut total_lines = 0;
13+
let mut prev_line = "";
14+
let allowed_makefiles: BTreeSet<&str> = include_str!("allowed_run_make_makefiles.txt")
15+
.lines()
16+
.map(|line| {
17+
total_lines += 1;
18+
19+
if prev_line > line {
20+
is_sorted = false;
21+
}
22+
23+
prev_line = line;
24+
25+
line
26+
})
27+
.collect();
28+
1329
if !is_sorted && !bless {
1430
tidy_error!(
1531
bad,
@@ -18,17 +34,16 @@ pub fn check(tests_path: &Path, src_path: &Path, bless: bool, bad: &mut bool) {
1834
`x test tidy --bless`"
1935
);
2036
}
21-
let allowed_makefiles_unique =
22-
allowed_makefiles.iter().map(ToString::to_string).collect::<BTreeSet<String>>();
23-
if allowed_makefiles_unique.len() != allowed_makefiles.len() {
37+
if allowed_makefiles.len() != total_lines {
2438
tidy_error!(
2539
bad,
2640
"`src/tools/tidy/src/allowed_run_make_makefiles.txt` contains duplicate entries, \
2741
likely because you modified it manually, please only update it with command \
2842
`x test tidy --bless`"
2943
);
3044
}
31-
allowed_makefiles_unique
45+
46+
allowed_makefiles
3247
};
3348

3449
let mut remaining_makefiles = allowed_makefiles.clone();
@@ -48,7 +63,7 @@ pub fn check(tests_path: &Path, src_path: &Path, bless: bool, bad: &mut bool) {
4863
let makefile_path = entry.path().strip_prefix(&tests_path).unwrap();
4964
let makefile_path = makefile_path.to_str().unwrap().replace('\\', "/");
5065

51-
if !remaining_makefiles.remove(&makefile_path) {
66+
if !remaining_makefiles.remove(makefile_path.as_str()) {
5267
tidy_error!(
5368
bad,
5469
"found run-make Makefile not permitted in \
@@ -64,7 +79,7 @@ pub fn check(tests_path: &Path, src_path: &Path, bless: bool, bad: &mut bool) {
6479
// Our data must remain up to date, so they must be removed from
6580
// `src/tools/tidy/src/allowed_run_make_makefiles.txt`.
6681
// This can be done automatically on --bless, or else a tidy error will be issued.
67-
if bless && !remaining_makefiles.is_empty() {
82+
if bless && (!remaining_makefiles.is_empty() || !is_sorted) {
6883
let tidy_src = src_path.join("tools").join("tidy").join("src");
6984
let org_file_path = tidy_src.join("allowed_run_make_makefiles.txt");
7085
let temp_file_path = tidy_src.join("blessed_allowed_run_make_makefiles.txt");

0 commit comments

Comments
 (0)