From ff49889890c14599f7581d5bea58bcd6c2ed01fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Fri, 24 Feb 2023 23:14:11 +0100 Subject: [PATCH] xtask: Reorder commands --- xtask/src/command.rs | 5 ++ xtask/src/main.rs | 106 ++++++++++++++++++++++--------------------- 2 files changed, 59 insertions(+), 52 deletions(-) diff --git a/xtask/src/command.rs b/xtask/src/command.rs index 6fce1c941b..4cf387fa81 100644 --- a/xtask/src/command.rs +++ b/xtask/src/command.rs @@ -54,6 +54,7 @@ pub enum CargoCommand<'a> { package: Vec, target: &'a str, features: Option<&'a str>, + mode: BuildMode, }, Clippy { cargoarg: &'a Option<&'a str>, @@ -172,6 +173,7 @@ impl<'a> CargoCommand<'a> { package, target, features, + mode, } => { let mut args = vec!["+nightly"]; if let Some(cargoarg) = cargoarg { @@ -187,6 +189,9 @@ impl<'a> CargoCommand<'a> { if let Some(feature) = features { args.extend_from_slice(&["--features", feature]); } + if let Some(flag) = mode.to_flag() { + args.push(flag); + } args } CargoCommand::Clippy { diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 62cfeafcb7..23f4242734 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -67,7 +67,7 @@ impl Backends { #[command(author, version, about, long_about = None)] /// RTIC xtask powered testing toolbox struct Cli { - /// For which backend to build + /// For which backend to build (defaults to thumbv7) #[arg(value_enum, short, long)] backend: Option, @@ -100,6 +100,27 @@ struct Cli { #[derive(Debug, Subcommand)] enum Commands { + /// Check formatting + FormatCheck(Package), + + /// Format code + Format(Package), + + /// Run clippy + Clippy(Package), + + /// Check all packages + Check(Package), + + /// Build all packages + Build(Package), + + /// Check all examples + ExampleCheck, + + /// Build all examples + ExampleBuild, + /// Run `cargo size` on selected or all examples /// /// To pass options to `cargo size`, add `--` and then the following @@ -124,27 +145,6 @@ enum Commands { /// Requires that an ARM target is selected Run(QemuAndRun), - /// Build all examples - ExampleBuild, - - /// Check all packages - ExampleCheck, - - /// Build all examples - Build(Package), - - /// Check all packages - Check(Package), - - /// Check formatting - FormatCheck(Package), - - /// Format code - Format(Package), - - /// Run clippy - Clippy(Package), - /// Build docs Doc, } @@ -329,6 +329,36 @@ fn main() -> anyhow::Result<()> { }; match cli.command { + Commands::FormatCheck(args) => { + info!("Running cargo fmt: {args:?}"); + let check_only = true; + cargo_format(&cargoarg, &args, check_only)?; + } + Commands::Format(args) => { + info!("Running cargo fmt --check: {args:?}"); + let check_only = false; + cargo_format(&cargoarg, &args, check_only)?; + } + Commands::Clippy(args) => { + info!("Running clippy on backend: {backend:?}"); + cargo_clippy(&cargoarg, &args, backend)?; + } + Commands::Check(args) => { + info!("Checking on backend: {backend:?}"); + cargo_check(&cargoarg, &args, backend)?; + } + Commands::Build(args) => { + info!("Building for backend: {backend:?}"); + cargo_build(&cargoarg, &args, backend)?; + } + Commands::ExampleCheck => { + info!("Checking on backend: {backend:?}"); + example_check(&cargoarg, backend, &examples_to_run)?; + } + Commands::ExampleBuild => { + info!("Building for backend: {backend:?}"); + example_build(&cargoarg, backend, &examples_to_run)?; + } Commands::Size(arguments) => { // x86_64 target not valid info!("Measuring for backend: {backend:?}"); @@ -349,40 +379,10 @@ fn main() -> anyhow::Result<()> { args.overwrite_expected, )?; } - Commands::ExampleBuild => { - info!("Building for backend: {backend:?}"); - example_build(&cargoarg, backend, &examples_to_run)?; - } - Commands::ExampleCheck => { - info!("Checking on backend: {backend:?}"); - example_check(&cargoarg, backend, &examples_to_run)?; - } - Commands::Build(args) => { - info!("Building for backend: {backend:?}"); - cargo_build(&cargoarg, &args, backend)?; - } - Commands::Check(args) => { - info!("Checking on backend: {backend:?}"); - cargo_check(&cargoarg, &args, backend)?; - } - Commands::Clippy(args) => { - info!("Running clippy on backend: {backend:?}"); - cargo_clippy(&cargoarg, &args, backend)?; - } Commands::Doc => { info!("Running cargo doc on backend: {backend:?}"); cargo_doc(&cargoarg, backend)?; } - Commands::FormatCheck(args) => { - info!("Running cargo fmt: {args:?}"); - let check_only = true; - cargo_format(&cargoarg, &args, check_only)?; - } - Commands::Format(args) => { - info!("Running cargo fmt --check: {args:?}"); - let check_only = false; - cargo_format(&cargoarg, &args, check_only)?; - } } Ok(()) @@ -441,6 +441,7 @@ fn cargo_check( package: package_filter(package), target: backend.to_target(), features, + mode: BuildMode::Release, }, false, )?; @@ -451,6 +452,7 @@ fn cargo_check( package: package_filter(package), target: backend.to_target(), features: None, + mode: BuildMode::Release, }, false, )?;