From f7bf34f0cd6fb51ee588291231e43d1338c1460a Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Mon, 17 Apr 2023 13:29:28 -0400 Subject: [PATCH] Don't use bitfields for CI (#744) * Don't use bitfields for CI * Yeet unused depedency * Update Cargo.lock --- Cargo.lock | 26 ++++----- tools/ci/Cargo.toml | 2 +- tools/ci/src/main.rs | 125 +++++++++++++++++++++++++++++-------------- 3 files changed, 100 insertions(+), 53 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 16f9ecece..41854c47c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -363,7 +363,7 @@ checksum = "7556c913daacbec7aa213eda82517673bf6c6b25e0d827a56efe17421ebaca35" dependencies = [ "proc-macro2", "quote", - "syn 2.0.14", + "syn 2.0.15", ] [[package]] @@ -1191,7 +1191,7 @@ checksum = "fdde5c9cd29ebd706ce1b35600920a33550e402fc998a2e53ad3b42c3c47a192" dependencies = [ "proc-macro2", "quote", - "syn 2.0.14", + "syn 2.0.15", ] [[package]] @@ -1252,7 +1252,7 @@ checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" name = "ci" version = "0.1.0" dependencies = [ - "bitflags", + "bevy", "xshell", ] @@ -2426,9 +2426,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "leafwing-input-manager" -version = "0.9.1" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cff07db1736e8796568bfd58c789714d4a36827ab68ffae477b092532bd907e7" +checksum = "8ca8bb439a17e3a964829170cd0252ad54d25a22cb9eb07ec888a7c923d94e05" dependencies = [ "bevy", "derive_more", @@ -3157,9 +3157,9 @@ dependencies = [ [[package]] name = "profiling" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74605f360ce573babfe43964cbe520294dcb081afbf8c108fc6e23036b4da2df" +checksum = "332cd62e95873ea4f41f3dfd6bbbfc5b52aec892d7e8d534197c4720a0bbbab2" [[package]] name = "quote" @@ -3330,9 +3330,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4a36c42d1873f9a77c53bde094f9664d9891bc604a45b4798fd2c389ed12e5b" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "rustc-hash" @@ -3403,7 +3403,7 @@ checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df" dependencies = [ "proc-macro2", "quote", - "syn 2.0.14", + "syn 2.0.15", ] [[package]] @@ -3516,9 +3516,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.14" +version = "2.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcf316d5356ed6847742d036f8a39c3b8435cac10bd528a4bd461928a6ab34d5" +checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" dependencies = [ "proc-macro2", "quote", @@ -3582,7 +3582,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.14", + "syn 2.0.15", ] [[package]] diff --git a/tools/ci/Cargo.toml b/tools/ci/Cargo.toml index a3c03ddad..70455dbaf 100644 --- a/tools/ci/Cargo.toml +++ b/tools/ci/Cargo.toml @@ -8,4 +8,4 @@ license = "MIT OR Apache-2.0" [dependencies] xshell = "0.2" -bitflags = "1.3" +bevy = "0.10" diff --git a/tools/ci/src/main.rs b/tools/ci/src/main.rs index b970ba87f..4d62e6063 100644 --- a/tools/ci/src/main.rs +++ b/tools/ci/src/main.rs @@ -1,21 +1,68 @@ -//! Modified from [Bevy's CI runner](https://github.com/bevyengine/bevy/tree/main/tools/ci/src) +//! Runs a set of checks on the codebase, allowing for easy local testing of CI runs. +//! +//! Heavily modified from [Bevy's CI runner](https://github.com/bevyengine/bevy/tree/main/tools/ci/src) +//! When run locally, results may differ from actual CI runs triggered by +//! .github/workflows/ci.yml +//! - Official CI runs latest stable +//! - Local runs use whatever the default Rust is locally +use bevy::utils::HashSet; use xshell::{cmd, Shell}; -use bitflags::bitflags; +/// The checks that can be run in CI. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +enum Check { + Format, + Clippy, + Test, + DocTest, + DocCheck, + CompileCheck, +} + +impl Check { + /// Returns the complete set of checks. + fn all() -> HashSet { + [ + Check::Format, + Check::Clippy, + Check::Test, + Check::DocTest, + Check::DocCheck, + Check::CompileCheck, + ] + .iter() + .copied() + .collect() + } -bitflags! { - struct Check: u32 { - const FORMAT = 0b00000001; - const CLIPPY = 0b00000010; - const TEST = 0b00001000; - const DOC_TEST = 0b00010000; - const DOC_CHECK = 0b00100000; - const COMPILE_CHECK = 0b100000000; + /// Returns the argument that corresponds to this check. + fn argument(&self) -> &'static str { + match self { + Check::Format => "format", + Check::Clippy => "clippy", + Check::Test => "test", + Check::DocTest => "doctest", + Check::DocCheck => "doccheck", + Check::CompileCheck => "compilecheck", + } + } + + /// Returns the [`Check`] that corresponds to the given argument. + fn from_argument(argument: &str) -> Option { + match argument { + "format" => Some(Check::Format), + "clippy" => Some(Check::Clippy), + "test" => Some(Check::Test), + "doctest" => Some(Check::DocTest), + "doccheck" => Some(Check::DocCheck), + "compilecheck" => Some(Check::CompileCheck), + _ => None, + } } } -// This can be configured as needed +/// Controls how clippy is run. const CLIPPY_FLAGS: [&str; 3] = [ "-Aclippy::type_complexity", "-Wclippy::doc_markdown", @@ -23,32 +70,19 @@ const CLIPPY_FLAGS: [&str; 3] = [ ]; fn main() { - // When run locally, results may differ from actual CI runs triggered by - // .github/workflows/ci.yml - // - Official CI runs latest stable - // - Local runs use whatever the default Rust is locally - - let arguments = [ - ("lints", Check::FORMAT | Check::CLIPPY), - ("test", Check::TEST), - ("doc", Check::DOC_TEST | Check::DOC_CHECK), - ("compile", Check::COMPILE_CHECK), - ("format", Check::FORMAT), - ("clippy", Check::CLIPPY), - ("doc-check", Check::DOC_CHECK), - ("doc-test", Check::DOC_TEST), - ]; - let what_to_run = if let Some(arg) = std::env::args().nth(1).as_deref() { - if let Some((_, check)) = arguments.iter().find(|(str, _)| *str == arg) { - *check + if let Some(check) = Check::from_argument(arg) { + let mut set = HashSet::default(); + set.insert(check); + set } else { println!( - "Invalid argument: {arg:?}.\nEnter one of: {}.", - arguments[1..] + "Invalid argument: {arg}.\nEnter one of: {}.", + Check::all() .iter() - .map(|(s, _)| s) - .fold(arguments[0].0.to_owned(), |c, v| c + ", " + v) + .map(|check| check.argument()) + .collect::>() + .join(", "), ); return; } @@ -58,14 +92,14 @@ fn main() { let sh = Shell::new().unwrap(); - if what_to_run.contains(Check::FORMAT) { + if what_to_run.contains(&Check::Format) { // See if any code needs to be formatted cmd!(sh, "cargo fmt --all -- --check") .run() .expect("Please run 'cargo fmt --all' to format your code."); } - if what_to_run.contains(Check::CLIPPY) { + if what_to_run.contains(&Check::Clippy) { // See if clippy has any complaints. // --all-targets --all-features was removed because Emergence currently has no special // targets or features; please add them back as necessary @@ -74,21 +108,21 @@ fn main() { .expect("Please fix clippy errors in output above."); } - if what_to_run.contains(Check::TEST) { + if what_to_run.contains(&Check::Test) { // Run tests (except doc tests and without building examples) cmd!(sh, "cargo test --workspace --lib --bins --tests --benches") .run() .expect("Please fix failing tests in output above."); } - if what_to_run.contains(Check::DOC_TEST) { + if what_to_run.contains(&Check::DocTest) { // Run doc tests cmd!(sh, "cargo test --workspace --doc") .run() .expect("Please fix failing doc-tests in output above."); } - if what_to_run.contains(Check::DOC_CHECK) { + if what_to_run.contains(&Check::DocCheck) { // Check that building docs work and does not emit warnings std::env::set_var("RUSTDOCFLAGS", "-D warnings"); cmd!( @@ -99,9 +133,22 @@ fn main() { .expect("Please fix doc warnings in output above."); } - if what_to_run.contains(Check::COMPILE_CHECK) { + if what_to_run.contains(&Check::CompileCheck) { cmd!(sh, "cargo check --workspace") .run() .expect("Please fix compiler errors in above output."); } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn check_from_argument_reverses() { + for check in Check::all() { + assert_eq!(Check::from_argument(check.argument()), Some(check)); + } + assert_eq!(Check::from_argument("invalid"), None); + } +}