@@ -6,10 +6,26 @@ use std::io::Write;
66use std:: path:: { Path , PathBuf } ;
77
88pub 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