xtask: Cleanup check and build

This commit is contained in:
Henrik Tjäder 2023-02-25 00:11:12 +01:00
parent 91be97d33f
commit 8b3aa7f346

View file

@ -63,6 +63,13 @@ impl Backends {
} }
} }
#[derive(Copy, Clone, Default, Debug)]
enum BuildOrCheck {
#[default]
Check,
Build,
}
#[derive(Parser)] #[derive(Parser)]
#[command(author, version, about, long_about = None)] #[command(author, version, about, long_about = None)]
/// RTIC xtask powered testing toolbox /// RTIC xtask powered testing toolbox
@ -345,19 +352,29 @@ fn main() -> anyhow::Result<()> {
} }
Commands::Check(args) => { Commands::Check(args) => {
info!("Checking on backend: {backend:?}"); info!("Checking on backend: {backend:?}");
cargo(&cli.command, &cargologlevel, &args, backend)?; cargo(BuildOrCheck::Check, &cargologlevel, &args, backend)?;
} }
Commands::Build(args) => { Commands::Build(args) => {
info!("Building for backend: {backend:?}"); info!("Building for backend: {backend:?}");
cargo_build(&cargologlevel, &args, backend)?; cargo(BuildOrCheck::Build, &cargologlevel, &args, backend)?;
} }
Commands::ExampleCheck => { Commands::ExampleCheck => {
info!("Checking on backend: {backend:?}"); info!("Checking on backend: {backend:?}");
example_check(&cargologlevel, backend, &examples_to_run)?; cargo_example(
BuildOrCheck::Check,
&cargologlevel,
backend,
&examples_to_run,
)?;
} }
Commands::ExampleBuild => { Commands::ExampleBuild => {
info!("Building for backend: {backend:?}"); info!("Building for backend: {backend:?}");
example_build(&cargologlevel, backend, &examples_to_run)?; cargo_example(
BuildOrCheck::Build,
&cargologlevel,
backend,
&examples_to_run,
)?;
} }
Commands::Size(arguments) => { Commands::Size(arguments) => {
// x86_64 target not valid // x86_64 target not valid
@ -388,75 +405,74 @@ fn main() -> anyhow::Result<()> {
Ok(()) Ok(())
} }
fn cargo_build( fn cargo(
operation: BuildOrCheck,
cargoarg: &Option<&str>, cargoarg: &Option<&str>,
package: &Package, package: &Package,
backend: Backends, backend: Backends,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let packages_to_check = package_filter(package); // rtic crate has features which needs special handling
if packages_to_check.contains(&"rtic".to_owned()) { let rtic_features = &format!("{},{}", DEFAULT_FEATURES, backend.to_rtic_feature());
// rtic crate has features which needs special handling let features: Option<&str>;
let s = format!("{},{}", DEFAULT_FEATURES, backend.to_rtic_feature()); let packages = package_filter(package);
let features: Option<&str> = Some(&s); features = if packages.contains(&"rtic".to_owned()) {
Some(&rtic_features)
command_parser(
&CargoCommand::Build {
cargoarg,
package: packages_to_check,
target: backend.to_target(),
features,
mode: BuildMode::Release,
},
false,
)?;
} else { } else {
command_parser( None
&CargoCommand::Build { };
cargoarg,
package: package_filter(package), let command = match operation {
target: backend.to_target(), BuildOrCheck::Check => CargoCommand::Check {
features: None, cargoarg,
mode: BuildMode::Release, package: packages,
}, target: backend.to_target(),
false, features,
)?; mode: BuildMode::Release,
} },
BuildOrCheck::Build => CargoCommand::Build {
cargoarg,
package: packages,
target: backend.to_target(),
features,
mode: BuildMode::Release,
},
};
command_parser(&command, false)?;
Ok(()) Ok(())
} }
fn cargo_check( fn cargo_example(
operation: BuildOrCheck,
cargoarg: &Option<&str>, cargoarg: &Option<&str>,
package: &Package,
backend: Backends, backend: Backends,
examples: &[String],
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let packages_to_check = package_filter(package); let s = format!("{},{}", DEFAULT_FEATURES, backend.to_rtic_feature());
if packages_to_check.contains(&"rtic".to_owned()) { let features: Option<&str> = Some(&s);
// rtic crate has features which needs special handling
let s = format!("{},{}", DEFAULT_FEATURES, backend.to_rtic_feature());
let features: Option<&str> = Some(&s);
command_parser( examples.into_par_iter().for_each(|example| {
&CargoCommand::Check { let command = match operation {
BuildOrCheck::Check => CargoCommand::ExampleCheck {
cargoarg, cargoarg,
package: package_filter(package), example,
target: backend.to_target(), target: backend.to_target(),
features, features,
mode: BuildMode::Release, mode: BuildMode::Release,
}, },
false, BuildOrCheck::Build => CargoCommand::ExampleBuild {
)?;
} else {
command_parser(
&CargoCommand::Check {
cargoarg, cargoarg,
package: package_filter(package), example,
target: backend.to_target(), target: backend.to_target(),
features: None, features,
mode: BuildMode::Release, mode: BuildMode::Release,
}, },
false, };
)?;
} if let Err(err) = command_parser(&command, false) {
error!("{err}");
}
});
Ok(()) Ok(())
} }
@ -554,55 +570,6 @@ fn run_test(
Ok(()) Ok(())
} }
fn example_check(
cargoarg: &Option<&str>,
backend: Backends,
examples: &[String],
) -> anyhow::Result<()> {
let s = format!("{},{}", DEFAULT_FEATURES, backend.to_rtic_feature());
let features: Option<&str> = Some(&s);
examples.into_par_iter().for_each(|example| {
let cmd = CargoCommand::ExampleCheck {
cargoarg,
example,
target: backend.to_target(),
features,
mode: BuildMode::Release,
};
if let Err(err) = command_parser(&cmd, false) {
error!("{err}");
}
});
Ok(())
}
fn example_build(
cargoarg: &Option<&str>,
backend: Backends,
examples: &[String],
) -> anyhow::Result<()> {
let s = format!("{},{}", DEFAULT_FEATURES, backend.to_rtic_feature());
let features: Option<&str> = Some(&s);
examples.into_par_iter().for_each(|example| {
let cmd = CargoCommand::ExampleBuild {
cargoarg,
example,
target: backend.to_target(),
features,
mode: BuildMode::Release,
};
if let Err(err) = command_parser(&cmd, false) {
error!("{err}");
}
});
Ok(())
}
fn build_and_check_size( fn build_and_check_size(
cargoarg: &Option<&str>, cargoarg: &Option<&str>,