|
1 | 1 | use xshell::{cmd, pushd};
|
2 | 2 |
|
| 3 | +use bitflags::bitflags; |
| 4 | + |
| 5 | +bitflags! { |
| 6 | + struct Check: u32 { |
| 7 | + const FORMAT = 0b00000001; |
| 8 | + const CLIPPY = 0b00000010; |
| 9 | + const COMPILE_FAIL = 0b00000100; |
| 10 | + const TEST = 0b00001000; |
| 11 | + const DOC_TEST = 0b00010000; |
| 12 | + const DOC_CHECK = 0b00100000; |
| 13 | + const BENCH_CHECK = 0b01000000; |
| 14 | + const EXAMPLE_CHECK = 0b10000000; |
| 15 | + } |
| 16 | +} |
| 17 | + |
3 | 18 | fn main() {
|
4 | 19 | // When run locally, results may differ from actual CI runs triggered by
|
5 | 20 | // .github/workflows/ci.yml
|
6 | 21 | // - Official CI runs latest stable
|
7 | 22 | // - Local runs use whatever the default Rust is locally
|
8 | 23 |
|
9 |
| - // See if any code needs to be formatted |
10 |
| - cmd!("cargo fmt --all -- --check") |
11 |
| - .run() |
12 |
| - .expect("Please run 'cargo fmt --all' to format your code."); |
| 24 | + let what_to_run = match std::env::args().nth(1).as_deref() { |
| 25 | + Some("format") => Check::FORMAT, |
| 26 | + Some("clippy") => Check::CLIPPY, |
| 27 | + Some("compile-fail") => Check::COMPILE_FAIL, |
| 28 | + Some("test") => Check::TEST, |
| 29 | + Some("doc-test") => Check::DOC_TEST, |
| 30 | + Some("doc-check") => Check::DOC_CHECK, |
| 31 | + Some("bench-check") => Check::BENCH_CHECK, |
| 32 | + Some("example-check") => Check::EXAMPLE_CHECK, |
| 33 | + Some("lints") => Check::FORMAT | Check::CLIPPY, |
| 34 | + Some("doc") => Check::DOC_TEST | Check::DOC_CHECK, |
| 35 | + Some("compile") => Check::COMPILE_FAIL | Check::BENCH_CHECK | Check::EXAMPLE_CHECK, |
| 36 | + _ => Check::all(), |
| 37 | + }; |
13 | 38 |
|
14 |
| - // See if clippy has any complaints. |
15 |
| - // - Type complexity must be ignored because we use huge templates for queries |
16 |
| - cmd!("cargo clippy --workspace --all-targets --all-features -- -D warnings -A clippy::type_complexity -W clippy::doc_markdown") |
| 39 | + if what_to_run.contains(Check::FORMAT) { |
| 40 | + // See if any code needs to be formatted |
| 41 | + cmd!("cargo fmt --all -- --check") |
| 42 | + .run() |
| 43 | + .expect("Please run 'cargo fmt --all' to format your code."); |
| 44 | + } |
| 45 | + |
| 46 | + if what_to_run.contains(Check::CLIPPY) { |
| 47 | + // See if clippy has any complaints. |
| 48 | + // - Type complexity must be ignored because we use huge templates for queries |
| 49 | + cmd!("cargo clippy --workspace --all-targets --all-features -- -A clippy::type_complexity -W clippy::doc_markdown -D warnings") |
17 | 50 | .run()
|
18 | 51 | .expect("Please fix clippy errors in output above.");
|
| 52 | + } |
19 | 53 |
|
20 |
| - // Run UI tests (they do not get executed with the workspace tests) |
21 |
| - // - See crates/bevy_ecs_compile_fail_tests/README.md |
22 |
| - { |
| 54 | + if what_to_run.contains(Check::COMPILE_FAIL) { |
| 55 | + // Run UI tests (they do not get executed with the workspace tests) |
| 56 | + // - See crates/bevy_ecs_compile_fail_tests/README.md |
23 | 57 | let _bevy_ecs_compile_fail_tests = pushd("crates/bevy_ecs_compile_fail_tests")
|
24 | 58 | .expect("Failed to navigate to the 'bevy_ecs_compile_fail_tests' crate");
|
25 |
| - cmd!("cargo test") |
| 59 | + cmd!("cargo test --target-dir ../../target") |
26 | 60 | .run()
|
27 | 61 | .expect("Compiler errors of the ECS compile fail tests seem to be different than expected! Check locally and compare rust versions.");
|
28 | 62 | }
|
29 | 63 |
|
30 |
| - // These tests are already run on the CI |
31 |
| - // Using a double-negative here allows end-users to have a nicer experience |
32 |
| - // as we can pass in the extra argument to the CI script |
33 |
| - let args: Vec<String> = std::env::args().collect(); |
34 |
| - if args.get(1) != Some(&"nonlocal".to_string()) { |
35 |
| - // Run tests |
36 |
| - cmd!("cargo test --workspace") |
| 64 | + if what_to_run.contains(Check::TEST) { |
| 65 | + // Run tests (except doc tests and without building examples) |
| 66 | + cmd!("cargo test --workspace --lib --bins --tests --benches") |
37 | 67 | .run()
|
38 | 68 | .expect("Please fix failing tests in output above.");
|
| 69 | + } |
| 70 | + |
| 71 | + if what_to_run.contains(Check::DOC_TEST) { |
| 72 | + // Run doc tests |
| 73 | + cmd!("cargo test --workspace --doc") |
| 74 | + .run() |
| 75 | + .expect("Please fix failing doc-tests in output above."); |
| 76 | + } |
| 77 | + |
| 78 | + if what_to_run.contains(Check::DOC_CHECK) { |
| 79 | + // Check that building docs work and does not emit warnings |
| 80 | + std::env::set_var("RUSTDOCFLAGS", "-D warnings"); |
| 81 | + cmd!("cargo doc --workspace --all-features --no-deps --document-private-items") |
| 82 | + .run() |
| 83 | + .expect("Please fix doc warnings in output above."); |
| 84 | + } |
| 85 | + |
| 86 | + if what_to_run.contains(Check::COMPILE_FAIL) { |
| 87 | + // Check that benches are building |
| 88 | + let _benches = pushd("benches").expect("Failed to navigate to the 'benches' folder"); |
| 89 | + cmd!("cargo check --benches --target-dir ../target") |
| 90 | + .run() |
| 91 | + .expect("Failed to check the benches."); |
| 92 | + } |
39 | 93 |
|
40 |
| - // Run doc tests: these are ignored by `cargo test` |
41 |
| - cmd!("cargo test --doc --workspace") |
| 94 | + if what_to_run.contains(Check::EXAMPLE_CHECK) { |
| 95 | + // Build examples and check they compile |
| 96 | + cmd!("cargo check --workspace --examples") |
42 | 97 | .run()
|
43 | 98 | .expect("Please fix failing doc-tests in output above.");
|
44 | 99 | }
|
|
0 commit comments