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 {}
|
pub struct TestMetadata {}
|
||||||
|
|
||||||
impl 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 {
|
match package {
|
||||||
Package::Rtic => {
|
Package::Rtic => {
|
||||||
let features = Some(backend.to_target().and_features(backend.to_rtic_feature()));
|
let features = Some(backend.to_target().and_features(backend.to_rtic_feature()));
|
||||||
|
|
@ -102,6 +102,7 @@ impl TestMetadata {
|
||||||
features,
|
features,
|
||||||
test: Some("ui".to_owned()),
|
test: Some("ui".to_owned()),
|
||||||
deny_warnings: true,
|
deny_warnings: true,
|
||||||
|
loom,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Package::RticMacros => CargoCommand::Test {
|
Package::RticMacros => CargoCommand::Test {
|
||||||
|
|
@ -109,30 +110,35 @@ impl TestMetadata {
|
||||||
features: Some(backend.to_rtic_macros_feature().to_owned()),
|
features: Some(backend.to_rtic_macros_feature().to_owned()),
|
||||||
test: None,
|
test: None,
|
||||||
deny_warnings: true,
|
deny_warnings: true,
|
||||||
|
loom,
|
||||||
},
|
},
|
||||||
Package::RticSync => CargoCommand::Test {
|
Package::RticSync => CargoCommand::Test {
|
||||||
package: Some(package.name()),
|
package: Some(package.name()),
|
||||||
features: Some("testing".to_owned()),
|
features: Some("testing".to_owned()),
|
||||||
test: None,
|
test: None,
|
||||||
deny_warnings: true,
|
deny_warnings: true,
|
||||||
|
loom,
|
||||||
},
|
},
|
||||||
Package::RticCommon => CargoCommand::Test {
|
Package::RticCommon => CargoCommand::Test {
|
||||||
package: Some(package.name()),
|
package: Some(package.name()),
|
||||||
features: Some("testing".to_owned()),
|
features: Some("testing".to_owned()),
|
||||||
test: None,
|
test: None,
|
||||||
deny_warnings: true,
|
deny_warnings: true,
|
||||||
|
loom,
|
||||||
},
|
},
|
||||||
Package::RticMonotonics => CargoCommand::Test {
|
Package::RticMonotonics => CargoCommand::Test {
|
||||||
package: Some(package.name()),
|
package: Some(package.name()),
|
||||||
features: None,
|
features: None,
|
||||||
test: None,
|
test: None,
|
||||||
deny_warnings: true,
|
deny_warnings: true,
|
||||||
|
loom,
|
||||||
},
|
},
|
||||||
Package::RticTime => CargoCommand::Test {
|
Package::RticTime => CargoCommand::Test {
|
||||||
package: Some(package.name()),
|
package: Some(package.name()),
|
||||||
features: Some("critical-section/std".into()),
|
features: Some("critical-section/std".into()),
|
||||||
test: None,
|
test: None,
|
||||||
deny_warnings: true,
|
deny_warnings: true,
|
||||||
|
loom,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -489,7 +495,7 @@ pub enum Commands {
|
||||||
Doc(Arg),
|
Doc(Arg),
|
||||||
|
|
||||||
/// Run tests
|
/// Run tests
|
||||||
Test(PackageOpt),
|
Test(TestOpt),
|
||||||
|
|
||||||
/// Build books with mdbook
|
/// Build books with mdbook
|
||||||
Book(Arg),
|
Book(Arg),
|
||||||
|
|
@ -511,12 +517,21 @@ pub struct FormatOpt {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Args, Debug, Clone, Default)]
|
#[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
|
/// Restrict to package, or run on whole workspace
|
||||||
pub struct PackageOpt {
|
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
|
||||||
package: Option<Package>,
|
pub package: Option<Package>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PackageOpt {
|
impl PackageOpt {
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,7 @@ pub enum CargoCommand<'a> {
|
||||||
features: Option<String>,
|
features: Option<String>,
|
||||||
test: Option<String>,
|
test: Option<String>,
|
||||||
deny_warnings: bool,
|
deny_warnings: bool,
|
||||||
|
loom: bool,
|
||||||
},
|
},
|
||||||
Book {
|
Book {
|
||||||
arguments: Option<ExtraArguments>,
|
arguments: Option<ExtraArguments>,
|
||||||
|
|
@ -336,6 +337,7 @@ impl core::fmt::Display for CargoCommand<'_> {
|
||||||
features,
|
features,
|
||||||
test,
|
test,
|
||||||
deny_warnings,
|
deny_warnings,
|
||||||
|
loom: _,
|
||||||
} => {
|
} => {
|
||||||
let p = p(package);
|
let p = p(package);
|
||||||
let test = test
|
let test = test
|
||||||
|
|
@ -576,15 +578,23 @@ impl<'a> CargoCommand<'a> {
|
||||||
test,
|
test,
|
||||||
// deny_warnings is exposed through `extra_env`
|
// deny_warnings is exposed through `extra_env`
|
||||||
deny_warnings: _,
|
deny_warnings: _,
|
||||||
|
loom,
|
||||||
} => {
|
} => {
|
||||||
let extra = if let Some(test) = test {
|
let mut extra = if let Some(test) = test {
|
||||||
vec!["--test", test]
|
vec!["--test", test]
|
||||||
} else {
|
} else {
|
||||||
vec![]
|
vec![]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let cargofeatures = if *loom {
|
||||||
|
extra.push(" --lib");
|
||||||
|
&None
|
||||||
|
} else {
|
||||||
|
features
|
||||||
|
};
|
||||||
let package = p(package);
|
let package = p(package);
|
||||||
let extra = extra.into_iter().chain(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 } => {
|
CargoCommand::Book { arguments } => {
|
||||||
let mut args = vec![];
|
let mut args = vec![];
|
||||||
|
|
@ -740,14 +750,33 @@ impl<'a> CargoCommand<'a> {
|
||||||
|
|
||||||
CargoCommand::Check { deny_warnings, .. }
|
CargoCommand::Check { deny_warnings, .. }
|
||||||
| CargoCommand::ExampleCheck { deny_warnings, .. }
|
| CargoCommand::ExampleCheck { deny_warnings, .. }
|
||||||
| CargoCommand::Build { deny_warnings, .. }
|
| CargoCommand::Build { deny_warnings, .. } => {
|
||||||
| CargoCommand::Test { deny_warnings, .. } => {
|
|
||||||
if *deny_warnings {
|
if *deny_warnings {
|
||||||
Some(("RUSTFLAGS", "-D warnings".to_string()))
|
Some(("RUSTFLAGS", "-D warnings".to_string()))
|
||||||
} else {
|
} else {
|
||||||
None
|
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,
|
_ => 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 cargo_command;
|
||||||
mod run;
|
mod run;
|
||||||
|
|
||||||
use argument_parsing::{ExtraArguments, FormatOpt, PackageOpt};
|
use argument_parsing::{ExtraArguments, FormatOpt, Package, PackageOpt, TestOpt};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use std::{path::Path, str};
|
use std::{path::Path, str};
|
||||||
|
|
@ -181,6 +181,14 @@ fn main() -> anyhow::Result<()> {
|
||||||
// Default set of all packages
|
// Default set of all packages
|
||||||
// CI always runs on all packages
|
// CI always runs on all packages
|
||||||
let package = PackageOpt::default();
|
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 {
|
let final_run_results = match &cli.command {
|
||||||
Commands::AllCi(args) => {
|
Commands::AllCi(args) => {
|
||||||
|
|
@ -263,7 +271,12 @@ fn main() -> anyhow::Result<()> {
|
||||||
return handle_results(globals, results)
|
return handle_results(globals, results)
|
||||||
.map_err(|_| anyhow::anyhow!("Commands failed"));
|
.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 {
|
if args.failearly {
|
||||||
return handle_results(globals, results)
|
return handle_results(globals, results)
|
||||||
.map_err(|_| anyhow::anyhow!("Commands failed"));
|
.map_err(|_| anyhow::anyhow!("Commands failed"));
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ use iter::{into_iter, CoalescingRunner};
|
||||||
use crate::{
|
use crate::{
|
||||||
argument_parsing::{
|
argument_parsing::{
|
||||||
Backends, BuildOrCheck, ExtraArguments, FormatOpt, Globals, PackageOpt, Platforms,
|
Backends, BuildOrCheck, ExtraArguments, FormatOpt, Globals, PackageOpt, Platforms,
|
||||||
TestMetadata,
|
TestMetadata, TestOpt,
|
||||||
},
|
},
|
||||||
cargo_command::{BuildMode, CargoCommand},
|
cargo_command::{BuildMode, CargoCommand},
|
||||||
};
|
};
|
||||||
|
|
@ -341,14 +341,15 @@ pub fn cargo_doc<'c>(
|
||||||
/// If no package is specified, loop through all packages
|
/// If no package is specified, loop through all packages
|
||||||
pub fn cargo_test<'c>(
|
pub fn cargo_test<'c>(
|
||||||
globals: &Globals,
|
globals: &Globals,
|
||||||
package: &'c PackageOpt,
|
testopts: &'c TestOpt,
|
||||||
backend: Backends,
|
backend: Backends,
|
||||||
) -> Vec<FinalRunResult<'c>> {
|
) -> Vec<FinalRunResult<'c>> {
|
||||||
info!("Running cargo test on backend: {backend:?}");
|
info!("Running cargo test on backend: {backend:?}");
|
||||||
|
let TestOpt { package, loom } = testopts;
|
||||||
package
|
package
|
||||||
.packages()
|
.packages()
|
||||||
.map(|p| {
|
.map(|p| {
|
||||||
let meta = TestMetadata::match_package(p, backend);
|
let meta = TestMetadata::match_package(p, backend, *loom);
|
||||||
(globals, meta, false)
|
(globals, meta, false)
|
||||||
})
|
})
|
||||||
.run_and_coalesce()
|
.run_and_coalesce()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue