mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-27 14:04:56 +01:00
xtask: Allow passing arguments to book and doc
This commit is contained in:
parent
0a995e46c7
commit
3908cbf7e8
4 changed files with 59 additions and 36 deletions
|
@ -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<Sizearguments>,
|
||||
pub arguments: Option<ExtraArguments>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Parser)]
|
||||
pub enum Sizearguments {
|
||||
pub enum ExtraArguments {
|
||||
/// All remaining flags and options
|
||||
#[command(external_subcommand)]
|
||||
Other(Vec<String>),
|
||||
|
|
|
@ -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<ExtraArguments>,
|
||||
) -> 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<ExtraArguments>) -> 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<Sizearguments>,
|
||||
arguments: &Option<ExtraArguments>,
|
||||
) -> 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}");
|
||||
|
|
|
@ -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<String>,
|
||||
arguments: Option<ExtraArguments>,
|
||||
},
|
||||
Test {
|
||||
package: Option<Package>,
|
||||
|
@ -77,7 +78,7 @@ pub enum CargoCommand<'a> {
|
|||
test: Option<String>,
|
||||
},
|
||||
Book {
|
||||
mdbookarg: &'a Option<&'a str>,
|
||||
arguments: Option<ExtraArguments>,
|
||||
},
|
||||
ExampleSize {
|
||||
cargoarg: &'a Option<&'a str>,
|
||||
|
@ -85,7 +86,7 @@ pub enum CargoCommand<'a> {
|
|||
target: &'a str,
|
||||
features: Option<String>,
|
||||
mode: BuildMode,
|
||||
arguments: Option<Sizearguments>,
|
||||
arguments: Option<ExtraArguments>,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue