mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-23 20:22:51 +01:00
Move run into a subdirectory and split iter
stuff into a module
This commit is contained in:
parent
c6b43800d2
commit
b87d55f960
2 changed files with 59 additions and 77 deletions
48
xtask/src/run/iter.rs
Normal file
48
xtask/src/run/iter.rs
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
use super::FinalRunResult;
|
||||||
|
|
||||||
|
pub use iter::*;
|
||||||
|
|
||||||
|
pub trait CoalescingRunner<'c> {
|
||||||
|
/// Run all the commands in this iterator, and coalesce the results into
|
||||||
|
/// one error (if any individual commands failed)
|
||||||
|
fn run_and_coalesce(self) -> Vec<FinalRunResult<'c>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "rayon"))]
|
||||||
|
mod iter {
|
||||||
|
use super::*;
|
||||||
|
use crate::{argument_parsing::Globals, cargo_command::*, run::run_and_convert};
|
||||||
|
|
||||||
|
pub fn into_iter<T: IntoIterator>(var: T) -> impl Iterator<Item = T::Item> {
|
||||||
|
var.into_iter()
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'g, 'c, I> CoalescingRunner<'c> for I
|
||||||
|
where
|
||||||
|
I: Iterator<Item = (&'g Globals, CargoCommand<'c>, bool)>,
|
||||||
|
{
|
||||||
|
fn run_and_coalesce(self) -> Vec<FinalRunResult<'c>> {
|
||||||
|
self.map(run_and_convert).collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "rayon")]
|
||||||
|
mod iter {
|
||||||
|
use super::*;
|
||||||
|
use crate::{argument_parsing::Globals, cargo_command::*, run::run_and_convert};
|
||||||
|
use rayon::prelude::*;
|
||||||
|
|
||||||
|
pub fn into_iter<T: IntoParallelIterator>(var: T) -> impl ParallelIterator<Item = T::Item> {
|
||||||
|
var.into_par_iter()
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'g, 'c, I> CoalescingRunner<'c> for I
|
||||||
|
where
|
||||||
|
I: ParallelIterator<Item = (&'g Globals, CargoCommand<'c>, bool)>,
|
||||||
|
{
|
||||||
|
fn run_and_coalesce(self) -> Vec<FinalRunResult<'c>> {
|
||||||
|
self.map(run_and_convert).collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,18 +5,20 @@ use std::{
|
||||||
process::{Command, Stdio},
|
process::{Command, Stdio},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
mod iter;
|
||||||
|
use iter::{into_iter, CoalescingRunner};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
argument_parsing::{Backends, BuildOrCheck, ExtraArguments, Globals, PackageOpt, TestMetadata},
|
argument_parsing::{Backends, BuildOrCheck, ExtraArguments, Globals, PackageOpt, TestMetadata},
|
||||||
cargo_command::{BuildMode, CargoCommand},
|
cargo_command::{BuildMode, CargoCommand},
|
||||||
command_parser, RunResult, TestRunError,
|
command_parser, RunResult, TestRunError,
|
||||||
};
|
};
|
||||||
|
|
||||||
use log::{error, info, Level};
|
use log::{error, info, Level};
|
||||||
|
|
||||||
#[cfg(feature = "rayon")]
|
#[cfg(feature = "rayon")]
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
|
||||||
use iters::*;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum OutputMode {
|
pub enum OutputMode {
|
||||||
PipedAndCollected,
|
PipedAndCollected,
|
||||||
|
@ -64,48 +66,6 @@ fn run_and_convert<'a>(
|
||||||
output
|
output
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait CoalescingRunner<'c> {
|
|
||||||
/// Run all the commands in this iterator, and coalesce the results into
|
|
||||||
/// one error (if any individual commands failed)
|
|
||||||
fn run_and_coalesce(self) -> Vec<FinalRunResult<'c>>;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "rayon"))]
|
|
||||||
mod iters {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
pub fn examples_iter(examples: &[String]) -> impl Iterator<Item = &String> {
|
|
||||||
examples.into_iter()
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'g, 'c, I> CoalescingRunner<'c> for I
|
|
||||||
where
|
|
||||||
I: Iterator<Item = (&'g Globals, CargoCommand<'c>, bool)>,
|
|
||||||
{
|
|
||||||
fn run_and_coalesce(self) -> Vec<FinalRunResult<'c>> {
|
|
||||||
self.map(run_and_convert).collect()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "rayon")]
|
|
||||||
mod iters {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
pub fn examples_iter(examples: &[String]) -> impl ParallelIterator<Item = &String> {
|
|
||||||
examples.into_par_iter()
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'g, 'c, I> CoalescingRunner<'c> for I
|
|
||||||
where
|
|
||||||
I: ParallelIterator<Item = (&'g Globals, CargoCommand<'c>, bool)>,
|
|
||||||
{
|
|
||||||
fn run_and_coalesce(self) -> Vec<FinalRunResult<'c>> {
|
|
||||||
self.map(run_and_convert).collect()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Cargo command to either build or check
|
/// Cargo command to either build or check
|
||||||
pub fn cargo<'c>(
|
pub fn cargo<'c>(
|
||||||
globals: &Globals,
|
globals: &Globals,
|
||||||
|
@ -119,16 +79,7 @@ pub fn cargo<'c>(
|
||||||
.flat_map(|package| {
|
.flat_map(|package| {
|
||||||
let target = backend.to_target();
|
let target = backend.to_target();
|
||||||
let features = package.features(target, backend, globals.partial);
|
let features = package.features(target, backend, globals.partial);
|
||||||
|
into_iter(features).map(move |f| (package, target, f))
|
||||||
#[cfg(feature = "rayon")]
|
|
||||||
{
|
|
||||||
features.into_par_iter().map(move |f| (package, target, f))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "rayon"))]
|
|
||||||
{
|
|
||||||
features.into_iter().map(move |f| (package, target, f))
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.map(move |(package, target, features)| {
|
.map(move |(package, target, features)| {
|
||||||
let target = target.into();
|
let target = target.into();
|
||||||
|
@ -165,7 +116,7 @@ pub fn cargo_usage_example(
|
||||||
operation: BuildOrCheck,
|
operation: BuildOrCheck,
|
||||||
usage_examples: Vec<String>,
|
usage_examples: Vec<String>,
|
||||||
) -> Vec<FinalRunResult<'_>> {
|
) -> Vec<FinalRunResult<'_>> {
|
||||||
examples_iter(&usage_examples)
|
into_iter(&usage_examples)
|
||||||
.map(|example| {
|
.map(|example| {
|
||||||
let path = format!("examples/{example}");
|
let path = format!("examples/{example}");
|
||||||
|
|
||||||
|
@ -202,7 +153,7 @@ pub fn cargo_example<'c>(
|
||||||
backend: Backends,
|
backend: Backends,
|
||||||
examples: &'c [String],
|
examples: &'c [String],
|
||||||
) -> Vec<FinalRunResult<'c>> {
|
) -> Vec<FinalRunResult<'c>> {
|
||||||
let runner = examples_iter(examples).map(|example| {
|
let runner = into_iter(examples).map(|example| {
|
||||||
let features = Some(backend.to_target().and_features(backend.to_rtic_feature()));
|
let features = Some(backend.to_target().and_features(backend.to_rtic_feature()));
|
||||||
|
|
||||||
let command = match operation {
|
let command = match operation {
|
||||||
|
@ -239,16 +190,7 @@ pub fn cargo_clippy<'c>(
|
||||||
.flat_map(|package| {
|
.flat_map(|package| {
|
||||||
let target = backend.to_target();
|
let target = backend.to_target();
|
||||||
let features = package.features(target, backend, globals.partial);
|
let features = package.features(target, backend, globals.partial);
|
||||||
|
into_iter(features).map(move |f| (package, target, f))
|
||||||
#[cfg(feature = "rayon")]
|
|
||||||
{
|
|
||||||
features.into_par_iter().map(move |f| (package, target, f))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "rayon"))]
|
|
||||||
{
|
|
||||||
features.into_iter().map(move |f| (package, target, f))
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.map(move |(package, target, features)| {
|
.map(move |(package, target, features)| {
|
||||||
let command = CargoCommand::Clippy {
|
let command = CargoCommand::Clippy {
|
||||||
|
@ -344,7 +286,7 @@ pub fn qemu_run_examples<'c>(
|
||||||
let target = backend.to_target();
|
let target = backend.to_target();
|
||||||
let features = Some(target.and_features(backend.to_rtic_feature()));
|
let features = Some(target.and_features(backend.to_rtic_feature()));
|
||||||
|
|
||||||
examples_iter(examples)
|
into_iter(examples)
|
||||||
.flat_map(|example| {
|
.flat_map(|example| {
|
||||||
let target = target.into();
|
let target = target.into();
|
||||||
let cmd_build = CargoCommand::ExampleBuild {
|
let cmd_build = CargoCommand::ExampleBuild {
|
||||||
|
@ -365,15 +307,7 @@ pub fn qemu_run_examples<'c>(
|
||||||
dir: Some(PathBuf::from("./rtic")),
|
dir: Some(PathBuf::from("./rtic")),
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(not(feature = "rayon"))]
|
into_iter([cmd_build, cmd_qemu])
|
||||||
{
|
|
||||||
[cmd_build, cmd_qemu].into_iter()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "rayon")]
|
|
||||||
{
|
|
||||||
[cmd_build, cmd_qemu].into_par_iter()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.map(|cmd| (globals, cmd, overwrite))
|
.map(|cmd| (globals, cmd, overwrite))
|
||||||
.run_and_coalesce()
|
.run_and_coalesce()
|
||||||
|
@ -390,7 +324,7 @@ pub fn build_and_check_size<'c>(
|
||||||
let target = backend.to_target();
|
let target = backend.to_target();
|
||||||
let features = Some(target.and_features(backend.to_rtic_feature()));
|
let features = Some(target.and_features(backend.to_rtic_feature()));
|
||||||
|
|
||||||
let runner = examples_iter(examples).map(|example| {
|
let runner = into_iter(examples).map(|example| {
|
||||||
let target = target.into();
|
let target = target.into();
|
||||||
|
|
||||||
// Make sure the requested example(s) are built
|
// Make sure the requested example(s) are built
|
Loading…
Reference in a new issue