mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-24 04:32:52 +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
|
/// arguments will be passed on
|
||||||
///
|
///
|
||||||
/// Example: `cargo xtask size -- -A`
|
/// Example: `cargo xtask size -- -A`
|
||||||
Size(Size),
|
Size(Arg),
|
||||||
|
|
||||||
/// Run examples in QEMU and compare against expected output
|
/// Run examples in QEMU and compare against expected output
|
||||||
///
|
///
|
||||||
|
@ -204,13 +204,18 @@ pub enum Commands {
|
||||||
Run(QemuAndRun),
|
Run(QemuAndRun),
|
||||||
|
|
||||||
/// Build docs
|
/// 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
|
/// Run tests
|
||||||
Test(PackageOpt),
|
Test(PackageOpt),
|
||||||
|
|
||||||
/// Build books with mdbook
|
/// Build books with mdbook
|
||||||
Book,
|
Book(Arg),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Args, Debug)]
|
#[derive(Args, Debug)]
|
||||||
|
@ -232,14 +237,14 @@ pub struct QemuAndRun {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
pub struct Size {
|
pub struct Arg {
|
||||||
/// Options to pass to `cargo size`
|
/// Options to pass to `cargo size`
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
pub sizearguments: Option<Sizearguments>,
|
pub arguments: Option<ExtraArguments>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Parser)]
|
#[derive(Clone, Debug, PartialEq, Parser)]
|
||||||
pub enum Sizearguments {
|
pub enum ExtraArguments {
|
||||||
/// All remaining flags and options
|
/// All remaining flags and options
|
||||||
#[command(external_subcommand)]
|
#[command(external_subcommand)]
|
||||||
Other(Vec<String>),
|
Other(Vec<String>),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
argument_parsing::{Backends, BuildOrCheck, Package, PackageOpt, Sizearguments, TestMetadata},
|
argument_parsing::{Backends, BuildOrCheck, ExtraArguments, Package, PackageOpt, TestMetadata},
|
||||||
command::{BuildMode, CargoCommand},
|
command::{BuildMode, CargoCommand},
|
||||||
command_parser, package_feature_extractor, DEFAULT_FEATURES,
|
command_parser, package_feature_extractor, DEFAULT_FEATURES,
|
||||||
};
|
};
|
||||||
|
@ -113,14 +113,25 @@ pub fn cargo_format(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Run cargo doc
|
/// 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!(
|
let features = Some(format!(
|
||||||
"{},{}",
|
"{},{}",
|
||||||
DEFAULT_FEATURES,
|
DEFAULT_FEATURES,
|
||||||
backend.to_rtic_feature()
|
backend.to_rtic_feature()
|
||||||
));
|
));
|
||||||
|
|
||||||
command_parser(&CargoCommand::Doc { cargoarg, features }, false)?;
|
command_parser(
|
||||||
|
&CargoCommand::Doc {
|
||||||
|
cargoarg,
|
||||||
|
features,
|
||||||
|
arguments: arguments.clone(),
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,10 +169,10 @@ pub fn cargo_test(package: &PackageOpt, backend: Backends) -> anyhow::Result<()>
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Use mdbook to build the book
|
/// 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(
|
command_parser(
|
||||||
&CargoCommand::Book {
|
&CargoCommand::Book {
|
||||||
mdbookarg: cargoarg,
|
arguments: arguments.clone(),
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
)?;
|
)?;
|
||||||
|
@ -218,7 +229,7 @@ pub fn build_and_check_size(
|
||||||
cargoarg: &Option<&str>,
|
cargoarg: &Option<&str>,
|
||||||
backend: Backends,
|
backend: Backends,
|
||||||
examples: &[String],
|
examples: &[String],
|
||||||
size_arguments: &Option<Sizearguments>,
|
arguments: &Option<ExtraArguments>,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
examples.into_par_iter().for_each(|example| {
|
examples.into_par_iter().for_each(|example| {
|
||||||
// Make sure the requested example(s) are built
|
// Make sure the requested example(s) are built
|
||||||
|
@ -247,7 +258,7 @@ pub fn build_and_check_size(
|
||||||
backend.to_rtic_feature()
|
backend.to_rtic_feature()
|
||||||
)),
|
)),
|
||||||
mode: BuildMode::Release,
|
mode: BuildMode::Release,
|
||||||
arguments: size_arguments.clone(),
|
arguments: arguments.clone(),
|
||||||
};
|
};
|
||||||
if let Err(err) = command_parser(&cmd, false) {
|
if let Err(err) = command_parser(&cmd, false) {
|
||||||
error!("{err}");
|
error!("{err}");
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{debug, Package, RunResult, Sizearguments, TestRunError};
|
use crate::{debug, ExtraArguments, Package, RunResult, TestRunError};
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use os_pipe::pipe;
|
use os_pipe::pipe;
|
||||||
use std::{fs::File, io::Read, process::Command};
|
use std::{fs::File, io::Read, process::Command};
|
||||||
|
@ -70,6 +70,7 @@ pub enum CargoCommand<'a> {
|
||||||
Doc {
|
Doc {
|
||||||
cargoarg: &'a Option<&'a str>,
|
cargoarg: &'a Option<&'a str>,
|
||||||
features: Option<String>,
|
features: Option<String>,
|
||||||
|
arguments: Option<ExtraArguments>,
|
||||||
},
|
},
|
||||||
Test {
|
Test {
|
||||||
package: Option<Package>,
|
package: Option<Package>,
|
||||||
|
@ -77,7 +78,7 @@ pub enum CargoCommand<'a> {
|
||||||
test: Option<String>,
|
test: Option<String>,
|
||||||
},
|
},
|
||||||
Book {
|
Book {
|
||||||
mdbookarg: &'a Option<&'a str>,
|
arguments: Option<ExtraArguments>,
|
||||||
},
|
},
|
||||||
ExampleSize {
|
ExampleSize {
|
||||||
cargoarg: &'a Option<&'a str>,
|
cargoarg: &'a Option<&'a str>,
|
||||||
|
@ -85,7 +86,7 @@ pub enum CargoCommand<'a> {
|
||||||
target: &'a str,
|
target: &'a str,
|
||||||
features: Option<String>,
|
features: Option<String>,
|
||||||
mode: BuildMode,
|
mode: BuildMode,
|
||||||
arguments: Option<Sizearguments>,
|
arguments: Option<ExtraArguments>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,7 +239,11 @@ impl<'a> CargoCommand<'a> {
|
||||||
}
|
}
|
||||||
args
|
args
|
||||||
}
|
}
|
||||||
CargoCommand::Doc { cargoarg, features } => {
|
CargoCommand::Doc {
|
||||||
|
cargoarg,
|
||||||
|
features,
|
||||||
|
arguments,
|
||||||
|
} => {
|
||||||
let mut args = vec!["+nightly"];
|
let mut args = vec!["+nightly"];
|
||||||
if let Some(cargoarg) = cargoarg {
|
if let Some(cargoarg) = cargoarg {
|
||||||
args.extend_from_slice(&[cargoarg]);
|
args.extend_from_slice(&[cargoarg]);
|
||||||
|
@ -249,6 +254,11 @@ impl<'a> CargoCommand<'a> {
|
||||||
if let Some(feature) = features {
|
if let Some(feature) = features {
|
||||||
args.extend_from_slice(&["--features", feature]);
|
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
|
args
|
||||||
}
|
}
|
||||||
CargoCommand::Test {
|
CargoCommand::Test {
|
||||||
|
@ -271,15 +281,17 @@ impl<'a> CargoCommand<'a> {
|
||||||
}
|
}
|
||||||
args
|
args
|
||||||
}
|
}
|
||||||
CargoCommand::Book { mdbookarg } => {
|
CargoCommand::Book { arguments } => {
|
||||||
let mut args = vec![];
|
let mut args = vec![];
|
||||||
|
|
||||||
args.extend_from_slice(&[self.name()]);
|
if let Some(ExtraArguments::Other(arguments)) = arguments {
|
||||||
|
for arg in arguments {
|
||||||
if let Some(arg) = mdbookarg {
|
args.extend_from_slice(&[arg.as_str()]);
|
||||||
args.extend_from_slice(&[arg]);
|
}
|
||||||
|
} else {
|
||||||
|
// If no argument given, run mdbook build
|
||||||
|
args.extend_from_slice(&[self.name()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
args.extend_from_slice(&["book/en"]);
|
args.extend_from_slice(&["book/en"]);
|
||||||
args
|
args
|
||||||
}
|
}
|
||||||
|
@ -364,7 +376,7 @@ impl<'a> CargoCommand<'a> {
|
||||||
if let Some(flag) = mode.to_flag() {
|
if let Some(flag) = mode.to_flag() {
|
||||||
args.push(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 "--"
|
// Arguments to cargo size must be passed after "--"
|
||||||
args.extend_from_slice(&["--"]);
|
args.extend_from_slice(&["--"]);
|
||||||
for arg in arguments {
|
for arg in arguments {
|
||||||
|
|
|
@ -4,7 +4,7 @@ mod cargo_commands;
|
||||||
mod command;
|
mod command;
|
||||||
|
|
||||||
use anyhow::bail;
|
use anyhow::bail;
|
||||||
use argument_parsing::{Package, Sizearguments};
|
use argument_parsing::{ExtraArguments, Package};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use diffy::{create_patch, PatchFormatter};
|
use diffy::{create_patch, PatchFormatter};
|
||||||
|
@ -230,12 +230,7 @@ fn main() -> anyhow::Result<()> {
|
||||||
Commands::Size(args) => {
|
Commands::Size(args) => {
|
||||||
// x86_64 target not valid
|
// x86_64 target not valid
|
||||||
info!("Measuring for backend: {backend:?}");
|
info!("Measuring for backend: {backend:?}");
|
||||||
build_and_check_size(
|
build_and_check_size(&cargologlevel, backend, &examples_to_run, &args.arguments)?;
|
||||||
&cargologlevel,
|
|
||||||
backend,
|
|
||||||
&examples_to_run,
|
|
||||||
&args.sizearguments,
|
|
||||||
)?;
|
|
||||||
}
|
}
|
||||||
Commands::Qemu(args) | Commands::Run(args) => {
|
Commands::Qemu(args) | Commands::Run(args) => {
|
||||||
// x86_64 target not valid
|
// x86_64 target not valid
|
||||||
|
@ -247,17 +242,17 @@ fn main() -> anyhow::Result<()> {
|
||||||
args.overwrite_expected,
|
args.overwrite_expected,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
Commands::Doc => {
|
Commands::Doc(args) => {
|
||||||
info!("Running cargo doc on backend: {backend:?}");
|
info!("Running cargo doc on backend: {backend:?}");
|
||||||
cargo_doc(&cargologlevel, backend)?;
|
cargo_doc(&cargologlevel, backend, &args.arguments)?;
|
||||||
}
|
}
|
||||||
Commands::Test(args) => {
|
Commands::Test(args) => {
|
||||||
info!("Running cargo test on backend: {backend:?}");
|
info!("Running cargo test on backend: {backend:?}");
|
||||||
cargo_test(&args, backend)?;
|
cargo_test(&args, backend)?;
|
||||||
}
|
}
|
||||||
Commands::Book => {
|
Commands::Book(args) => {
|
||||||
info!("Running mdbook build");
|
info!("Running mdbook");
|
||||||
cargo_book(&cargologlevel)?;
|
cargo_book(&args.arguments)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue