From 512bab17cc52a288dd2e41e39f7b3b0af95e03ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Wed, 1 Mar 2023 00:10:07 +0100 Subject: xtask: Split out arg parsing --- xtask/src/argument_parsing.rs | 253 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100644 xtask/src/argument_parsing.rs (limited to 'xtask/src/argument_parsing.rs') diff --git a/xtask/src/argument_parsing.rs b/xtask/src/argument_parsing.rs new file mode 100644 index 0000000..bd28492 --- /dev/null +++ b/xtask/src/argument_parsing.rs @@ -0,0 +1,253 @@ +use crate::{command::CargoCommand, ARMV6M, ARMV7M, ARMV8MBASE, ARMV8MMAIN, DEFAULT_FEATURES}; +use clap::{Args, Parser, Subcommand}; +use core::fmt; + +#[derive(clap::ValueEnum, Copy, Clone, Debug)] +pub enum Package { + Rtic, + RticArbiter, + RticChannel, + RticCommon, + RticMacros, + RticMonotonics, + RticTime, +} + +impl fmt::Display for Package { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.name()) + } +} + +impl Package { + pub fn name(&self) -> &str { + match self { + Package::Rtic => "rtic", + Package::RticArbiter => "rtic-arbiter", + Package::RticChannel => "rtic-channel", + Package::RticCommon => "rtic-common", + Package::RticMacros => "rtic-macros", + Package::RticMonotonics => "rtic-monotonics", + Package::RticTime => "rtic-time", + } + } +} + +pub struct TestMetadata {} + +impl TestMetadata { + pub fn match_package(package: Package, backend: Backends) -> CargoCommand<'static> { + match package { + Package::Rtic => { + let features = Some(format!( + "{},{}", + DEFAULT_FEATURES, + backend.to_rtic_feature(), + )); + CargoCommand::Test { + package: Some(package), + features, + test: Some("ui".to_owned()), + } + } + Package::RticMacros => CargoCommand::Test { + package: Some(package), + features: Some(backend.to_rtic_macros_feature().to_owned()), + test: None, + }, + Package::RticArbiter => CargoCommand::Test { + package: Some(package), + features: Some("testing".to_owned()), + test: None, + }, + Package::RticChannel => CargoCommand::Test { + package: Some(package), + features: Some("testing".to_owned()), + test: None, + }, + Package::RticCommon => CargoCommand::Test { + package: Some(package), + features: Some("testing".to_owned()), + test: None, + }, + Package::RticMonotonics => CargoCommand::Test { + package: Some(package), + features: None, + test: Some("tests".to_owned()), + }, + Package::RticTime => CargoCommand::Test { + package: Some(package), + features: None, + test: None, + }, + } + } +} + +#[derive(clap::ValueEnum, Copy, Clone, Default, Debug)] +pub enum Backends { + Thumbv6, + #[default] + Thumbv7, + Thumbv8Base, + Thumbv8Main, +} + +impl Backends { + pub fn to_target(&self) -> &str { + match self { + Backends::Thumbv6 => ARMV6M, + Backends::Thumbv7 => ARMV7M, + Backends::Thumbv8Base => ARMV8MBASE, + Backends::Thumbv8Main => ARMV8MMAIN, + } + } + + pub fn to_rtic_feature(&self) -> &str { + match self { + Backends::Thumbv6 => "thumbv6-backend", + Backends::Thumbv7 => "thumbv7-backend", + Backends::Thumbv8Base => "thumbv8base-backend", + Backends::Thumbv8Main => "thumbv8main-backend", + } + } + pub fn to_rtic_macros_feature(&self) -> &str { + match self { + Backends::Thumbv6 => "cortex-m-source-masking", + Backends::Thumbv7 => "cortex-m-basepri", + Backends::Thumbv8Base => "cortex-m-source-masking", + Backends::Thumbv8Main => "cortex-m-basepri", + } + } +} + +#[derive(Copy, Clone, Default, Debug)] +pub enum BuildOrCheck { + #[default] + Check, + Build, +} + +#[derive(Parser)] +#[command(author, version, about, long_about = None)] +/// RTIC xtask powered testing toolbox +pub struct Cli { + /// For which backend to build (defaults to thumbv7) + #[arg(value_enum, short, long)] + pub backend: Option, + + /// List of comma separated examples to include, all others are excluded + /// + /// If omitted all examples are included + /// + /// Example: `cargo xtask --example complex,spawn,init` + /// would include complex, spawn and init + #[arg(short, long, group = "example_group")] + pub example: Option, + + /// List of comma separated examples to exclude, all others are included + /// + /// If omitted all examples are included + /// + /// Example: `cargo xtask --excludeexample complex,spawn,init` + /// would exclude complex, spawn and init + #[arg(long, group = "example_group")] + pub exampleexclude: Option, + + /// Enable more verbose output, repeat up to `-vvv` for even more + #[arg(short, long, action = clap::ArgAction::Count)] + pub verbose: u8, + + /// Subcommand selecting operation + #[command(subcommand)] + pub command: Commands, +} + +#[derive(Debug, Subcommand)] +pub enum Commands { + /// Check formatting + FormatCheck(PackageOpt), + + /// Format code + Format(PackageOpt), + + /// Run clippy + Clippy(PackageOpt), + + /// Check all packages + Check(PackageOpt), + + /// Build all packages + Build(PackageOpt), + + /// 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 + /// arguments will be passed on + /// + /// Example: `cargo xtask size -- -A` + Size(Size), + + /// Run examples in QEMU and compare against expected output + /// + /// Example runtime output is matched against `rtic/ci/expected/` + /// + /// Requires that an ARM target is selected + Qemu(QemuAndRun), + + /// Run examples through embedded-ci and compare against expected output + /// + /// unimplemented!() For now TODO, equal to Qemu + /// + /// Example runtime output is matched against `rtic/ci/expected/` + /// + /// Requires that an ARM target is selected + Run(QemuAndRun), + + /// Build docs + Doc, + + /// Run tests + Test(PackageOpt), + + /// Build books with mdbook + Book, +} + +#[derive(Args, Debug)] +/// Restrict to package, or run on whole workspace +pub struct PackageOpt { + /// For which package/workspace member to operate + /// + /// If omitted, work on all + pub package: Option, +} + +#[derive(Args, Debug)] +pub struct QemuAndRun { + /// If expected output is missing or mismatching, recreate the file + /// + /// This overwrites only missing or mismatching + #[arg(long)] + pub overwrite_expected: bool, +} + +#[derive(Debug, Parser)] +pub struct Size { + /// Options to pass to `cargo size` + #[command(subcommand)] + pub sizearguments: Option, +} + +#[derive(Clone, Debug, PartialEq, Parser)] +pub enum Sizearguments { + /// All remaining flags and options + #[command(external_subcommand)] + Other(Vec), +} -- cgit v1.2.3 From 39a06368c8f1e6e77c1e838b0a8a39e548c344f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Thu, 2 Mar 2023 19:40:50 +0100 Subject: xtask: rtic-sync --- xtask/src/argument_parsing.rs | 13 +++---------- 1 file changed, 3 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 bd28492..aff464c 100644 --- a/xtask/src/argument_parsing.rs +++ b/xtask/src/argument_parsing.rs @@ -5,11 +5,10 @@ use core::fmt; #[derive(clap::ValueEnum, Copy, Clone, Debug)] pub enum Package { Rtic, - RticArbiter, - RticChannel, RticCommon, RticMacros, RticMonotonics, + RticSync, RticTime, } @@ -23,11 +22,10 @@ impl Package { pub fn name(&self) -> &str { match self { Package::Rtic => "rtic", - Package::RticArbiter => "rtic-arbiter", - Package::RticChannel => "rtic-channel", Package::RticCommon => "rtic-common", Package::RticMacros => "rtic-macros", Package::RticMonotonics => "rtic-monotonics", + Package::RticSync => "rtic-sync", Package::RticTime => "rtic-time", } } @@ -55,12 +53,7 @@ impl TestMetadata { features: Some(backend.to_rtic_macros_feature().to_owned()), test: None, }, - Package::RticArbiter => CargoCommand::Test { - package: Some(package), - features: Some("testing".to_owned()), - test: None, - }, - Package::RticChannel => CargoCommand::Test { + Package::RticSync => CargoCommand::Test { package: Some(package), features: Some("testing".to_owned()), test: None, -- cgit v1.2.3 From 3908cbf7e8f3a0e7da7dbe132afd387f227a8a3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Thu, 2 Mar 2023 22:02:19 +0100 Subject: xtask: Allow passing arguments to book and doc --- xtask/src/argument_parsing.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'xtask/src/argument_parsing.rs') diff --git a/xtask/src/argument_parsing.rs b/xtask/src/argument_parsing.rs index aff464c..1fc06c1 100644 --- a/xtask/src/argument_parsing.rs +++ b/xtask/src/argument_parsing.rs @@ -185,7 +185,7 @@ pub enum Commands { /// arguments will be passed on /// /// Example: `cargo xtask size -- -A` - Size(Size), + Size(Arg), /// Run examples in QEMU and compare against expected output /// @@ -204,13 +204,18 @@ pub enum Commands { Run(QemuAndRun), /// Build docs - Doc, + /// + /// To pass options to `cargo doc`, add `--` and then the following + /// arguments will be passed on + /// + /// Example: `cargo xtask doc -- --open` + Doc(Arg), /// Run tests Test(PackageOpt), /// Build books with mdbook - Book, + Book(Arg), } #[derive(Args, Debug)] @@ -232,14 +237,14 @@ pub struct QemuAndRun { } #[derive(Debug, Parser)] -pub struct Size { +pub struct Arg { /// Options to pass to `cargo size` #[command(subcommand)] - pub sizearguments: Option, + pub arguments: Option, } #[derive(Clone, Debug, PartialEq, Parser)] -pub enum Sizearguments { +pub enum ExtraArguments { /// All remaining flags and options #[command(external_subcommand)] Other(Vec), -- cgit v1.2.3 From 2e63f5bca30acdec81495e0dc59aa6f7ebff5976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Sat, 4 Mar 2023 02:11:50 +0100 Subject: ci: Add rtic-uitest feature Fixes the trybuild ui tests for rtic crate --- xtask/src/argument_parsing.rs | 3 ++- 1 file changed, 2 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 1fc06c1..aef5e3a 100644 --- a/xtask/src/argument_parsing.rs +++ b/xtask/src/argument_parsing.rs @@ -38,9 +38,10 @@ impl TestMetadata { match package { Package::Rtic => { let features = Some(format!( - "{},{}", + "{},{},{}", DEFAULT_FEATURES, backend.to_rtic_feature(), + "rtic-uitest" )); CargoCommand::Test { package: Some(package), -- cgit v1.2.3 From 3789798e33f613dbdc91576eb57bf7691ba0568a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Sat, 4 Mar 2023 20:52:29 +0100 Subject: xtask: clippy fixes --- xtask/src/argument_parsing.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'xtask/src/argument_parsing.rs') diff --git a/xtask/src/argument_parsing.rs b/xtask/src/argument_parsing.rs index aef5e3a..3e5afc3 100644 --- a/xtask/src/argument_parsing.rs +++ b/xtask/src/argument_parsing.rs @@ -88,6 +88,7 @@ pub enum Backends { } impl Backends { + #[allow(clippy::wrong_self_convention)] pub fn to_target(&self) -> &str { match self { Backends::Thumbv6 => ARMV6M, @@ -97,6 +98,7 @@ impl Backends { } } + #[allow(clippy::wrong_self_convention)] pub fn to_rtic_feature(&self) -> &str { match self { Backends::Thumbv6 => "thumbv6-backend", @@ -105,6 +107,7 @@ impl Backends { Backends::Thumbv8Main => "thumbv8main-backend", } } + #[allow(clippy::wrong_self_convention)] pub fn to_rtic_macros_feature(&self) -> &str { match self { Backends::Thumbv6 => "cortex-m-source-masking", -- cgit v1.2.3 From 62e687242ad1e92f9172f6cc897407156cf42e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Sat, 4 Mar 2023 21:03:46 +0100 Subject: ci: Add v6 uitest feature --- xtask/src/argument_parsing.rs | 15 ++++++++++----- 1 file changed, 10 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 3e5afc3..70bae73 100644 --- a/xtask/src/argument_parsing.rs +++ b/xtask/src/argument_parsing.rs @@ -41,7 +41,7 @@ impl TestMetadata { "{},{},{}", DEFAULT_FEATURES, backend.to_rtic_feature(), - "rtic-uitest" + backend.to_rtic_uitest_feature(), )); CargoCommand::Test { package: Some(package), @@ -110,10 +110,15 @@ impl Backends { #[allow(clippy::wrong_self_convention)] pub fn to_rtic_macros_feature(&self) -> &str { match self { - Backends::Thumbv6 => "cortex-m-source-masking", - Backends::Thumbv7 => "cortex-m-basepri", - Backends::Thumbv8Base => "cortex-m-source-masking", - Backends::Thumbv8Main => "cortex-m-basepri", + 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 { + match self { + Backends::Thumbv6 | Backends::Thumbv8Base => "rtic-uitestv6", + Backends::Thumbv7 | Backends::Thumbv8Main => "rtic-uitestv7", } } } -- cgit v1.2.3 From a5ede5408cff4834608134dd6a07e4978d9bbd08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Sat, 4 Mar 2023 21:32:37 +0100 Subject: xtask: rtic-monotonics: no tests argument --- xtask/src/argument_parsing.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'xtask/src/argument_parsing.rs') diff --git a/xtask/src/argument_parsing.rs b/xtask/src/argument_parsing.rs index 70bae73..8795213 100644 --- a/xtask/src/argument_parsing.rs +++ b/xtask/src/argument_parsing.rs @@ -67,7 +67,7 @@ impl TestMetadata { Package::RticMonotonics => CargoCommand::Test { package: Some(package), features: None, - test: Some("tests".to_owned()), + test: None, }, Package::RticTime => CargoCommand::Test { package: Some(package), -- cgit v1.2.3