diff --git a/xtask/src/command.rs b/xtask/src/command.rs index b1f885c141..6fce1c941b 100644 --- a/xtask/src/command.rs +++ b/xtask/src/command.rs @@ -66,6 +66,10 @@ pub enum CargoCommand<'a> { package: Vec, check_only: bool, }, + Doc { + cargoarg: &'a Option<&'a str>, + features: Option<&'a str>, + }, ExampleSize { cargoarg: &'a Option<&'a str>, example: &'a str, @@ -85,9 +89,9 @@ impl<'a> CargoCommand<'a> { CargoCommand::ExampleSize { .. } => "size", CargoCommand::Clippy { .. } => "clippy", CargoCommand::Format { .. } => "fmt", + CargoCommand::Doc { .. } => "doc", // TODO // CargoCommand::Test { .. } => "test", - // CargoCommand::Doc { .. } => "doc", } } @@ -208,6 +212,19 @@ impl<'a> CargoCommand<'a> { } args } + CargoCommand::Doc { cargoarg, features } => { + let mut args = vec!["+nightly"]; + if let Some(cargoarg) = cargoarg { + args.extend_from_slice(&[cargoarg]); + } + + args.extend_from_slice(&[self.name()]); + + if let Some(feature) = features { + args.extend_from_slice(&["--features", feature]); + } + args + } CargoCommand::Format { cargoarg, package, diff --git a/xtask/src/main.rs b/xtask/src/main.rs index b042b64046..62cfeafcb7 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -144,6 +144,9 @@ enum Commands { /// Run clippy Clippy(Package), + + /// Build docs + Doc, } #[derive(Args, Debug)] @@ -366,6 +369,10 @@ fn main() -> anyhow::Result<()> { info!("Running clippy on backend: {backend:?}"); cargo_clippy(&cargoarg, &args, backend)?; } + Commands::Doc => { + info!("Running cargo doc on backend: {backend:?}"); + cargo_doc(&cargoarg, backend)?; + } Commands::FormatCheck(args) => { info!("Running cargo fmt: {args:?}"); let check_only = true; @@ -501,6 +508,14 @@ fn cargo_format( Ok(()) } +fn cargo_doc(cargoarg: &Option<&str>, backend: Backends) -> anyhow::Result<()> { + let s = format!("{}", backend.to_rtic_feature()); + let features: Option<&str> = Some(&s); + + command_parser(&CargoCommand::Doc { cargoarg, features }, false)?; + Ok(()) +} + fn run_test( cargoarg: &Option<&str>, backend: Backends, @@ -701,6 +716,7 @@ fn command_parser(command: &CargoCommand, overwrite: bool) -> anyhow::Result<()> | CargoCommand::Build { .. } | CargoCommand::Check { .. } | CargoCommand::Clippy { .. } + | CargoCommand::Doc { .. } | CargoCommand::Format { .. } | CargoCommand::ExampleSize { .. } => { let cargo_result = run_command(command)?;