diff --git a/xtask/src/argument_parsing.rs b/xtask/src/argument_parsing.rs index aff464c941..1fc06c1f8b 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), diff --git a/xtask/src/cargo_commands.rs b/xtask/src/cargo_commands.rs index 31250d458c..f262c9fa11 100644 --- a/xtask/src/cargo_commands.rs +++ b/xtask/src/cargo_commands.rs @@ -1,5 +1,5 @@ use crate::{ - argument_parsing::{Backends, BuildOrCheck, Package, PackageOpt, Sizearguments, TestMetadata}, + argument_parsing::{Backends, BuildOrCheck, ExtraArguments, Package, PackageOpt, TestMetadata}, command::{BuildMode, CargoCommand}, command_parser, package_feature_extractor, DEFAULT_FEATURES, }; @@ -113,14 +113,25 @@ pub fn cargo_format( } /// Run cargo doc -pub fn cargo_doc(cargoarg: &Option<&str>, backend: Backends) -> anyhow::Result<()> { +pub fn cargo_doc( + cargoarg: &Option<&str>, + backend: Backends, + arguments: &Option, +) -> anyhow::Result<()> { let features = Some(format!( "{},{}", DEFAULT_FEATURES, backend.to_rtic_feature() )); - command_parser(&CargoCommand::Doc { cargoarg, features }, false)?; + command_parser( + &CargoCommand::Doc { + cargoarg, + features, + arguments: arguments.clone(), + }, + false, + )?; Ok(()) } @@ -158,10 +169,10 @@ pub fn cargo_test(package: &PackageOpt, backend: Backends) -> anyhow::Result<()> } /// Use mdbook to build the book -pub fn cargo_book(cargoarg: &Option<&str>) -> anyhow::Result<()> { +pub fn cargo_book(arguments: &Option) -> anyhow::Result<()> { command_parser( &CargoCommand::Book { - mdbookarg: cargoarg, + arguments: arguments.clone(), }, false, )?; @@ -218,7 +229,7 @@ pub fn build_and_check_size( cargoarg: &Option<&str>, backend: Backends, examples: &[String], - size_arguments: &Option, + arguments: &Option, ) -> anyhow::Result<()> { examples.into_par_iter().for_each(|example| { // Make sure the requested example(s) are built @@ -247,7 +258,7 @@ pub fn build_and_check_size( backend.to_rtic_feature() )), mode: BuildMode::Release, - arguments: size_arguments.clone(), + arguments: arguments.clone(), }; if let Err(err) = command_parser(&cmd, false) { error!("{err}"); diff --git a/xtask/src/command.rs b/xtask/src/command.rs index b6602eeba5..6dd661ea73 100644 --- a/xtask/src/command.rs +++ b/xtask/src/command.rs @@ -1,4 +1,4 @@ -use crate::{debug, Package, RunResult, Sizearguments, TestRunError}; +use crate::{debug, ExtraArguments, Package, RunResult, TestRunError}; use core::fmt; use os_pipe::pipe; use std::{fs::File, io::Read, process::Command}; @@ -70,6 +70,7 @@ pub enum CargoCommand<'a> { Doc { cargoarg: &'a Option<&'a str>, features: Option, + arguments: Option, }, Test { package: Option, @@ -77,7 +78,7 @@ pub enum CargoCommand<'a> { test: Option, }, Book { - mdbookarg: &'a Option<&'a str>, + arguments: Option, }, ExampleSize { cargoarg: &'a Option<&'a str>, @@ -85,7 +86,7 @@ pub enum CargoCommand<'a> { target: &'a str, features: Option, mode: BuildMode, - arguments: Option, + arguments: Option, }, } @@ -238,7 +239,11 @@ impl<'a> CargoCommand<'a> { } args } - CargoCommand::Doc { cargoarg, features } => { + CargoCommand::Doc { + cargoarg, + features, + arguments, + } => { let mut args = vec!["+nightly"]; if let Some(cargoarg) = cargoarg { args.extend_from_slice(&[cargoarg]); @@ -249,6 +254,11 @@ impl<'a> CargoCommand<'a> { if let Some(feature) = features { args.extend_from_slice(&["--features", feature]); } + if let Some(ExtraArguments::Other(arguments)) = arguments { + for arg in arguments { + args.extend_from_slice(&[arg.as_str()]); + } + } args } CargoCommand::Test { @@ -271,15 +281,17 @@ impl<'a> CargoCommand<'a> { } args } - CargoCommand::Book { mdbookarg } => { + CargoCommand::Book { arguments } => { let mut args = vec![]; - args.extend_from_slice(&[self.name()]); - - if let Some(arg) = mdbookarg { - args.extend_from_slice(&[arg]); + if let Some(ExtraArguments::Other(arguments)) = arguments { + for arg in arguments { + args.extend_from_slice(&[arg.as_str()]); + } + } else { + // If no argument given, run mdbook build + args.extend_from_slice(&[self.name()]); } - args.extend_from_slice(&["book/en"]); args } @@ -364,7 +376,7 @@ impl<'a> CargoCommand<'a> { if let Some(flag) = mode.to_flag() { args.push(flag); } - if let Some(Sizearguments::Other(arguments)) = arguments { + if let Some(ExtraArguments::Other(arguments)) = arguments { // Arguments to cargo size must be passed after "--" args.extend_from_slice(&["--"]); for arg in arguments { diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 6bf93176df..aed74eb55e 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -4,7 +4,7 @@ mod cargo_commands; mod command; use anyhow::bail; -use argument_parsing::{Package, Sizearguments}; +use argument_parsing::{ExtraArguments, Package}; use clap::Parser; use core::fmt; use diffy::{create_patch, PatchFormatter}; @@ -230,12 +230,7 @@ fn main() -> anyhow::Result<()> { Commands::Size(args) => { // x86_64 target not valid info!("Measuring for backend: {backend:?}"); - build_and_check_size( - &cargologlevel, - backend, - &examples_to_run, - &args.sizearguments, - )?; + build_and_check_size(&cargologlevel, backend, &examples_to_run, &args.arguments)?; } Commands::Qemu(args) | Commands::Run(args) => { // x86_64 target not valid @@ -247,17 +242,17 @@ fn main() -> anyhow::Result<()> { args.overwrite_expected, )?; } - Commands::Doc => { + Commands::Doc(args) => { info!("Running cargo doc on backend: {backend:?}"); - cargo_doc(&cargologlevel, backend)?; + cargo_doc(&cargologlevel, backend, &args.arguments)?; } Commands::Test(args) => { info!("Running cargo test on backend: {backend:?}"); cargo_test(&args, backend)?; } - Commands::Book => { - info!("Running mdbook build"); - cargo_book(&cargologlevel)?; + Commands::Book(args) => { + info!("Running mdbook"); + cargo_book(&args.arguments)?; } }