xtask: Make target flag optional, default to all targets

This commit is contained in:
Henrik Tjäder 2023-02-04 16:55:29 +01:00
parent 0f7e0e9736
commit 81ba62787c

View file

@ -32,10 +32,10 @@ struct Options {
/// ///
/// * thumbv7m-none-eabi /// * thumbv7m-none-eabi
#[structopt(short, long)] #[structopt(short, long)]
target: String, target: Option<String>,
/// Example to run, by default all examples are run /// Example to run, by default all examples are run
/// ///
/// Example: `cargo xtask --target <..> --example complex` /// Example: `cargo xtask --example complex`
#[structopt(short, long)] #[structopt(short, long)]
example: Option<String>, example: Option<String>,
/// Enables also running `cargo size` on the selected examples /// Enables also running `cargo size` on the selected examples
@ -43,7 +43,7 @@ struct Options {
/// To pass options to `cargo size`, add `--` and then the following /// To pass options to `cargo size`, add `--` and then the following
/// arguments will be passed on /// arguments will be passed on
/// ///
/// Example: `cargo xtask --target <..> -s -- -A` /// Example: `cargo xtask -s -- -A`
#[structopt(short, long)] #[structopt(short, long)]
size: bool, size: bool,
/// Options to pass to `cargo size` /// Options to pass to `cargo size`
@ -147,20 +147,25 @@ fn main() -> anyhow::Result<()> {
} }
init_build_dir()?; init_build_dir()?;
if target == "all" { match target {
None => {
for t in targets { for t in targets {
println!("Testing all targets: {targets:?}");
run_test(t, &examples, check_size, size_arguments)?; run_test(t, &examples, check_size, size_arguments)?;
} }
} else if targets.contains(&target.as_str()) { }
Some(target) => {
if targets.contains(&target.as_str()) {
run_test(target, &examples, check_size, size_arguments)?; run_test(target, &examples, check_size, size_arguments)?;
} else { } else {
eprintln!( eprintln!(
"The target you specified is not available. Available targets are:\ "The target you specified is not available. Available targets are:\
\n{targets:?}\n\ \n{targets:?}\n",
as well as `all` (testing on all of the above)",
); );
process::exit(1); process::exit(1);
} }
}
}
Ok(()) Ok(())
} }