diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2023-04-16 19:19:09 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-16 19:19:09 +0000 |
| commit | 55083fb3ccee36c623c91b48ecc7d1f563ed80f8 (patch) | |
| tree | b2166e9a5f93646f7123e2eb323331bf9a4b2fa2 /xtask/src/argument_parsing.rs | |
| parent | 56bf829931cd3f8267ad435f6ff8f3ae200418b4 (diff) | |
| parent | b7e4498a7136041d89541bdc7725c8c023fa5c9c (diff) | |
Merge #736
736: More `xtasks` and add examples to `rtic` repo r=korken89 a=datdenkikniet
This was in #732 before, but decluttering that PR seemed sensible
Co-authored-by: datdenkikniet <jcdra1@gmail.com>
Diffstat (limited to 'xtask/src/argument_parsing.rs')
| -rw-r--r-- | xtask/src/argument_parsing.rs | 85 |
1 files changed, 73 insertions, 12 deletions
diff --git a/xtask/src/argument_parsing.rs b/xtask/src/argument_parsing.rs index 3ee9e34..05d0ae4 100644 --- a/xtask/src/argument_parsing.rs +++ b/xtask/src/argument_parsing.rs @@ -1,4 +1,4 @@ -use crate::{command::CargoCommand, Target, ARMV6M, ARMV7M, ARMV8MBASE, ARMV8MMAIN}; +use crate::{cargo_command::CargoCommand, Target, ARMV6M, ARMV7M, ARMV8MBASE, ARMV8MMAIN}; use clap::{Args, Parser, Subcommand}; use core::fmt; @@ -19,15 +19,17 @@ impl fmt::Display for Package { } impl Package { - pub fn name(&self) -> &str { - match self { + pub fn name(&self) -> String { + let name = match self { Package::Rtic => "rtic", Package::RticCommon => "rtic-common", Package::RticMacros => "rtic-macros", Package::RticMonotonics => "rtic-monotonics", Package::RticSync => "rtic-sync", Package::RticTime => "rtic-time", - } + }; + + name.to_string() } pub fn all() -> Vec<Self> { @@ -102,35 +104,41 @@ impl TestMetadata { ); let features = Some(backend.to_target().and_features(&features)); CargoCommand::Test { - package: Some(package), + package: Some(package.name()), features, test: Some("ui".to_owned()), + deny_warnings: true, } } Package::RticMacros => CargoCommand::Test { - package: Some(package), + package: Some(package.name()), features: Some(backend.to_rtic_macros_feature().to_owned()), test: None, + deny_warnings: true, }, Package::RticSync => CargoCommand::Test { - package: Some(package), + package: Some(package.name()), features: Some("testing".to_owned()), test: None, + deny_warnings: true, }, Package::RticCommon => CargoCommand::Test { - package: Some(package), + package: Some(package.name()), features: Some("testing".to_owned()), test: None, + deny_warnings: true, }, Package::RticMonotonics => CargoCommand::Test { - package: Some(package), + package: Some(package.name()), features: None, test: None, + deny_warnings: true, }, Package::RticTime => CargoCommand::Test { - package: Some(package), + package: Some(package.name()), features: Some("critical-section/std".into()), test: None, + deny_warnings: true, }, } } @@ -190,8 +198,12 @@ pub enum BuildOrCheck { #[derive(Parser, Clone)] pub struct Globals { - /// For which backend to build (defaults to thumbv7) - #[arg(value_enum, short, long, global = true)] + /// Error out on warnings + #[arg(short = 'D', long)] + pub deny_warnings: bool, + + /// For which backend to build. + #[arg(value_enum, short, default_value = "thumbv7", long, global = true)] pub backend: Option<Backends>, /// List of comma separated examples to include, all others are excluded @@ -300,6 +312,55 @@ pub enum Commands { /// Build books with mdbook Book(Arg), + + /// Check one or more usage examples. + /// + /// Usage examples are located in ./examples + UsageExampleCheck(UsageExamplesOpt), + + /// Build one or more usage examples. + /// + /// Usage examples are located in ./examples + #[clap(alias = "./examples")] + UsageExampleBuild(UsageExamplesOpt), +} + +#[derive(Args, Clone, Debug)] +pub struct UsageExamplesOpt { + /// The usage examples to build. All usage examples are selected if this argument is not provided. + /// + /// Example: `rp2040_local_i2c_init,stm32f3_blinky`. + examples: Option<String>, +} + +impl UsageExamplesOpt { + pub fn examples(&self) -> anyhow::Result<Vec<String>> { + let usage_examples: Vec<_> = std::fs::read_dir("./examples")? + .filter_map(Result::ok) + .filter(|p| p.metadata().ok().map(|p| p.is_dir()).unwrap_or(false)) + .filter_map(|p| p.file_name().to_str().map(ToString::to_string)) + .collect(); + + let selected_examples: Option<Vec<String>> = self + .examples + .clone() + .map(|s| s.split(",").map(ToString::to_string).collect()); + + if let Some(selected_examples) = selected_examples { + if let Some(unfound_example) = selected_examples + .iter() + .find(|e| !usage_examples.contains(e)) + { + Err(anyhow::anyhow!( + "Usage example {unfound_example} does not exist" + )) + } else { + Ok(selected_examples) + } + } else { + Ok(usage_examples) + } + } } #[derive(Args, Debug, Clone)] |
