From 18522122f1238d7200a9c4bcc696e707385bcbb1 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Sat, 15 Apr 2023 00:26:16 +0200 Subject: xtask: forward globals through the chain and add stderr-inheritance flag --- xtask/src/argument_parsing.rs | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'xtask/src/argument_parsing.rs') diff --git a/xtask/src/argument_parsing.rs b/xtask/src/argument_parsing.rs index c0538e2..eda0a89 100644 --- a/xtask/src/argument_parsing.rs +++ b/xtask/src/argument_parsing.rs @@ -130,10 +130,8 @@ pub enum BuildOrCheck { Build, } -#[derive(Parser)] -#[command(author, version, about, long_about = None)] -/// RTIC xtask powered testing toolbox -pub struct Cli { +#[derive(Parser, Clone)] +pub struct Globals { /// For which backend to build (defaults to thumbv7) #[arg(value_enum, short, long)] pub backend: Option, @@ -160,12 +158,28 @@ pub struct Cli { #[arg(short, long, action = clap::ArgAction::Count)] pub verbose: u8, + /// Enable `stderr` inheritance on child processes. + /// + /// If this flag is enabled, the output of `stderr` produced by child + /// processes is printed directly to `stderr`. This will cause a lot of + /// clutter, but can make debugging long-running processes a lot easier. + #[arg(short, long)] + pub stderr_inherited: bool, +} + +#[derive(Parser)] +#[command(author, version, about, long_about = None)] +/// RTIC xtask powered testing toolbox +pub struct Cli { + #[clap(flatten)] + pub globals: Globals, + /// Subcommand selecting operation #[command(subcommand)] pub command: Commands, } -#[derive(Debug, Subcommand)] +#[derive(Debug, Clone, Subcommand)] pub enum Commands { /// Check formatting FormatCheck(PackageOpt), @@ -227,7 +241,7 @@ pub enum Commands { Book(Arg), } -#[derive(Args, Debug)] +#[derive(Args, Debug, Clone)] /// Restrict to package, or run on whole workspace pub struct PackageOpt { /// For which package/workspace member to operate @@ -236,7 +250,7 @@ pub struct PackageOpt { pub package: Option, } -#[derive(Args, Debug)] +#[derive(Args, Debug, Clone)] pub struct QemuAndRun { /// If expected output is missing or mismatching, recreate the file /// @@ -245,7 +259,7 @@ pub struct QemuAndRun { pub overwrite_expected: bool, } -#[derive(Debug, Parser)] +#[derive(Debug, Parser, Clone)] pub struct Arg { /// Options to pass to `cargo size` #[command(subcommand)] -- cgit v1.2.3 From 4adae80f2d575b631b0bc1aef4b7272e62acedb6 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Sat, 15 Apr 2023 00:50:46 +0200 Subject: xtask: don't add default arguments if building for a no_std target --- xtask/src/argument_parsing.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'xtask/src/argument_parsing.rs') diff --git a/xtask/src/argument_parsing.rs b/xtask/src/argument_parsing.rs index eda0a89..f643cbb 100644 --- a/xtask/src/argument_parsing.rs +++ b/xtask/src/argument_parsing.rs @@ -1,4 +1,4 @@ -use crate::{command::CargoCommand, ARMV6M, ARMV7M, ARMV8MBASE, ARMV8MMAIN, DEFAULT_FEATURES}; +use crate::{command::CargoCommand, Target, ARMV6M, ARMV7M, ARMV8MBASE, ARMV8MMAIN}; use clap::{Args, Parser, Subcommand}; use core::fmt; @@ -37,12 +37,12 @@ impl TestMetadata { pub fn match_package(package: Package, backend: Backends) -> CargoCommand<'static> { match package { Package::Rtic => { - let features = Some(format!( - "{},{},{}", - DEFAULT_FEATURES, + let features = format!( + "{},{}", backend.to_rtic_feature(), - backend.to_rtic_uitest_feature(), - )); + backend.to_rtic_uitest_feature() + ); + let features = Some(backend.to_target().and_features(&features)); CargoCommand::Test { package: Some(package), features, @@ -89,7 +89,7 @@ pub enum Backends { impl Backends { #[allow(clippy::wrong_self_convention)] - pub fn to_target(&self) -> &str { + pub fn to_target(&self) -> Target { match self { Backends::Thumbv6 => ARMV6M, Backends::Thumbv7 => ARMV7M, -- cgit v1.2.3 From 480aa210594a1ea808da93614aa49a508f9f35af Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Sat, 15 Apr 2023 10:03:52 +0200 Subject: Always run stuff for all packages if none is specified --- xtask/src/argument_parsing.rs | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'xtask/src/argument_parsing.rs') diff --git a/xtask/src/argument_parsing.rs b/xtask/src/argument_parsing.rs index f643cbb..7284fc5 100644 --- a/xtask/src/argument_parsing.rs +++ b/xtask/src/argument_parsing.rs @@ -29,6 +29,30 @@ impl Package { Package::RticTime => "rtic-time", } } + + pub fn all() -> Vec { + vec![ + Self::Rtic, + Self::RticCommon, + Self::RticMacros, + Self::RticMonotonics, + Self::RticSync, + Self::RticTime, + ] + } + + /// Get the features needed given the selected package + /// + /// Without package specified the features for RTIC are required + /// With only a single package which is not RTIC, no special + /// features are needed + pub fn extract_features(&self, target: Target, backend: Backends) -> Option { + match self { + Package::Rtic => Some(target.and_features(backend.to_rtic_feature())), + Package::RticMacros => Some(backend.to_rtic_macros_feature().to_owned()), + _ => None, + } + } } pub struct TestMetadata {} @@ -247,7 +271,16 @@ pub struct PackageOpt { /// For which package/workspace member to operate /// /// If omitted, work on all - pub package: Option, + package: Option, +} + +impl PackageOpt { + pub fn packages(&self) -> impl Iterator { + self.package + .map(|p| vec![p]) + .unwrap_or(Package::all()) + .into_iter() + } } #[derive(Args, Debug, Clone)] -- cgit v1.2.3 From 525703358bf52b74a01d9b0c04680d33621d60cd Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Sat, 15 Apr 2023 12:21:11 +0200 Subject: Rework command execution structure and make rayon optional (since it's not necessarily faster due to workspace wide lockfile contention) --- xtask/src/argument_parsing.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'xtask/src/argument_parsing.rs') diff --git a/xtask/src/argument_parsing.rs b/xtask/src/argument_parsing.rs index 7284fc5..e653f9a 100644 --- a/xtask/src/argument_parsing.rs +++ b/xtask/src/argument_parsing.rs @@ -275,12 +275,22 @@ pub struct PackageOpt { } impl PackageOpt { + #[cfg(not(feature = "rayon"))] pub fn packages(&self) -> impl Iterator { self.package .map(|p| vec![p]) .unwrap_or(Package::all()) .into_iter() } + + #[cfg(feature = "rayon")] + pub fn packages(&self) -> impl rayon::prelude::ParallelIterator { + use rayon::prelude::*; + self.package + .map(|p| vec![p]) + .unwrap_or(Package::all()) + .into_par_iter() + } } #[derive(Args, Debug, Clone)] -- cgit v1.2.3 From cefb622cf8ccfb8f50dff7ca2327d7dea5be7b7a Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Sat, 15 Apr 2023 13:17:59 +0200 Subject: Make all globals actually global --- xtask/src/argument_parsing.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'xtask/src/argument_parsing.rs') diff --git a/xtask/src/argument_parsing.rs b/xtask/src/argument_parsing.rs index e653f9a..77433ee 100644 --- a/xtask/src/argument_parsing.rs +++ b/xtask/src/argument_parsing.rs @@ -157,7 +157,7 @@ pub enum BuildOrCheck { #[derive(Parser, Clone)] pub struct Globals { /// For which backend to build (defaults to thumbv7) - #[arg(value_enum, short, long)] + #[arg(value_enum, short, long, global = true)] pub backend: Option, /// List of comma separated examples to include, all others are excluded @@ -166,7 +166,7 @@ pub struct Globals { /// /// Example: `cargo xtask --example complex,spawn,init` /// would include complex, spawn and init - #[arg(short, long, group = "example_group")] + #[arg(short, long, group = "example_group", global = true)] pub example: Option, /// List of comma separated examples to exclude, all others are included @@ -175,11 +175,11 @@ pub struct Globals { /// /// Example: `cargo xtask --excludeexample complex,spawn,init` /// would exclude complex, spawn and init - #[arg(long, group = "example_group")] + #[arg(long, group = "example_group", global = true)] pub exampleexclude: Option, /// Enable more verbose output, repeat up to `-vvv` for even more - #[arg(short, long, action = clap::ArgAction::Count)] + #[arg(short, long, action = clap::ArgAction::Count, global = true)] pub verbose: u8, /// Enable `stderr` inheritance on child processes. @@ -187,7 +187,7 @@ pub struct Globals { /// If this flag is enabled, the output of `stderr` produced by child /// processes is printed directly to `stderr`. This will cause a lot of /// clutter, but can make debugging long-running processes a lot easier. - #[arg(short, long)] + #[arg(short, long, global = true)] pub stderr_inherited: bool, } -- cgit v1.2.3 From df69b35c250eff5858d6e994a9866be35b987a6e Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Sat, 15 Apr 2023 13:18:18 +0200 Subject: More housekeeping and making it work that bit better --- xtask/src/argument_parsing.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'xtask/src/argument_parsing.rs') diff --git a/xtask/src/argument_parsing.rs b/xtask/src/argument_parsing.rs index 77433ee..3a89dfc 100644 --- a/xtask/src/argument_parsing.rs +++ b/xtask/src/argument_parsing.rs @@ -209,7 +209,8 @@ pub enum Commands { FormatCheck(PackageOpt), /// Format code - Format(PackageOpt), + #[clap(alias = "fmt")] + Format(FormatOpt), /// Run clippy Clippy(PackageOpt), @@ -265,6 +266,15 @@ pub enum Commands { Book(Arg), } +#[derive(Args, Debug, Clone)] +pub struct FormatOpt { + #[clap(flatten)] + pub package: PackageOpt, + /// Only check formatting, without applying fixes. + #[clap(short, long, alias = "check-only")] + pub check: bool, +} + #[derive(Args, Debug, Clone)] /// Restrict to package, or run on whole workspace pub struct PackageOpt { @@ -315,3 +325,13 @@ pub enum ExtraArguments { #[command(external_subcommand)] Other(Vec), } + +impl core::fmt::Display for ExtraArguments { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + ExtraArguments::Other(args) => { + write!(f, "{}", args.join(" ")) + } + } + } +} -- cgit v1.2.3 From 461023e3b836db394dce0e034a1d329b1f5c8f48 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Sat, 15 Apr 2023 13:45:58 +0200 Subject: More emojis and correct place for things --- xtask/src/argument_parsing.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'xtask/src/argument_parsing.rs') diff --git a/xtask/src/argument_parsing.rs b/xtask/src/argument_parsing.rs index 3a89dfc..34e0064 100644 --- a/xtask/src/argument_parsing.rs +++ b/xtask/src/argument_parsing.rs @@ -113,7 +113,7 @@ pub enum Backends { impl Backends { #[allow(clippy::wrong_self_convention)] - pub fn to_target(&self) -> Target { + pub fn to_target(&self) -> Target<'static> { match self { Backends::Thumbv6 => ARMV6M, Backends::Thumbv7 => ARMV7M, @@ -123,7 +123,7 @@ impl Backends { } #[allow(clippy::wrong_self_convention)] - pub fn to_rtic_feature(&self) -> &str { + pub fn to_rtic_feature(&self) -> &'static str { match self { Backends::Thumbv6 => "thumbv6-backend", Backends::Thumbv7 => "thumbv7-backend", @@ -132,14 +132,14 @@ impl Backends { } } #[allow(clippy::wrong_self_convention)] - pub fn to_rtic_macros_feature(&self) -> &str { + pub fn to_rtic_macros_feature(&self) -> &'static str { match self { Backends::Thumbv6 | Backends::Thumbv8Base => "cortex-m-source-masking", Backends::Thumbv7 | Backends::Thumbv8Main => "cortex-m-basepri", } } #[allow(clippy::wrong_self_convention)] - pub fn to_rtic_uitest_feature(&self) -> &str { + pub fn to_rtic_uitest_feature(&self) -> &'static str { match self { Backends::Thumbv6 | Backends::Thumbv8Base => "rtic-uitestv6", Backends::Thumbv7 | Backends::Thumbv8Main => "rtic-uitestv7", @@ -205,9 +205,6 @@ pub struct Cli { #[derive(Debug, Clone, Subcommand)] pub enum Commands { - /// Check formatting - FormatCheck(PackageOpt), - /// Format code #[clap(alias = "fmt")] Format(FormatOpt), @@ -270,9 +267,9 @@ pub enum Commands { pub struct FormatOpt { #[clap(flatten)] pub package: PackageOpt, - /// Only check formatting, without applying fixes. - #[clap(short, long, alias = "check-only")] - pub check: bool, + /// Apply formatting fixes immediately. + #[clap(short, long)] + pub apply: bool, } #[derive(Args, Debug, Clone)] -- cgit v1.2.3 From feb00a9755ae8f96c8b761f288a6dad2eb41c5b1 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Sat, 15 Apr 2023 14:28:24 +0200 Subject: Add support for "feature mixer" --- xtask/src/argument_parsing.rs | 47 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) (limited to 'xtask/src/argument_parsing.rs') diff --git a/xtask/src/argument_parsing.rs b/xtask/src/argument_parsing.rs index 34e0064..7028017 100644 --- a/xtask/src/argument_parsing.rs +++ b/xtask/src/argument_parsing.rs @@ -46,11 +46,45 @@ impl Package { /// Without package specified the features for RTIC are required /// With only a single package which is not RTIC, no special /// features are needed - pub fn extract_features(&self, target: Target, backend: Backends) -> Option { + pub fn features( + &self, + target: Target, + backend: Backends, + partial: bool, + ) -> Vec> { match self { - Package::Rtic => Some(target.and_features(backend.to_rtic_feature())), - Package::RticMacros => Some(backend.to_rtic_macros_feature().to_owned()), - _ => None, + Package::Rtic => vec![Some(target.and_features(backend.to_rtic_feature()))], + Package::RticMacros => { + vec![Some(backend.to_rtic_macros_feature().to_string())] + } + Package::RticMonotonics => { + let features = if partial { + &["cortex-m-systick", "rp2040", "nrf52840"][..] + } else { + &[ + "cortex-m-systick", + "cortex-m-systick,systick-100hz", + "cortex-m-systick,systick-10khz", + "rp2040", + "nrf52810", + "nrf52811", + "nrf52832", + "nrf52833", + "nrf52840", + "nrf5340-app", + "nrf5340-net", + "nrf9160", + ][..] + }; + + features + .into_iter() + .map(ToString::to_string) + .map(Some) + .chain(std::iter::once(None)) + .collect() + } + _ => vec![None], } } } @@ -189,6 +223,11 @@ pub struct Globals { /// clutter, but can make debugging long-running processes a lot easier. #[arg(short, long, global = true)] pub stderr_inherited: bool, + + /// Don't build/check/test all feature combinations that are available, only + /// a necessary subset. + #[arg(long, global = true)] + pub partial: bool, } #[derive(Parser)] -- cgit v1.2.3 From c6f4b834c184275298fabaae7b5bd70efe54b29d Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Sat, 15 Apr 2023 14:43:40 +0200 Subject: Fix fmt --- xtask/src/argument_parsing.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'xtask/src/argument_parsing.rs') diff --git a/xtask/src/argument_parsing.rs b/xtask/src/argument_parsing.rs index 7028017..3ee9e34 100644 --- a/xtask/src/argument_parsing.rs +++ b/xtask/src/argument_parsing.rs @@ -306,9 +306,9 @@ pub enum Commands { pub struct FormatOpt { #[clap(flatten)] pub package: PackageOpt, - /// Apply formatting fixes immediately. + /// Check-only, do not apply formatting fixes. #[clap(short, long)] - pub apply: bool, + pub check: bool, } #[derive(Args, Debug, Clone)] -- cgit v1.2.3