Skip to content

Add --toolchain option for test command #697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 43 additions & 28 deletions build_system/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ fn show_usage() {
--use-system-gcc : Use system installed libgccjit
--build-only : Only build rustc_codegen_gcc then exits
--nb-parts : Used to split rustc_tests (for CI needs)
--current-part : Used with `--nb-parts`, allows you to specify which parts to test"#
--current-part : Used with `--nb-parts`, allows you to specify which parts to test
--toolchain [arg] : The (rustc) toolchain to be used"#
);
ConfigInfo::show_usage();
for (option, (doc, _)) in get_runners() {
Expand All @@ -95,6 +96,7 @@ struct TestArg {
sysroot_panic_abort: bool,
config_info: ConfigInfo,
sysroot_features: Vec<String>,
toolchain_name: Option<String>,
keep_lto_tests: bool,
}

Expand Down Expand Up @@ -142,6 +144,18 @@ impl TestArg {
return Err(format!("Expected an argument after `{}`, found nothing", arg));
}
},
"--toolchain" => match args.next() {
Some(toolchain_name) if !toolchain_name.is_empty() => {
if !toolchain_name.starts_with('+') {
test_arg.toolchain_name = Some(format!("+{toolchain_name}"));
} else {
test_arg.toolchain_name = Some(toolchain_name);
}
}
_ => {
return Err(format!("Expected an argument after `{}`, found nothing", arg));
}
},
"--help" => {
show_usage();
return Ok(None);
Expand Down Expand Up @@ -181,7 +195,7 @@ impl TestArg {
}

fn build_if_no_backend(env: &Env, args: &TestArg) -> Result<(), String> {
if args.config_info.backend.is_some() {
if args.config_info.backend.is_some() || args.toolchain_name.is_some() {
return Ok(());
}
let mut command: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"rustc"];
Expand Down Expand Up @@ -459,6 +473,15 @@ fn std_tests(env: &Env, args: &TestArg) -> Result<(), String> {
Ok(())
}

fn get_rustc_path_for_toolchain(toolchain: &str, cwd: Option<&Path>) -> Result<String, String> {
String::from_utf8(run_command(&[&"rustup", &toolchain, &"which", &"rustc"], cwd)?.stdout)
.map_err(|error| format!("Failed to retrieve rustc path: {:?}", error))
.and_then(|rustc| {
let rustc = rustc.trim().to_owned();
if rustc.is_empty() { Err(format!("`rustc` path is empty")) } else { Ok(rustc) }
})
}

fn setup_rustc(env: &mut Env, args: &TestArg) -> Result<PathBuf, String> {
let toolchain = format!(
"+{channel}-{host}",
Expand Down Expand Up @@ -517,15 +540,7 @@ fn setup_rustc(env: &mut Env, args: &TestArg) -> Result<PathBuf, String> {
let cargo = cargo.trim().to_owned();
if cargo.is_empty() { Err(format!("`cargo` path is empty")) } else { Ok(cargo) }
})?;
let rustc = String::from_utf8(
run_command_with_env(&[&"rustup", &toolchain, &"which", &"rustc"], rust_dir, Some(env))?
.stdout,
)
.map_err(|error| format!("Failed to retrieve rustc path: {:?}", error))
.and_then(|rustc| {
let rustc = rustc.trim().to_owned();
if rustc.is_empty() { Err(format!("`rustc` path is empty")) } else { Ok(rustc) }
})?;
let rustc = get_rustc_path_for_toolchain(&toolchain, rust_dir)?;
let llvm_filecheck = match run_command_with_env(
&[
&"bash",
Expand Down Expand Up @@ -644,8 +659,10 @@ fn run_cargo_command_with_callback<F>(
where
F: Fn(&[&dyn AsRef<OsStr>], Option<&Path>, &Env) -> Result<(), String>,
{
let toolchain = get_toolchain()?;
let toolchain_arg = format!("+{}", toolchain);
let toolchain_arg = match args.toolchain_name {
Some(ref toolchain) => toolchain.clone(),
None => format!("+{}", get_toolchain()?),
};
let rustc_version = String::from_utf8(
run_command_with_env(&[&args.config_info.rustc_command[0], &"-V"], cwd, Some(env))?.stdout,
)
Expand Down Expand Up @@ -1098,21 +1115,19 @@ where

env.get_mut("RUSTFLAGS").unwrap().clear();

run_command_with_output_and_env(
&[
&"./x.py",
&"test",
&"--run",
&"always",
&"--stage",
&"0",
&format!("tests/{}", test_type),
&"--compiletest-rustc-args",
&rustc_args,
],
Some(&rust_path),
Some(&env),
)?;
let test_type = format!("tests/{}", test_type);
let mut command: Vec<&dyn AsRef<OsStr>> =
vec![&"./x.py", &"test", &"--run", &"always", &"--stage", &"0", &test_type];
let rustc;
if let Some(ref toolchain) = args.toolchain_name {
env.insert("COMPILETEST_FORCE_STAGE0=1".to_string(), "1".to_string());
command.push(&"--set");
rustc = format!("build.rustc={}", get_rustc_path_for_toolchain(toolchain, None)?);
command.push(&rustc);
}
command.push(&"--compiletest-rustc-args");
command.push(&rustc_args);
run_command_with_output_and_env(&command, Some(&rust_path), Some(&env))?;
Ok(())
}

Expand Down