2022-05-30 16:21:03 +00:00
|
|
|
use xshell::{cmd, Shell};
|
2021-02-22 08:42:19 +00:00
|
|
|
|
2022-05-02 19:13:34 +00:00
|
|
|
use bitflags::bitflags;
|
|
|
|
|
|
|
|
bitflags! {
|
|
|
|
struct Check: u32 {
|
|
|
|
const FORMAT = 0b00000001;
|
|
|
|
const CLIPPY = 0b00000010;
|
|
|
|
const COMPILE_FAIL = 0b00000100;
|
|
|
|
const TEST = 0b00001000;
|
|
|
|
const DOC_TEST = 0b00010000;
|
|
|
|
const DOC_CHECK = 0b00100000;
|
|
|
|
const BENCH_CHECK = 0b01000000;
|
|
|
|
const EXAMPLE_CHECK = 0b10000000;
|
2022-05-06 19:29:44 +00:00
|
|
|
const COMPILE_CHECK = 0b100000000;
|
2022-05-02 19:13:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-22 08:42:19 +00:00
|
|
|
fn main() {
|
2021-03-11 00:27:30 +00:00
|
|
|
// When run locally, results may differ from actual CI runs triggered by
|
|
|
|
// .github/workflows/ci.yml
|
2021-02-22 08:42:19 +00:00
|
|
|
// - Official CI runs latest stable
|
|
|
|
// - Local runs use whatever the default Rust is locally
|
|
|
|
|
2022-05-02 19:13:34 +00:00
|
|
|
let what_to_run = match std::env::args().nth(1).as_deref() {
|
|
|
|
Some("format") => Check::FORMAT,
|
|
|
|
Some("clippy") => Check::CLIPPY,
|
|
|
|
Some("compile-fail") => Check::COMPILE_FAIL,
|
|
|
|
Some("test") => Check::TEST,
|
|
|
|
Some("doc-test") => Check::DOC_TEST,
|
|
|
|
Some("doc-check") => Check::DOC_CHECK,
|
|
|
|
Some("bench-check") => Check::BENCH_CHECK,
|
|
|
|
Some("example-check") => Check::EXAMPLE_CHECK,
|
|
|
|
Some("lints") => Check::FORMAT | Check::CLIPPY,
|
|
|
|
Some("doc") => Check::DOC_TEST | Check::DOC_CHECK,
|
2022-05-06 19:29:44 +00:00
|
|
|
Some("compile") => {
|
|
|
|
Check::COMPILE_FAIL | Check::BENCH_CHECK | Check::EXAMPLE_CHECK | Check::COMPILE_CHECK
|
|
|
|
}
|
2022-05-02 19:13:34 +00:00
|
|
|
_ => Check::all(),
|
|
|
|
};
|
2021-02-22 08:42:19 +00:00
|
|
|
|
2022-05-30 16:21:03 +00:00
|
|
|
let sh = Shell::new().unwrap();
|
|
|
|
|
2022-05-02 19:13:34 +00:00
|
|
|
if what_to_run.contains(Check::FORMAT) {
|
|
|
|
// See if any code needs to be formatted
|
2022-05-30 16:21:03 +00:00
|
|
|
cmd!(sh, "cargo fmt --all -- --check")
|
2022-05-02 19:13:34 +00:00
|
|
|
.run()
|
|
|
|
.expect("Please run 'cargo fmt --all' to format your code.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if what_to_run.contains(Check::CLIPPY) {
|
|
|
|
// See if clippy has any complaints.
|
|
|
|
// - Type complexity must be ignored because we use huge templates for queries
|
2022-05-30 16:21:03 +00:00
|
|
|
cmd!(sh, "cargo clippy --workspace --all-targets --all-features -- -A clippy::type_complexity -W clippy::doc_markdown -D warnings")
|
2021-11-13 22:43:19 +00:00
|
|
|
.run()
|
|
|
|
.expect("Please fix clippy errors in output above.");
|
2022-05-02 19:13:34 +00:00
|
|
|
}
|
2021-11-13 22:43:19 +00:00
|
|
|
|
2022-05-02 19:13:34 +00:00
|
|
|
if what_to_run.contains(Check::COMPILE_FAIL) {
|
|
|
|
// Run UI tests (they do not get executed with the workspace tests)
|
|
|
|
// - See crates/bevy_ecs_compile_fail_tests/README.md
|
2022-05-30 16:21:03 +00:00
|
|
|
let _subdir = sh.push_dir("crates/bevy_ecs_compile_fail_tests");
|
|
|
|
cmd!(sh, "cargo test --target-dir ../../target")
|
2021-11-13 22:43:19 +00:00
|
|
|
.run()
|
|
|
|
.expect("Compiler errors of the ECS compile fail tests seem to be different than expected! Check locally and compare rust versions.");
|
|
|
|
}
|
2022-02-03 04:25:45 +00:00
|
|
|
|
2022-05-02 19:13:34 +00:00
|
|
|
if what_to_run.contains(Check::TEST) {
|
|
|
|
// Run tests (except doc tests and without building examples)
|
2022-05-30 16:21:03 +00:00
|
|
|
cmd!(sh, "cargo test --workspace --lib --bins --tests --benches")
|
2022-02-03 04:25:45 +00:00
|
|
|
.run()
|
|
|
|
.expect("Please fix failing tests in output above.");
|
2022-05-02 19:13:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if what_to_run.contains(Check::DOC_TEST) {
|
|
|
|
// Run doc tests
|
2022-05-30 16:21:03 +00:00
|
|
|
cmd!(sh, "cargo test --workspace --doc")
|
2022-05-02 19:13:34 +00:00
|
|
|
.run()
|
|
|
|
.expect("Please fix failing doc-tests in output above.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if what_to_run.contains(Check::DOC_CHECK) {
|
|
|
|
// Check that building docs work and does not emit warnings
|
|
|
|
std::env::set_var("RUSTDOCFLAGS", "-D warnings");
|
2022-05-30 16:21:03 +00:00
|
|
|
cmd!(
|
|
|
|
sh,
|
|
|
|
"cargo doc --workspace --all-features --no-deps --document-private-items"
|
|
|
|
)
|
|
|
|
.run()
|
|
|
|
.expect("Please fix doc warnings in output above.");
|
2022-05-02 19:13:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if what_to_run.contains(Check::COMPILE_FAIL) {
|
2022-05-30 16:21:03 +00:00
|
|
|
let _subdir = sh.push_dir("benches");
|
2022-05-02 19:13:34 +00:00
|
|
|
// Check that benches are building
|
2022-05-30 16:21:03 +00:00
|
|
|
cmd!(sh, "cargo check --benches --target-dir ../target")
|
2022-05-02 19:13:34 +00:00
|
|
|
.run()
|
|
|
|
.expect("Failed to check the benches.");
|
|
|
|
}
|
2022-02-03 04:25:45 +00:00
|
|
|
|
2022-05-02 19:13:34 +00:00
|
|
|
if what_to_run.contains(Check::EXAMPLE_CHECK) {
|
|
|
|
// Build examples and check they compile
|
2022-05-30 16:21:03 +00:00
|
|
|
cmd!(sh, "cargo check --workspace --examples")
|
2022-02-03 04:25:45 +00:00
|
|
|
.run()
|
|
|
|
.expect("Please fix failing doc-tests in output above.");
|
|
|
|
}
|
2022-05-06 19:29:44 +00:00
|
|
|
|
|
|
|
if what_to_run.contains(Check::COMPILE_CHECK) {
|
|
|
|
// Build examples and check they compile
|
2022-05-30 16:21:03 +00:00
|
|
|
cmd!(sh, "cargo check --workspace")
|
2022-05-06 19:29:44 +00:00
|
|
|
.run()
|
|
|
|
.expect("Please fix failing doc-tests in output above.");
|
|
|
|
}
|
2021-02-22 08:42:19 +00:00
|
|
|
}
|