Skip to content

Commit 867ea12

Browse files
Fix non-running rustc ui tests
1 parent ebb7aa0 commit 867ea12

File tree

4 files changed

+108
-103
lines changed

4 files changed

+108
-103
lines changed

build_system/src/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
128128
&[
129129
&"cargo",
130130
&"build",
131+
&"--release",
131132
&"--target",
132133
&config.target_triple,
133-
&"--release",
134134
],
135135
Some(start_dir),
136136
Some(&env),

build_system/src/config.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ pub struct ConfigInfo {
1313
pub dylib_ext: String,
1414
pub sysroot_release_channel: bool,
1515
pub sysroot_panic_abort: bool,
16+
pub cg_backend_path: String,
17+
pub sysroot_path: String,
1618
}
1719

1820
impl ConfigInfo {
@@ -118,13 +120,12 @@ impl ConfigInfo {
118120
.get("BUILTIN_BACKEND")
119121
.map(|backend| !backend.is_empty())
120122
.unwrap_or(false);
121-
let cg_backend_path;
122123

123124
let mut rustflags = Vec::new();
124125
if has_builtin_backend {
125126
// It means we're building inside the rustc testsuite, so some options need to be handled
126127
// a bit differently.
127-
cg_backend_path = "gcc".to_string();
128+
self.cg_backend_path = "gcc".to_string();
128129

129130
match env.get("RUSTC_SYSROOT") {
130131
Some(rustc_sysroot) if !rustc_sysroot.is_empty() => {
@@ -134,15 +135,17 @@ impl ConfigInfo {
134135
}
135136
rustflags.push("-Cpanic=abort".to_string());
136137
} else {
137-
cg_backend_path = current_dir
138+
self.cg_backend_path = current_dir
138139
.join("target")
139140
.join(channel)
140141
.join(&format!("librustc_codegen_gcc.{}", self.dylib_ext))
141142
.display()
142143
.to_string();
143-
let sysroot_path = current_dir.join("build_sysroot/sysroot");
144-
rustflags
145-
.extend_from_slice(&["--sysroot".to_string(), sysroot_path.display().to_string()]);
144+
self.sysroot_path = current_dir
145+
.join("build_sysroot/sysroot")
146+
.display()
147+
.to_string();
148+
rustflags.extend_from_slice(&["--sysroot".to_string(), self.sysroot_path.clone()]);
146149
};
147150

148151
// This environment variable is useful in case we want to change options of rustc commands.
@@ -156,7 +159,7 @@ impl ConfigInfo {
156159
rustflags.extend_from_slice(&[
157160
"-Csymbol-mangling-version=v0".to_string(),
158161
"-Cdebuginfo=2".to_string(),
159-
format!("-Zcodegen-backend={}", cg_backend_path),
162+
format!("-Zcodegen-backend={}", self.cg_backend_path),
160163
]);
161164

162165
// Since we don't support ThinLTO, disable LTO completely when not trying to do LTO.

build_system/src/test.rs

Lines changed: 92 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use crate::build;
22
use crate::config::ConfigInfo;
33
use crate::utils::{
4-
get_gcc_path, get_toolchain, run_command, run_command_with_env,
4+
get_gcc_path, get_toolchain, remove_file, run_command, run_command_with_env,
55
run_command_with_output_and_env, rustc_version_info, split_args, walk_dir,
6-
remove_file,
76
};
87

98
use std::collections::{BTreeSet, HashMap};
109
use std::ffi::OsStr;
11-
use std::fs::{File, remove_dir_all};
10+
use std::fs::{remove_dir_all, File};
1211
use std::io::{BufRead, BufReader};
1312
use std::path::{Path, PathBuf};
1413
use std::str::FromStr;
@@ -213,8 +212,11 @@ impl TestArg {
213212
match (test_arg.current_part, test_arg.nb_parts) {
214213
(Some(_), Some(_)) | (None, None) => {}
215214
_ => {
216-
return Err("If either `--current-part` or `--nb-parts` is specified, the other one \
217-
needs to be specified as well!".to_string());
215+
return Err(
216+
"If either `--current-part` or `--nb-parts` is specified, the other one \
217+
needs to be specified as well!"
218+
.to_string(),
219+
);
218220
}
219221
}
220222
Ok(Some(test_arg))
@@ -230,20 +232,19 @@ fn build_if_no_backend(env: &Env, args: &TestArg) -> Result<(), String> {
230232
return Ok(());
231233
}
232234
let mut command: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"rustc"];
233-
if args.channel == Channel::Release {
234-
let mut env = env.clone();
235-
env.insert("CARGO_INCREMENTAL".to_string(), "1".to_string());
235+
let mut tmp_env;
236+
let env = if args.channel == Channel::Release {
237+
tmp_env = env.clone();
238+
tmp_env.insert("CARGO_INCREMENTAL".to_string(), "1".to_string());
236239
command.push(&"--release");
237-
for flag in args.flags.iter() {
238-
command.push(flag);
239-
}
240-
run_command_with_output_and_env(&command, None, Some(&env))
240+
&tmp_env
241241
} else {
242-
for flag in args.flags.iter() {
243-
command.push(flag);
244-
}
245-
run_command_with_output_and_env(&command, None, Some(&env))
242+
&env
243+
};
244+
for flag in args.flags.iter() {
245+
command.push(flag);
246246
}
247+
run_command_with_output_and_env(&command, None, Some(env))
247248
}
248249

249250
fn clean(_env: &Env, args: &TestArg) -> Result<(), String> {
@@ -403,11 +404,7 @@ fn std_tests(env: &Env, args: &TestArg) -> Result<(), String> {
403404
&args.config_info.target_triple,
404405
]);
405406
run_command_with_env(&command, None, Some(env))?;
406-
maybe_run_command_in_vm(
407-
&[&cargo_target_dir.join("alloc_example")],
408-
env,
409-
args,
410-
)?;
407+
maybe_run_command_in_vm(&[&cargo_target_dir.join("alloc_example")], env, args)?;
411408
}
412409

413410
// FIXME: create a function "display_if_not_quiet" or something along the line.
@@ -424,11 +421,7 @@ fn std_tests(env: &Env, args: &TestArg) -> Result<(), String> {
424421
&args.config_info.target_triple,
425422
]);
426423
run_command_with_env(&command, None, Some(env))?;
427-
maybe_run_command_in_vm(
428-
&[&cargo_target_dir.join("dst_field_align")],
429-
env,
430-
args,
431-
)?;
424+
maybe_run_command_in_vm(&[&cargo_target_dir.join("dst_field_align")], env, args)?;
432425

433426
// FIXME: create a function "display_if_not_quiet" or something along the line.
434427
println!("[AOT] std_example");
@@ -525,14 +518,15 @@ fn setup_rustc(env: &mut Env, args: &TestArg) -> Result<(), String> {
525518
None,
526519
Some(env),
527520
);
521+
run_command(&[&"git", &"checkout", &"--", &"tests/"], rust_dir)?;
528522
run_command_with_output_and_env(&[&"git", &"fetch"], rust_dir, Some(env))?;
529523
let rustc_commit = match rustc_version_info(env.get("RUSTC").map(|s| s.as_str()))?.commit_hash {
530524
Some(commit_hash) => commit_hash,
531525
None => return Err("Couldn't retrieve rustc commit hash".to_string()),
532526
};
533527
run_command_with_output_and_env(&[&"git", &"checkout", &rustc_commit], rust_dir, Some(env))?;
534528
// FIXME: Is it really needed to empty `RUSTFLAGS` here?
535-
env.insert("RUSTFLAGS".to_string(), String::new());
529+
// env.insert("RUSTFLAGS".to_string(), String::new());
536530
let cargo = String::from_utf8(
537531
run_command_with_env(&[&"rustup", &"which", &"cargo"], rust_dir, Some(env))?.stdout,
538532
)
@@ -591,15 +585,6 @@ download-ci-llvm = false
591585
),
592586
)
593587
.map_err(|error| format!("Failed to write into `rust/config.toml`: {:?}", error))?;
594-
595-
let rustc_commit = match rustc_version_info(env.get("RUSTC").map(|s| s.as_str()))?.commit_hash {
596-
Some(commit_hash) => commit_hash,
597-
None => return Err("Couldn't retrieve rustc commit hash".to_string()),
598-
};
599-
// FIXME: create a function "display_if_not_quiet" or something along the line.
600-
println!("commit: {:?}", rustc_commit);
601-
let command: &[&dyn AsRef<OsStr>] = &[&"git", &"checkout", &rustc_commit, &"tests"];
602-
run_command_with_output_and_env(command, rust_dir, Some(env))?;
603588
Ok(())
604589
}
605590

@@ -834,27 +819,6 @@ fn extended_sysroot_tests(env: &Env, args: &TestArg) -> Result<(), String> {
834819
Ok(())
835820
}
836821

837-
fn should_remove_ui_test(file: File) -> bool {
838-
for line in BufReader::new(file).lines() {
839-
if let Ok(line) = line {
840-
if [
841-
"// error-pattern:",
842-
"// build-fail",
843-
"// run-fail",
844-
"-Cllvm-args",
845-
"//~",
846-
"// ~",
847-
]
848-
.iter()
849-
.any(|check| line.contains(check))
850-
{
851-
return true;
852-
}
853-
}
854-
}
855-
false
856-
}
857-
858822
fn should_not_remove_test(file: &str) -> bool {
859823
// contains //~ERROR, but shouldn't be removed
860824
[
@@ -870,21 +834,40 @@ fn should_not_remove_test(file: &str) -> bool {
870834
.any(|to_ignore| file.ends_with(to_ignore))
871835
}
872836

873-
fn should_remove_test(path: &Path, path_str: &str) -> bool {
837+
fn should_remove_test(file_path: &Path) -> Result<bool, String> {
874838
// Tests generating errors.
875-
path.file_name()
876-
.and_then(|name| name.to_str())
877-
.map(|name| name.contains("thread"))
878-
.unwrap_or(false)
879-
|| [
880-
"consts/issue-miri-1910.rs",
881-
// Tests generating errors.
882-
"consts/issue-94675.rs",
883-
// this test is oom-killed in the CI.
884-
"mir/mir_heavy/issue-miri-1910.rs",
839+
let file = File::open(file_path)
840+
.map_err(|error| format!("Failed to read `{}`: {:?}", file_path.display(), error))?;
841+
for line in BufReader::new(file).lines().filter_map(|line| line.ok()) {
842+
let line = line.trim();
843+
if line.is_empty() {
844+
continue;
845+
}
846+
if [
847+
"// error-pattern:",
848+
"// build-fail",
849+
"// run-fail",
850+
"-Cllvm-args",
851+
"//~",
852+
"thread",
885853
]
886854
.iter()
887-
.any(|to_ignore| path_str.ends_with(to_ignore))
855+
.any(|check| line.contains(check))
856+
{
857+
return Ok(true);
858+
}
859+
if line.contains("//[") && line.contains("]~") {
860+
return Ok(true);
861+
}
862+
}
863+
if file_path
864+
.display()
865+
.to_string()
866+
.contains("ambiguous-4-extern.rs")
867+
{
868+
eprintln!("nothing found for {file_path:?}");
869+
}
870+
Ok(false)
888871
}
889872

890873
fn test_rustc_inner<F>(env: &Env, args: &TestArg, prepare_files_callback: F) -> Result<(), String>
@@ -896,6 +879,8 @@ where
896879
let mut env = env.clone();
897880
setup_rustc(&mut env, args)?;
898881

882+
let rust_path = Path::new("rust");
883+
899884
walk_dir(
900885
"rust/tests/ui",
901886
|dir| {
@@ -924,32 +909,41 @@ where
924909
// These two functions are used to remove files that are known to not be working currently
925910
// with the GCC backend to reduce noise.
926911
fn dir_handling(dir: &Path) -> Result<(), String> {
912+
if dir
913+
.file_name()
914+
.map(|name| name == "auxiliary")
915+
.unwrap_or(true)
916+
{
917+
return Ok(());
918+
}
927919
walk_dir(dir, dir_handling, file_handling)
928920
}
929921
fn file_handling(file_path: &Path) -> Result<(), String> {
930-
let path_str = file_path.display().to_string().replace("\\", "/");
931-
if !path_str.ends_with(".rs") {
922+
if !file_path
923+
.extension()
924+
.map(|extension| extension == "rs")
925+
.unwrap_or(false)
926+
{
932927
return Ok(());
933-
} else if should_not_remove_test(&path_str) {
928+
}
929+
let path_str = file_path.display().to_string().replace("\\", "/");
930+
if should_not_remove_test(&path_str) {
934931
return Ok(());
935-
} else if should_remove_test(file_path, &path_str) {
932+
} else if should_remove_test(file_path)? {
936933
return remove_file(&file_path);
937934
}
938-
let file = File::open(file_path)
939-
.map_err(|error| format!("Failed to read `{}`: {:?}", file_path.display(), error))?;
940-
if should_remove_ui_test(file) {
941-
remove_file(&file_path)?;
942-
}
943935
Ok(())
944936
}
945937

946-
let rust_path = Path::new("rust");
938+
remove_file(&rust_path.join("tests/ui/consts/const_cmp_type_id.rs"))?;
939+
remove_file(&rust_path.join("tests/ui/consts/issue-73976-monomorphic.rs"))?;
940+
// this test is oom-killed in the CI.
941+
remove_file(&rust_path.join("tests/ui/consts/issue-miri-1910.rs"))?;
942+
// Tests generating errors.
943+
remove_file(&rust_path.join("tests/ui/consts/issue-94675.rs"))?;
944+
remove_file(&rust_path.join("tests/ui/mir/mir_heavy_promoted.rs"))?;
947945

948946
walk_dir(rust_path.join("tests/ui"), dir_handling, file_handling)?;
949-
let file = rust_path.join("tests/ui/consts/const_cmp_type_id.rs");
950-
remove_file(&file)?;
951-
let file = rust_path.join("tests/ui/consts/issue-73976-monomorphic.rs");
952-
remove_file(&file)?;
953947

954948
if !prepare_files_callback()? {
955949
// FIXME: create a function "display_if_not_quiet" or something along the line.
@@ -992,26 +986,30 @@ where
992986
// We increment the number of tests by one because if this is an odd number, we would skip
993987
// one test.
994988
let count = files.len() / nb_parts + 1;
995-
let start = nb_parts * count;
996-
let end = start + count;
997-
for (pos, path) in files.iter().enumerate() {
998-
if pos >= start && pos <= end {
999-
continue;
1000-
}
1001-
let test_path = rust_path.join(path);
1002-
remove_file(&test_path)?;
989+
let start = current_part * count;
990+
let end = current_part * count + count;
991+
// We remove the files we don't want to test.
992+
for path in files
993+
.iter()
994+
.enumerate()
995+
.filter(|(pos, _)| *pos < start || *pos >= end)
996+
.map(|(_, path)| path)
997+
{
998+
remove_file(&rust_path.join(path))?;
1003999
}
10041000
}
10051001

10061002
// FIXME: create a function "display_if_not_quiet" or something along the line.
10071003
println!("[TEST] rustc test suite");
10081004
env.insert("COMPILETEST_FORCE_STAGE0".to_string(), "1".to_string());
10091005
let rustc_args = format!(
1010-
"{} {}",
1011-
env.get("RUSTFLAGS")
1012-
.expect("RUSTFLAGS should not be empty at this stage"),
1006+
"{} -Csymbol-mangling-version=v0 -Zcodegen-backend={} --sysroot {}",
10131007
env.get("TEST_FLAGS").unwrap_or(&String::new()),
1008+
args.config_info.cg_backend_path,
1009+
args.config_info.sysroot_path,
10141010
);
1011+
1012+
env.get_mut("RUSTFLAGS").unwrap().clear();
10151013
run_command_with_output_and_env(
10161014
&[
10171015
&"./x.py",

build_system/src/utils.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,11 @@ pub fn split_args(args: &str) -> Result<Vec<String>, String> {
336336
}
337337
}
338338
if !found_end {
339-
return Err(format!("Didn't find `{}` at the end of `{}`", end, &args[start..]));
339+
return Err(format!(
340+
"Didn't find `{}` at the end of `{}`",
341+
end,
342+
&args[start..]
343+
));
340344
}
341345
} else if c == '\\' {
342346
// We skip the escaped character.

0 commit comments

Comments
 (0)