xtask: Add docs building

This commit is contained in:
Henrik Tjäder 2023-02-24 22:56:36 +01:00
parent 2f8c7d3083
commit a73a8d63cf
2 changed files with 34 additions and 1 deletions

View file

@ -66,6 +66,10 @@ pub enum CargoCommand<'a> {
package: Vec<String>, package: Vec<String>,
check_only: bool, check_only: bool,
}, },
Doc {
cargoarg: &'a Option<&'a str>,
features: Option<&'a str>,
},
ExampleSize { ExampleSize {
cargoarg: &'a Option<&'a str>, cargoarg: &'a Option<&'a str>,
example: &'a str, example: &'a str,
@ -85,9 +89,9 @@ impl<'a> CargoCommand<'a> {
CargoCommand::ExampleSize { .. } => "size", CargoCommand::ExampleSize { .. } => "size",
CargoCommand::Clippy { .. } => "clippy", CargoCommand::Clippy { .. } => "clippy",
CargoCommand::Format { .. } => "fmt", CargoCommand::Format { .. } => "fmt",
CargoCommand::Doc { .. } => "doc",
// TODO // TODO
// CargoCommand::Test { .. } => "test", // CargoCommand::Test { .. } => "test",
// CargoCommand::Doc { .. } => "doc",
} }
} }
@ -208,6 +212,19 @@ impl<'a> CargoCommand<'a> {
} }
args 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 { CargoCommand::Format {
cargoarg, cargoarg,
package, package,

View file

@ -144,6 +144,9 @@ enum Commands {
/// Run clippy /// Run clippy
Clippy(Package), Clippy(Package),
/// Build docs
Doc,
} }
#[derive(Args, Debug)] #[derive(Args, Debug)]
@ -366,6 +369,10 @@ fn main() -> anyhow::Result<()> {
info!("Running clippy on backend: {backend:?}"); info!("Running clippy on backend: {backend:?}");
cargo_clippy(&cargoarg, &args, backend)?; cargo_clippy(&cargoarg, &args, backend)?;
} }
Commands::Doc => {
info!("Running cargo doc on backend: {backend:?}");
cargo_doc(&cargoarg, backend)?;
}
Commands::FormatCheck(args) => { Commands::FormatCheck(args) => {
info!("Running cargo fmt: {args:?}"); info!("Running cargo fmt: {args:?}");
let check_only = true; let check_only = true;
@ -501,6 +508,14 @@ fn cargo_format(
Ok(()) 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( fn run_test(
cargoarg: &Option<&str>, cargoarg: &Option<&str>,
backend: Backends, backend: Backends,
@ -701,6 +716,7 @@ fn command_parser(command: &CargoCommand, overwrite: bool) -> anyhow::Result<()>
| CargoCommand::Build { .. } | CargoCommand::Build { .. }
| CargoCommand::Check { .. } | CargoCommand::Check { .. }
| CargoCommand::Clippy { .. } | CargoCommand::Clippy { .. }
| CargoCommand::Doc { .. }
| CargoCommand::Format { .. } | CargoCommand::Format { .. }
| CargoCommand::ExampleSize { .. } => { | CargoCommand::ExampleSize { .. } => {
let cargo_result = run_command(command)?; let cargo_result = run_command(command)?;