Skip to content

Commit ae56c8c

Browse files
committed
modifed y.sh to allow for running cargo tests.
1 parent cfe88fa commit ae56c8c

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

build_system/src/test.rs

+31-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn get_runners() -> Runners {
4242
);
4343
runners.insert("--extended-regex-tests", ("Run extended regex tests", extended_regex_tests));
4444
runners.insert("--mini-tests", ("Run mini tests", mini_tests));
45-
45+
runners.insert("--cargo-tests", ("Run cargo tests", cargo_tests));
4646
runners
4747
}
4848

@@ -88,6 +88,8 @@ struct TestArg {
8888
use_system_gcc: bool,
8989
runners: Vec<String>,
9090
flags: Vec<String>,
91+
/// Additonal arguments, to be passed to commands like `cargo test`.
92+
test_args: Vec<String>,
9193
nb_parts: Option<usize>,
9294
current_part: Option<usize>,
9395
sysroot_panic_abort: bool,
@@ -144,6 +146,7 @@ impl TestArg {
144146
show_usage();
145147
return Ok(None);
146148
}
149+
"--" => test_arg.test_args.extend(&mut args),
147150
x if runners.contains_key(x)
148151
&& !test_arg.runners.iter().any(|runner| runner == x) =>
149152
{
@@ -203,6 +206,32 @@ fn clean(_env: &Env, args: &TestArg) -> Result<(), String> {
203206
create_dir(&path)
204207
}
205208

209+
fn cargo_tests(test_env: &Env, test_args: &TestArg) -> Result<(), String> {
210+
// First, we call `mini_tests` to build minicore for us. This ensures we are testing with a working `minicore`,
211+
// and that any changes we have made affect `minicore`(since it would get rebuilt).
212+
mini_tests(test_env, test_args)?;
213+
// Then, we copy some of the env vars from `test_env`
214+
// We don't want to pass things like `RUSTFLAGS`, since they contain the -Zcodegen-backend flag.
215+
// That would force `cg_gcc` to *rebuild itself* and only then run tests, which is undesirable.
216+
let mut env = HashMap::new();
217+
env.insert(
218+
"LD_LIBRARY_PATH".into(),
219+
test_env.get("LD_LIBRARY_PATH").expect("LD_LIBRARY_PATH missing!").to_string(),
220+
);
221+
env.insert(
222+
"LIBRARY_PATH".into(),
223+
test_env.get("LIBRARY_PATH").expect("LIBRARY_PATH missing!").to_string(),
224+
);
225+
env.insert(
226+
"CG_RUSTFLAGS".into(),
227+
test_env.get("CG_RUSTFLAGS").map(|s| s.as_str()).unwrap_or("").to_string(),
228+
);
229+
// Pass all the default args + the user-specified ones.
230+
let mut args: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"test"];
231+
args.extend(test_args.test_args.iter().map(|s| s as &dyn AsRef<OsStr>));
232+
run_command_with_output_and_env(&args, None, Some(&env))?;
233+
Ok(())
234+
}
206235
fn mini_tests(env: &Env, args: &TestArg) -> Result<(), String> {
207236
// FIXME: create a function "display_if_not_quiet" or something along the line.
208237
println!("[BUILD] mini_core");
@@ -1218,6 +1247,7 @@ fn run_all(env: &Env, args: &TestArg) -> Result<(), String> {
12181247
test_libcore(env, args)?;
12191248
extended_sysroot_tests(env, args)?;
12201249
test_rustc(env, args)?;
1250+
cargo_tests(env, args)?;
12211251
Ok(())
12221252
}
12231253

0 commit comments

Comments
 (0)