Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 620d1bc

Browse files
authoredApr 6, 2024
Rollup merge of #123339 - onur-ozkan:optimize-tidy-check, r=Mark-Simulacrum
optimize tidy check on `src/tools/tidy/src/issues.txt` This change applies to the following: - Handles `is_sorted` in the first iteration without needing a second. - Fixes line sorting on `--bless`. - Reads `issues.txt` as str rather than making it part of the source code. Fixes #123002
2 parents 426508e + 49c10e4 commit 620d1bc

File tree

2 files changed

+4393
-4391
lines changed

2 files changed

+4393
-4391
lines changed
 

‎src/tools/tidy/src/issues.txt

Lines changed: 4369 additions & 4374 deletions
Large diffs are not rendered by default.

‎src/tools/tidy/src/ui_tests.rs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,25 +100,41 @@ fn check_entries(tests_path: &Path, bad: &mut bool) {
100100
}
101101

102102
pub fn check(root_path: &Path, bless: bool, bad: &mut bool) {
103+
let issues_txt_header = r#"============================================================
104+
⚠️⚠️⚠️NOTHING SHOULD EVER BE ADDED TO THIS LIST⚠️⚠️⚠️
105+
============================================================
106+
"#;
107+
103108
let path = &root_path.join("tests");
104109
check_entries(&path, bad);
105110

106111
// the list of files in ui tests that are allowed to start with `issue-XXXX`
107112
// BTreeSet because we would like a stable ordering so --bless works
108-
let issues_list =
109-
include!("issues.txt").map(|path| path.replace("/", std::path::MAIN_SEPARATOR_STR));
110-
let issues: Vec<String> = Vec::from(issues_list.clone());
111-
let is_sorted = issues.windows(2).all(|w| w[0] < w[1]);
113+
let mut prev_line = "";
114+
let mut is_sorted = true;
115+
let allowed_issue_names: BTreeSet<_> = include_str!("issues.txt")
116+
.strip_prefix(issues_txt_header)
117+
.unwrap()
118+
.lines()
119+
.map(|line| {
120+
if prev_line > line {
121+
is_sorted = false;
122+
}
123+
124+
prev_line = line;
125+
line
126+
})
127+
.collect();
128+
112129
if !is_sorted && !bless {
113130
tidy_error!(
114131
bad,
115132
"`src/tools/tidy/src/issues.txt` is not in order, mostly because you modified it manually,
116133
please only update it with command `x test tidy --bless`"
117134
);
118135
}
119-
let allowed_issue_names = BTreeSet::from(issues_list);
120136

121-
let mut remaining_issue_names: BTreeSet<String> = allowed_issue_names.clone();
137+
let mut remaining_issue_names: BTreeSet<&str> = allowed_issue_names.clone();
122138

123139
let (ui, ui_fulldeps) = (path.join("ui"), path.join("ui-fulldeps"));
124140
let paths = [ui.as_path(), ui_fulldeps.as_path()];
@@ -186,15 +202,7 @@ pub fn check(root_path: &Path, bless: bool, bad: &mut bool) {
186202
// if there are any file names remaining, they were moved on the fs.
187203
// our data must remain up to date, so it must be removed from issues.txt
188204
// do this automatically on bless, otherwise issue a tidy error
189-
if bless && !remaining_issue_names.is_empty() {
190-
let issues_txt_header = r#"
191-
/*
192-
============================================================
193-
⚠️⚠️⚠️NOTHING SHOULD EVER BE ADDED TO THIS LIST⚠️⚠️⚠️
194-
============================================================
195-
*/
196-
[
197-
"#;
205+
if bless && (!remaining_issue_names.is_empty() || !is_sorted) {
198206
let tidy_src = root_path.join("src/tools/tidy/src");
199207
// instead of overwriting the file, recreate it and use an "atomic rename"
200208
// so we don't bork things on panic or a contributor using Ctrl+C
@@ -206,9 +214,8 @@ pub fn check(root_path: &Path, bless: bool, bad: &mut bool) {
206214
.difference(&remaining_issue_names)
207215
.map(|s| s.replace(std::path::MAIN_SEPARATOR_STR, "/"))
208216
{
209-
write!(blessed_issues_txt, "\"{filename}\",\n").unwrap();
217+
writeln!(blessed_issues_txt, "{filename}").unwrap();
210218
}
211-
write!(blessed_issues_txt, "]\n").unwrap();
212219
let old_issues_path = tidy_src.join("issues.txt");
213220
fs::rename(blessed_issues_path, old_issues_path).unwrap();
214221
} else {

0 commit comments

Comments
 (0)
Please sign in to comment.