@@ -93,6 +93,7 @@ struct TestArg {
93
93
sysroot_panic_abort : bool ,
94
94
config_info : ConfigInfo ,
95
95
sysroot_features : Vec < String > ,
96
+ keep_lto_tests : bool ,
96
97
}
97
98
98
99
impl TestArg {
@@ -128,6 +129,9 @@ impl TestArg {
128
129
"--sysroot-panic-abort" => {
129
130
test_arg. sysroot_panic_abort = true ;
130
131
}
132
+ "--keep-lto-tests" => {
133
+ test_arg. keep_lto_tests = true ;
134
+ }
131
135
"--sysroot-features" => match args. next ( ) {
132
136
Some ( feature) if !feature. is_empty ( ) => {
133
137
test_arg. sysroot_features . push ( feature) ;
@@ -194,7 +198,7 @@ fn build_if_no_backend(env: &Env, args: &TestArg) -> Result<(), String> {
194
198
}
195
199
196
200
fn clean ( _env : & Env , args : & TestArg ) -> Result < ( ) , String > {
197
- let _ = std :: fs :: remove_dir_all ( & args. config_info . cargo_target_dir ) ;
201
+ let _ = remove_dir_all ( & args. config_info . cargo_target_dir ) ;
198
202
let path = Path :: new ( & args. config_info . cargo_target_dir ) . join ( "gccjit" ) ;
199
203
create_dir ( & path)
200
204
}
@@ -835,8 +839,7 @@ fn valid_ui_error_pattern_test(file: &str) -> bool {
835
839
. any ( |to_ignore| file. ends_with ( to_ignore) )
836
840
}
837
841
838
- #[ rustfmt:: skip]
839
- fn contains_ui_error_patterns ( file_path : & Path ) -> Result < bool , String > {
842
+ fn contains_ui_error_patterns ( file_path : & Path , keep_lto_tests : bool ) -> Result < bool , String > {
840
843
// Tests generating errors.
841
844
let file = File :: open ( file_path)
842
845
. map_err ( |error| format ! ( "Failed to read `{}`: {:?}" , file_path. display( ) , error) ) ?;
@@ -845,19 +848,22 @@ fn contains_ui_error_patterns(file_path: &Path) -> Result<bool, String> {
845
848
if line. is_empty ( ) {
846
849
continue ;
847
850
}
848
- if [
849
- "//@ error-pattern:" ,
850
- "//@ build-fail" ,
851
- "//@ run-fail" ,
852
- "-Cllvm-args" ,
853
- "//~" ,
854
- "thread" ,
855
- ]
851
+ if [ "//@ error-pattern:" , "//@ build-fail" , "//@ run-fail" , "-Cllvm-args" , "//~" , "thread" ]
856
852
. iter ( )
857
853
. any ( |check| line. contains ( check) )
858
854
{
859
855
return Ok ( true ) ;
860
856
}
857
+
858
+ if !keep_lto_tests
859
+ && ( line. contains ( "-Clto" )
860
+ || line. contains ( "-C lto" )
861
+ || line. contains ( "compile-flags: -Clinker-plugin-lto" ) )
862
+ && !line. contains ( "-Clto=thin" )
863
+ {
864
+ return Ok ( true ) ;
865
+ }
866
+
861
867
if line. contains ( "//[" ) && line. contains ( "]~" ) {
862
868
return Ok ( true ) ;
863
869
}
@@ -903,7 +909,7 @@ where
903
909
rust_path. join ( "tests/ui" ) ,
904
910
& mut |_dir| Ok ( ( ) ) ,
905
911
& mut |file_path| {
906
- if contains_ui_error_patterns ( file_path) ? {
912
+ if contains_ui_error_patterns ( file_path, args . keep_lto_tests ) ? {
907
913
Ok ( ( ) )
908
914
} else {
909
915
remove_file ( file_path) . map_err ( |e| e. to_string ( ) )
@@ -928,7 +934,7 @@ where
928
934
. iter ( )
929
935
. any ( |name| * name == dir_name)
930
936
{
931
- std :: fs :: remove_dir_all ( dir) . map_err ( |error| {
937
+ remove_dir_all ( dir) . map_err ( |error| {
932
938
format ! ( "Failed to remove folder `{}`: {:?}" , dir. display( ) , error)
933
939
} ) ?;
934
940
}
@@ -940,27 +946,42 @@ where
940
946
941
947
// These two functions are used to remove files that are known to not be working currently
942
948
// with the GCC backend to reduce noise.
943
- fn dir_handling ( dir : & Path ) -> Result < ( ) , String > {
944
- if dir. file_name ( ) . map ( |name| name == "auxiliary" ) . unwrap_or ( true ) {
945
- return Ok ( ( ) ) ;
946
- }
949
+ fn dir_handling ( keep_lto_tests : bool ) -> impl Fn ( & Path ) -> Result < ( ) , String > {
950
+ move |dir| {
951
+ if dir. file_name ( ) . map ( |name| name == "auxiliary" ) . unwrap_or ( true ) {
952
+ return Ok ( ( ) ) ;
953
+ }
947
954
948
- walk_dir ( dir, & mut dir_handling, & mut file_handling, false )
949
- }
950
- fn file_handling ( file_path : & Path ) -> Result < ( ) , String > {
951
- if !file_path. extension ( ) . map ( |extension| extension == "rs" ) . unwrap_or ( false ) {
952
- return Ok ( ( ) ) ;
955
+ walk_dir (
956
+ dir,
957
+ & mut dir_handling ( keep_lto_tests) ,
958
+ & mut file_handling ( keep_lto_tests) ,
959
+ false ,
960
+ )
953
961
}
954
- let path_str = file_path. display ( ) . to_string ( ) . replace ( "\\ " , "/" ) ;
955
- if valid_ui_error_pattern_test ( & path_str) {
956
- return Ok ( ( ) ) ;
957
- } else if contains_ui_error_patterns ( file_path) ? {
958
- return remove_file ( & file_path) ;
962
+ }
963
+
964
+ fn file_handling ( keep_lto_tests : bool ) -> impl Fn ( & Path ) -> Result < ( ) , String > {
965
+ move |file_path| {
966
+ if !file_path. extension ( ) . map ( |extension| extension == "rs" ) . unwrap_or ( false ) {
967
+ return Ok ( ( ) ) ;
968
+ }
969
+ let path_str = file_path. display ( ) . to_string ( ) . replace ( "\\ " , "/" ) ;
970
+ if valid_ui_error_pattern_test ( & path_str) {
971
+ return Ok ( ( ) ) ;
972
+ } else if contains_ui_error_patterns ( file_path, keep_lto_tests) ? {
973
+ return remove_file ( & file_path) ;
974
+ }
975
+ Ok ( ( ) )
959
976
}
960
- Ok ( ( ) )
961
977
}
962
978
963
- walk_dir ( rust_path. join ( "tests/ui" ) , & mut dir_handling, & mut file_handling, false ) ?;
979
+ walk_dir (
980
+ rust_path. join ( "tests/ui" ) ,
981
+ & mut dir_handling ( args. keep_lto_tests ) ,
982
+ & mut file_handling ( args. keep_lto_tests ) ,
983
+ false ,
984
+ ) ?;
964
985
}
965
986
let nb_parts = args. nb_parts . unwrap_or ( 0 ) ;
966
987
if nb_parts > 0 {
@@ -1173,7 +1194,7 @@ fn remove_files_callback<'a>(
1173
1194
files. split ( '\n' ) . map ( |line| line. trim ( ) ) . filter ( |line| !line. is_empty ( ) )
1174
1195
{
1175
1196
let path = rust_path. join ( file) ;
1176
- if let Err ( e) = std :: fs :: remove_dir_all ( & path) {
1197
+ if let Err ( e) = remove_dir_all ( & path) {
1177
1198
println ! ( "Failed to remove directory `{}`: {}" , path. display( ) , e) ;
1178
1199
}
1179
1200
}
0 commit comments