mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-25 21:19:35 +01:00
Always run stuff for all packages if none is specified
This commit is contained in:
parent
f2115e3d47
commit
480aa21059
3 changed files with 115 additions and 95 deletions
|
@ -29,6 +29,30 @@ impl Package {
|
||||||
Package::RticTime => "rtic-time",
|
Package::RticTime => "rtic-time",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn all() -> Vec<Self> {
|
||||||
|
vec![
|
||||||
|
Self::Rtic,
|
||||||
|
Self::RticCommon,
|
||||||
|
Self::RticMacros,
|
||||||
|
Self::RticMonotonics,
|
||||||
|
Self::RticSync,
|
||||||
|
Self::RticTime,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the features needed given the selected package
|
||||||
|
///
|
||||||
|
/// Without package specified the features for RTIC are required
|
||||||
|
/// With only a single package which is not RTIC, no special
|
||||||
|
/// features are needed
|
||||||
|
pub fn extract_features(&self, target: Target, backend: Backends) -> Option<String> {
|
||||||
|
match self {
|
||||||
|
Package::Rtic => Some(target.and_features(backend.to_rtic_feature())),
|
||||||
|
Package::RticMacros => Some(backend.to_rtic_macros_feature().to_owned()),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TestMetadata {}
|
pub struct TestMetadata {}
|
||||||
|
@ -247,7 +271,16 @@ pub struct PackageOpt {
|
||||||
/// For which package/workspace member to operate
|
/// For which package/workspace member to operate
|
||||||
///
|
///
|
||||||
/// If omitted, work on all
|
/// If omitted, work on all
|
||||||
pub package: Option<Package>,
|
package: Option<Package>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PackageOpt {
|
||||||
|
pub fn packages(&self) -> impl Iterator<Item = Package> {
|
||||||
|
self.package
|
||||||
|
.map(|p| vec![p])
|
||||||
|
.unwrap_or(Package::all())
|
||||||
|
.into_iter()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Args, Debug, Clone)]
|
#[derive(Args, Debug, Clone)]
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
argument_parsing::{
|
argument_parsing::{Backends, BuildOrCheck, ExtraArguments, Globals, PackageOpt, TestMetadata},
|
||||||
Backends, BuildOrCheck, ExtraArguments, Globals, Package, PackageOpt, TestMetadata,
|
|
||||||
},
|
|
||||||
command::{BuildMode, CargoCommand},
|
command::{BuildMode, CargoCommand},
|
||||||
command_parser, package_feature_extractor,
|
command_parser,
|
||||||
};
|
};
|
||||||
use log::error;
|
use log::error;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
@ -16,26 +14,42 @@ pub fn cargo(
|
||||||
package: &PackageOpt,
|
package: &PackageOpt,
|
||||||
backend: Backends,
|
backend: Backends,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let target = backend.to_target();
|
package.packages().for_each(|package| {
|
||||||
let features = package_feature_extractor(target, package, backend);
|
let target = backend.to_target();
|
||||||
|
|
||||||
|
let features = package.extract_features(target, backend);
|
||||||
|
|
||||||
|
match operation {
|
||||||
|
BuildOrCheck::Check => {
|
||||||
|
log::debug!(target: "xtask::command", "Checking package: {package}")
|
||||||
|
}
|
||||||
|
BuildOrCheck::Build => {
|
||||||
|
log::debug!(target: "xtask::command", "Building package: {package}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let command = match operation {
|
||||||
|
BuildOrCheck::Check => CargoCommand::Check {
|
||||||
|
cargoarg,
|
||||||
|
package: Some(package),
|
||||||
|
target,
|
||||||
|
features,
|
||||||
|
mode: BuildMode::Release,
|
||||||
|
},
|
||||||
|
BuildOrCheck::Build => CargoCommand::Build {
|
||||||
|
cargoarg,
|
||||||
|
package: Some(package),
|
||||||
|
target,
|
||||||
|
features,
|
||||||
|
mode: BuildMode::Release,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
let res = command_parser(globals, &command, false);
|
||||||
|
if let Err(e) = res {
|
||||||
|
error!("{e}");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let command = match operation {
|
|
||||||
BuildOrCheck::Check => CargoCommand::Check {
|
|
||||||
cargoarg,
|
|
||||||
package: package.package,
|
|
||||||
target,
|
|
||||||
features,
|
|
||||||
mode: BuildMode::Release,
|
|
||||||
},
|
|
||||||
BuildOrCheck::Build => CargoCommand::Build {
|
|
||||||
cargoarg,
|
|
||||||
package: package.package,
|
|
||||||
target,
|
|
||||||
features,
|
|
||||||
mode: BuildMode::Release,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
command_parser(globals, &command, false)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,18 +98,26 @@ pub fn cargo_clippy(
|
||||||
package: &PackageOpt,
|
package: &PackageOpt,
|
||||||
backend: Backends,
|
backend: Backends,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let target = backend.to_target();
|
package.packages().for_each(|p| {
|
||||||
let features = package_feature_extractor(target, package, backend);
|
let target = backend.to_target();
|
||||||
command_parser(
|
let features = p.extract_features(target, backend);
|
||||||
globals,
|
|
||||||
&CargoCommand::Clippy {
|
let res = command_parser(
|
||||||
cargoarg,
|
globals,
|
||||||
package: package.package,
|
&CargoCommand::Clippy {
|
||||||
target,
|
cargoarg,
|
||||||
features,
|
package: Some(p),
|
||||||
},
|
target,
|
||||||
false,
|
features,
|
||||||
)?;
|
},
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
if let Err(e) = res {
|
||||||
|
error!("{e}")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,15 +128,22 @@ pub fn cargo_format(
|
||||||
package: &PackageOpt,
|
package: &PackageOpt,
|
||||||
check_only: bool,
|
check_only: bool,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
command_parser(
|
package.packages().for_each(|p| {
|
||||||
globals,
|
let res = command_parser(
|
||||||
&CargoCommand::Format {
|
globals,
|
||||||
cargoarg,
|
&CargoCommand::Format {
|
||||||
package: package.package,
|
cargoarg,
|
||||||
check_only,
|
package: Some(p),
|
||||||
},
|
check_only,
|
||||||
false,
|
},
|
||||||
)?;
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
if let Err(e) = res {
|
||||||
|
error!("{e}")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,32 +176,13 @@ pub fn cargo_test(
|
||||||
package: &PackageOpt,
|
package: &PackageOpt,
|
||||||
backend: Backends,
|
backend: Backends,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
if let Some(package) = package.package {
|
package.packages().for_each(|p| {
|
||||||
let cmd = TestMetadata::match_package(package, backend);
|
let cmd = &TestMetadata::match_package(p, backend);
|
||||||
command_parser(globals, &cmd, false)?;
|
if let Err(err) = command_parser(globals, cmd, false) {
|
||||||
} else {
|
error!("{err}")
|
||||||
// Iterate over all workspace packages
|
|
||||||
for package in [
|
|
||||||
Package::Rtic,
|
|
||||||
Package::RticCommon,
|
|
||||||
Package::RticMacros,
|
|
||||||
Package::RticMonotonics,
|
|
||||||
Package::RticSync,
|
|
||||||
Package::RticTime,
|
|
||||||
] {
|
|
||||||
let mut error_messages = vec![];
|
|
||||||
let cmd = &TestMetadata::match_package(package, backend);
|
|
||||||
if let Err(err) = command_parser(globals, cmd, false) {
|
|
||||||
error_messages.push(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
if !error_messages.is_empty() {
|
|
||||||
for err in error_messages {
|
|
||||||
error!("{err}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,6 +219,7 @@ pub fn run_test(
|
||||||
features: features.clone(),
|
features: features.clone(),
|
||||||
mode: BuildMode::Release,
|
mode: BuildMode::Release,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(err) = command_parser(globals, &cmd, false) {
|
if let Err(err) = command_parser(globals, &cmd, false) {
|
||||||
error!("{err}");
|
error!("{err}");
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ use env_logger::Env;
|
||||||
use log::{debug, error, info, log_enabled, trace, Level};
|
use log::{debug, error, info, log_enabled, trace, Level};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
argument_parsing::{Backends, BuildOrCheck, Cli, Commands, PackageOpt},
|
argument_parsing::{Backends, BuildOrCheck, Cli, Commands},
|
||||||
build::init_build_dir,
|
build::init_build_dir,
|
||||||
cargo_commands::{
|
cargo_commands::{
|
||||||
build_and_check_size, cargo, cargo_book, cargo_clippy, cargo_doc, cargo_example,
|
build_and_check_size, cargo, cargo_book, cargo_clippy, cargo_doc, cargo_example,
|
||||||
|
@ -299,30 +299,6 @@ fn main() -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the features needed given the selected package
|
|
||||||
///
|
|
||||||
/// Without package specified the features for RTIC are required
|
|
||||||
/// With only a single package which is not RTIC, no special
|
|
||||||
/// features are needed
|
|
||||||
fn package_feature_extractor(
|
|
||||||
target: Target,
|
|
||||||
package: &PackageOpt,
|
|
||||||
backend: Backends,
|
|
||||||
) -> Option<String> {
|
|
||||||
let default_features = Some(target.and_features(backend.to_rtic_feature()));
|
|
||||||
|
|
||||||
if let Some(package) = package.package {
|
|
||||||
debug!("\nTesting package: {package}");
|
|
||||||
match package {
|
|
||||||
Package::Rtic => default_features,
|
|
||||||
Package::RticMacros => Some(backend.to_rtic_macros_feature().to_owned()),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
default_features
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// run example binary `example`
|
// run example binary `example`
|
||||||
fn command_parser(glob: &Globals, command: &CargoCommand, overwrite: bool) -> anyhow::Result<()> {
|
fn command_parser(glob: &Globals, command: &CargoCommand, overwrite: bool) -> anyhow::Result<()> {
|
||||||
let output_mode = if glob.stderr_inherited {
|
let output_mode = if glob.stderr_inherited {
|
||||||
|
|
Loading…
Reference in a new issue