mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-16 21:05:35 +01:00
xtask: Add --loom argument to test
For now filter to only rtic-sync in ci subcommand
This commit is contained in:
parent
6a68e8e54d
commit
90bb324906
5 changed files with 71 additions and 12 deletions
|
|
@ -93,7 +93,7 @@ impl Package {
|
|||
pub struct TestMetadata {}
|
||||
|
||||
impl TestMetadata {
|
||||
pub fn match_package(package: Package, backend: Backends) -> CargoCommand<'static> {
|
||||
pub fn match_package(package: Package, backend: Backends, loom: bool) -> CargoCommand<'static> {
|
||||
match package {
|
||||
Package::Rtic => {
|
||||
let features = Some(backend.to_target().and_features(backend.to_rtic_feature()));
|
||||
|
|
@ -102,6 +102,7 @@ impl TestMetadata {
|
|||
features,
|
||||
test: Some("ui".to_owned()),
|
||||
deny_warnings: true,
|
||||
loom,
|
||||
}
|
||||
}
|
||||
Package::RticMacros => CargoCommand::Test {
|
||||
|
|
@ -109,30 +110,35 @@ impl TestMetadata {
|
|||
features: Some(backend.to_rtic_macros_feature().to_owned()),
|
||||
test: None,
|
||||
deny_warnings: true,
|
||||
loom,
|
||||
},
|
||||
Package::RticSync => CargoCommand::Test {
|
||||
package: Some(package.name()),
|
||||
features: Some("testing".to_owned()),
|
||||
test: None,
|
||||
deny_warnings: true,
|
||||
loom,
|
||||
},
|
||||
Package::RticCommon => CargoCommand::Test {
|
||||
package: Some(package.name()),
|
||||
features: Some("testing".to_owned()),
|
||||
test: None,
|
||||
deny_warnings: true,
|
||||
loom,
|
||||
},
|
||||
Package::RticMonotonics => CargoCommand::Test {
|
||||
package: Some(package.name()),
|
||||
features: None,
|
||||
test: None,
|
||||
deny_warnings: true,
|
||||
loom,
|
||||
},
|
||||
Package::RticTime => CargoCommand::Test {
|
||||
package: Some(package.name()),
|
||||
features: Some("critical-section/std".into()),
|
||||
test: None,
|
||||
deny_warnings: true,
|
||||
loom,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -489,7 +495,7 @@ pub enum Commands {
|
|||
Doc(Arg),
|
||||
|
||||
/// Run tests
|
||||
Test(PackageOpt),
|
||||
Test(TestOpt),
|
||||
|
||||
/// Build books with mdbook
|
||||
Book(Arg),
|
||||
|
|
@ -511,12 +517,21 @@ pub struct FormatOpt {
|
|||
}
|
||||
|
||||
#[derive(Args, Debug, Clone, Default)]
|
||||
pub struct TestOpt {
|
||||
#[clap(flatten)]
|
||||
pub package: PackageOpt,
|
||||
/// Should tests be loom tests
|
||||
#[clap(short, long)]
|
||||
pub loom: bool,
|
||||
}
|
||||
|
||||
#[derive(Args, Debug, Clone, Copy, Default)]
|
||||
/// Restrict to package, or run on whole workspace
|
||||
pub struct PackageOpt {
|
||||
/// For which package/workspace member to operate
|
||||
///
|
||||
/// If omitted, work on all
|
||||
package: Option<Package>,
|
||||
pub package: Option<Package>,
|
||||
}
|
||||
|
||||
impl PackageOpt {
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@ pub enum CargoCommand<'a> {
|
|||
features: Option<String>,
|
||||
test: Option<String>,
|
||||
deny_warnings: bool,
|
||||
loom: bool,
|
||||
},
|
||||
Book {
|
||||
arguments: Option<ExtraArguments>,
|
||||
|
|
@ -336,6 +337,7 @@ impl core::fmt::Display for CargoCommand<'_> {
|
|||
features,
|
||||
test,
|
||||
deny_warnings,
|
||||
loom: _,
|
||||
} => {
|
||||
let p = p(package);
|
||||
let test = test
|
||||
|
|
@ -576,15 +578,23 @@ impl<'a> CargoCommand<'a> {
|
|||
test,
|
||||
// deny_warnings is exposed through `extra_env`
|
||||
deny_warnings: _,
|
||||
loom,
|
||||
} => {
|
||||
let extra = if let Some(test) = test {
|
||||
let mut extra = if let Some(test) = test {
|
||||
vec!["--test", test]
|
||||
} else {
|
||||
vec![]
|
||||
};
|
||||
|
||||
let cargofeatures = if *loom {
|
||||
extra.push(" --lib");
|
||||
&None
|
||||
} else {
|
||||
features
|
||||
};
|
||||
let package = p(package);
|
||||
let extra = extra.into_iter().chain(package);
|
||||
self.build_args(false, &None, features, None, extra)
|
||||
self.build_args(false, &None, cargofeatures, None, extra)
|
||||
}
|
||||
CargoCommand::Book { arguments } => {
|
||||
let mut args = vec![];
|
||||
|
|
@ -740,14 +750,33 @@ impl<'a> CargoCommand<'a> {
|
|||
|
||||
CargoCommand::Check { deny_warnings, .. }
|
||||
| CargoCommand::ExampleCheck { deny_warnings, .. }
|
||||
| CargoCommand::Build { deny_warnings, .. }
|
||||
| CargoCommand::Test { deny_warnings, .. } => {
|
||||
| CargoCommand::Build { deny_warnings, .. } => {
|
||||
if *deny_warnings {
|
||||
Some(("RUSTFLAGS", "-D warnings".to_string()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
CargoCommand::Test {
|
||||
deny_warnings,
|
||||
loom,
|
||||
..
|
||||
} => {
|
||||
let mut combined_flags = vec![""];
|
||||
|
||||
if *deny_warnings {
|
||||
combined_flags.push("-D warnings");
|
||||
}
|
||||
if *loom {
|
||||
combined_flags.push("--cfg loom");
|
||||
}
|
||||
if !combined_flags.is_empty() {
|
||||
let rust_flags = combined_flags.join(" ").to_string();
|
||||
Some(("RUSTFLAGS", rust_flags))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
1
xtask/src/cargo_test
Normal file
1
xtask/src/cargo_test
Normal file
|
|
@ -0,0 +1 @@
|
|||
|
||||
|
|
@ -3,7 +3,7 @@ mod build;
|
|||
mod cargo_command;
|
||||
mod run;
|
||||
|
||||
use argument_parsing::{ExtraArguments, FormatOpt, PackageOpt};
|
||||
use argument_parsing::{ExtraArguments, FormatOpt, Package, PackageOpt, TestOpt};
|
||||
use clap::Parser;
|
||||
use core::fmt;
|
||||
use std::{path::Path, str};
|
||||
|
|
@ -181,6 +181,14 @@ fn main() -> anyhow::Result<()> {
|
|||
// Default set of all packages
|
||||
// CI always runs on all packages
|
||||
let package = PackageOpt::default();
|
||||
let testopts = TestOpt::default();
|
||||
// Currently only rtic-sync supports loom tests
|
||||
let testoptsloom = TestOpt {
|
||||
loom: true,
|
||||
package: PackageOpt {
|
||||
package: Some(Package::RticSync),
|
||||
},
|
||||
};
|
||||
|
||||
let final_run_results = match &cli.command {
|
||||
Commands::AllCi(args) => {
|
||||
|
|
@ -263,7 +271,12 @@ fn main() -> anyhow::Result<()> {
|
|||
return handle_results(globals, results)
|
||||
.map_err(|_| anyhow::anyhow!("Commands failed"));
|
||||
}
|
||||
results.append(&mut cargo_test(globals, &package, backend));
|
||||
results.append(&mut cargo_test(globals, &testopts, backend));
|
||||
if args.failearly {
|
||||
return handle_results(globals, results)
|
||||
.map_err(|_| anyhow::anyhow!("Commands failed"));
|
||||
}
|
||||
results.append(&mut cargo_test(globals, &testoptsloom, backend));
|
||||
if args.failearly {
|
||||
return handle_results(globals, results)
|
||||
.map_err(|_| anyhow::anyhow!("Commands failed"));
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ use iter::{into_iter, CoalescingRunner};
|
|||
use crate::{
|
||||
argument_parsing::{
|
||||
Backends, BuildOrCheck, ExtraArguments, FormatOpt, Globals, PackageOpt, Platforms,
|
||||
TestMetadata,
|
||||
TestMetadata, TestOpt,
|
||||
},
|
||||
cargo_command::{BuildMode, CargoCommand},
|
||||
};
|
||||
|
|
@ -341,14 +341,15 @@ pub fn cargo_doc<'c>(
|
|||
/// If no package is specified, loop through all packages
|
||||
pub fn cargo_test<'c>(
|
||||
globals: &Globals,
|
||||
package: &'c PackageOpt,
|
||||
testopts: &'c TestOpt,
|
||||
backend: Backends,
|
||||
) -> Vec<FinalRunResult<'c>> {
|
||||
info!("Running cargo test on backend: {backend:?}");
|
||||
let TestOpt { package, loom } = testopts;
|
||||
package
|
||||
.packages()
|
||||
.map(|p| {
|
||||
let meta = TestMetadata::match_package(p, backend);
|
||||
let meta = TestMetadata::match_package(p, backend, *loom);
|
||||
(globals, meta, false)
|
||||
})
|
||||
.run_and_coalesce()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue