Skip to content

Commit 9da753c

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

File tree

6 files changed

+37
-9
lines changed

6 files changed

+37
-9
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ jobs:
8080
run: |
8181
./y.sh prepare --only-libcore
8282
./y.sh build --sysroot
83-
./y.sh test --mini-tests
84-
cargo test
83+
./y.sh --cargo-tests
8584
8685
- name: Run y.sh cargo build
8786
run: |
@@ -122,7 +121,7 @@ jobs:
122121
- name: Test build system
123122
run: |
124123
cd build_system
125-
cargo test
124+
./y.sh --cargo-tests
126125
127126
# Summary job for the merge queue.
128127
# ALL THE PREVIOUS JOBS NEED TO BE ADDED TO THE `needs` SECTION OF THIS JOB!

.github/workflows/m68k.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ jobs:
9595
./y.sh prepare --only-libcore --cross
9696
./y.sh build --sysroot --features compiler_builtins/no-f16-f128 --target-triple m68k-unknown-linux-gnu
9797
./y.sh test --mini-tests
98-
CG_GCC_TEST_TARGET=m68k-unknown-linux-gnu cargo test
98+
CG_GCC_TEST_TARGET=m68k-unknown-linux-gnu ./y.sh --cargo-tests
9999
./y.sh clean all
100100
101101
- name: Prepare dependencies

.github/workflows/release.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ jobs:
5656
run: |
5757
./y.sh prepare --only-libcore
5858
EMBED_LTO_BITCODE=1 ./y.sh build --sysroot --release --release-sysroot
59-
./y.sh test --mini-tests
60-
cargo test
59+
./y.sh --cargo-tests
6160
./y.sh clean all
6261
6362
- name: Prepare dependencies

.github/workflows/stdarch.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090
if: ${{ !matrix.cargo_runner }}
9191
run: |
9292
./y.sh test --release --clean --release-sysroot --build-sysroot --mini-tests --std-tests --test-libcore
93-
cargo test
93+
./y.sh --cargo-tests
9494
9595
- name: Run stdarch tests
9696
if: ${{ !matrix.cargo_runner }}

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ To run specific tests, use appropriate flags such as:
3333

3434
- `./y.sh test --test-libcore`
3535
- `./y.sh test --std-tests`
36-
- `cargo test -- <name of test>`
36+
- `./y.sh test --cargo-tests <name of test>`
3737

3838
Additionally, you can run the tests of `libgccjit`:
3939

build_system/src/test.rs

Lines changed: 31 additions & 1 deletion
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)