From c8ce99b2b49e5e8120ba561ee5a033353877b5fe Mon Sep 17 00:00:00 2001 From: michal kostrubiec Date: Fri, 9 May 2025 22:47:20 +0200 Subject: [PATCH] modifed y.sh to allow for running cargo tests. --- build_system/src/test.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/build_system/src/test.rs b/build_system/src/test.rs index df4ac85233b..8e709c3a7e2 100644 --- a/build_system/src/test.rs +++ b/build_system/src/test.rs @@ -42,7 +42,7 @@ fn get_runners() -> Runners { ); runners.insert("--extended-regex-tests", ("Run extended regex tests", extended_regex_tests)); runners.insert("--mini-tests", ("Run mini tests", mini_tests)); - + runners.insert("--cargo-tests", ("Run cargo tests", cargo_tests)); runners } @@ -88,6 +88,8 @@ struct TestArg { use_system_gcc: bool, runners: Vec, flags: Vec, + /// Additonal arguments, to be passed to commands like `cargo test`. + test_args: Vec, nb_parts: Option, current_part: Option, sysroot_panic_abort: bool, @@ -144,6 +146,7 @@ impl TestArg { show_usage(); return Ok(None); } + "--" => test_arg.test_args.extend(&mut args), x if runners.contains_key(x) && !test_arg.runners.iter().any(|runner| runner == x) => { @@ -203,6 +206,21 @@ fn clean(_env: &Env, args: &TestArg) -> Result<(), String> { create_dir(&path) } +fn cargo_tests(test_env: &Env, test_args: &TestArg) -> Result<(), String> { + // First, we call `mini_tests` to build minicore for us. This ensures we are testing with a working `minicore`, + // and that any changes we have made affect `minicore`(since it would get rebuilt). + mini_tests(test_env, test_args)?; + // Then, we copy the env vars from `test_env` + // We don't want to pass things like `RUSTFLAGS`, since they contain the -Zcodegen-backend flag. + // That would force `cg_gcc` to *rebuild itself* and only then run tests, which is undesirable. + let mut env = test_env.clone(); + env.remove("RUSTFLAGS"); + // Pass all the default args + the user-specified ones. + let mut args: Vec<&dyn AsRef> = vec![&"cargo", &"test"]; + args.extend(test_args.test_args.iter().map(|s| s as &dyn AsRef)); + run_command_with_output_and_env(&args, None, Some(&env))?; + Ok(()) +} fn mini_tests(env: &Env, args: &TestArg) -> Result<(), String> { // FIXME: create a function "display_if_not_quiet" or something along the line. println!("[BUILD] mini_core"); @@ -1218,6 +1236,7 @@ fn run_all(env: &Env, args: &TestArg) -> Result<(), String> { test_libcore(env, args)?; extended_sysroot_tests(env, args)?; test_rustc(env, args)?; + cargo_tests(env, args)?; Ok(()) }