@@ -6,10 +6,26 @@ use std::io::Write;
6
6
use std:: path:: { Path , PathBuf } ;
7
7
8
8
pub fn check ( tests_path : & Path , src_path : & Path , bless : bool , bad : & mut bool ) {
9
+ let mut is_sorted = true ;
10
+
9
11
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
+
13
29
if !is_sorted && !bless {
14
30
tidy_error ! (
15
31
bad,
@@ -18,17 +34,16 @@ pub fn check(tests_path: &Path, src_path: &Path, bless: bool, bad: &mut bool) {
18
34
`x test tidy --bless`"
19
35
) ;
20
36
}
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 {
24
38
tidy_error ! (
25
39
bad,
26
40
"`src/tools/tidy/src/allowed_run_make_makefiles.txt` contains duplicate entries, \
27
41
likely because you modified it manually, please only update it with command \
28
42
`x test tidy --bless`"
29
43
) ;
30
44
}
31
- allowed_makefiles_unique
45
+
46
+ allowed_makefiles
32
47
} ;
33
48
34
49
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) {
48
63
let makefile_path = entry. path ( ) . strip_prefix ( & tests_path) . unwrap ( ) ;
49
64
let makefile_path = makefile_path. to_str ( ) . unwrap ( ) . replace ( '\\' , "/" ) ;
50
65
51
- if !remaining_makefiles. remove ( & makefile_path) {
66
+ if !remaining_makefiles. remove ( makefile_path. as_str ( ) ) {
52
67
tidy_error ! (
53
68
bad,
54
69
"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) {
64
79
// Our data must remain up to date, so they must be removed from
65
80
// `src/tools/tidy/src/allowed_run_make_makefiles.txt`.
66
81
// 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 ) {
68
83
let tidy_src = src_path. join ( "tools" ) . join ( "tidy" ) . join ( "src" ) ;
69
84
let org_file_path = tidy_src. join ( "allowed_run_make_makefiles.txt" ) ;
70
85
let temp_file_path = tidy_src. join ( "blessed_allowed_run_make_makefiles.txt" ) ;
0 commit comments