Skip to content

Commit e1439ba

Browse files
committed
Automatically detect LTO tests to remove when the sysroot is not compiled with LTO
1 parent 660305d commit e1439ba

File tree

7 files changed

+52
-54
lines changed

7 files changed

+52
-54
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,6 @@ jobs:
9595
git config --global user.name "User"
9696
./y.sh prepare
9797
98-
- name: Add more failing tests because the sysroot is not compiled with LTO
99-
run: cat tests/failing-non-lto-tests.txt >> tests/failing-ui-tests.txt
100-
10198
- name: Run tests
10299
run: |
103100
./y.sh test --release --clean --build-sysroot ${{ matrix.commands }}

.github/workflows/failures.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ jobs:
9090
if: matrix.libgccjit_version.gcc != 'libgccjit12.so'
9191
run: ./y.sh prepare
9292

93-
- name: Add more failing tests because the sysroot is not compiled with LTO
94-
run: cat tests/failing-non-lto-tests.txt >> tests/failing-ui-tests.txt
95-
9693
- name: Run tests
9794
# TODO: re-enable those tests for libgccjit 12.
9895
if: matrix.libgccjit_version.gcc != 'libgccjit12.so'

.github/workflows/gcc12.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@ jobs:
8282
#- name: Add more failing tests for GCC 12
8383
#run: cat tests/failing-ui-tests12.txt >> tests/failing-ui-tests.txt
8484

85-
#- name: Add more failing tests because the sysroot is not compiled with LTO
86-
#run: cat tests/failing-non-lto-tests.txt >> tests/failing-ui-tests.txt
87-
8885
#- name: Run tests
8986
#run: |
9087
#./y.sh test --release --clean --build-sysroot ${{ matrix.commands }} --no-default-features

.github/workflows/m68k.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ jobs:
102102
git config --global user.name "User"
103103
./y.sh prepare --cross
104104
105-
- name: Add more failing tests because the sysroot is not compiled with LTO
106-
run: cat tests/failing-non-lto-tests.txt >> tests/failing-ui-tests.txt
107-
108105
- name: Run tests
109106
run: |
110107
./y.sh test --release --clean --build-sysroot --sysroot-features compiler_builtins/no-f16-f128 ${{ matrix.commands }}

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ jobs:
7070
run: |
7171
# FIXME(antoyo): we cannot enable LTO for stdarch tests currently because of some failing LTO tests using proc-macros.
7272
echo -n 'lto = "fat"' >> build_system/build_sysroot/Cargo.toml
73-
EMBED_LTO_BITCODE=1 ./y.sh test --release --clean --release-sysroot --build-sysroot ${{ matrix.commands }}
73+
EMBED_LTO_BITCODE=1 ./y.sh test --release --clean --release-sysroot --build-sysroot --keep-lto-tests ${{ matrix.commands }}

build_system/src/test.rs

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ struct TestArg {
9393
sysroot_panic_abort: bool,
9494
config_info: ConfigInfo,
9595
sysroot_features: Vec<String>,
96+
keep_lto_tests: bool,
9697
}
9798

9899
impl TestArg {
@@ -128,6 +129,9 @@ impl TestArg {
128129
"--sysroot-panic-abort" => {
129130
test_arg.sysroot_panic_abort = true;
130131
}
132+
"--keep-lto-tests" => {
133+
test_arg.keep_lto_tests = true;
134+
}
131135
"--sysroot-features" => match args.next() {
132136
Some(feature) if !feature.is_empty() => {
133137
test_arg.sysroot_features.push(feature);
@@ -194,7 +198,7 @@ fn build_if_no_backend(env: &Env, args: &TestArg) -> Result<(), String> {
194198
}
195199

196200
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);
198202
let path = Path::new(&args.config_info.cargo_target_dir).join("gccjit");
199203
create_dir(&path)
200204
}
@@ -835,8 +839,7 @@ fn valid_ui_error_pattern_test(file: &str) -> bool {
835839
.any(|to_ignore| file.ends_with(to_ignore))
836840
}
837841

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> {
840843
// Tests generating errors.
841844
let file = File::open(file_path)
842845
.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> {
845848
if line.is_empty() {
846849
continue;
847850
}
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"]
856852
.iter()
857853
.any(|check| line.contains(check))
858854
{
859855
return Ok(true);
860856
}
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+
861867
if line.contains("//[") && line.contains("]~") {
862868
return Ok(true);
863869
}
@@ -903,7 +909,7 @@ where
903909
rust_path.join("tests/ui"),
904910
&mut |_dir| Ok(()),
905911
&mut |file_path| {
906-
if contains_ui_error_patterns(file_path)? {
912+
if contains_ui_error_patterns(file_path, args.keep_lto_tests)? {
907913
Ok(())
908914
} else {
909915
remove_file(file_path).map_err(|e| e.to_string())
@@ -928,7 +934,7 @@ where
928934
.iter()
929935
.any(|name| *name == dir_name)
930936
{
931-
std::fs::remove_dir_all(dir).map_err(|error| {
937+
remove_dir_all(dir).map_err(|error| {
932938
format!("Failed to remove folder `{}`: {:?}", dir.display(), error)
933939
})?;
934940
}
@@ -940,27 +946,42 @@ where
940946

941947
// These two functions are used to remove files that are known to not be working currently
942948
// 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+
}
947954

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+
)
953961
}
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(())
959976
}
960-
Ok(())
961977
}
962978

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+
)?;
964985
}
965986
let nb_parts = args.nb_parts.unwrap_or(0);
966987
if nb_parts > 0 {
@@ -1173,7 +1194,7 @@ fn remove_files_callback<'a>(
11731194
files.split('\n').map(|line| line.trim()).filter(|line| !line.is_empty())
11741195
{
11751196
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) {
11771198
println!("Failed to remove directory `{}`: {}", path.display(), e);
11781199
}
11791200
}

tests/failing-non-lto-tests.txt

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)