|
|
|
@ -41,9 +41,18 @@ type ProgressSender = progress::ProgressSender;
|
|
|
|
|
#[cfg(not(feature="progress"))]
|
|
|
|
|
type ProgressSender = ();
|
|
|
|
|
|
|
|
|
|
#[cfg(feature="collect_err")]
|
|
|
|
|
struct Error
|
|
|
|
|
{
|
|
|
|
|
pub internal: process::Error,
|
|
|
|
|
pub stack: fixed_stack::FixedStack<(bool, String)>,
|
|
|
|
|
}
|
|
|
|
|
#[cfg(not(feature="collect_err"))]
|
|
|
|
|
type Error = process::Error;
|
|
|
|
|
|
|
|
|
|
#[allow(unused_mut)]
|
|
|
|
|
#[allow(unused_variables)]
|
|
|
|
|
async fn do_work(process: impl AsRef<Process>, file: impl AsRef<OsStr>, mut prog: ProgressSender) -> Result<fixed_stack::IntoIter<String>, process::Error>
|
|
|
|
|
async fn do_work(process: impl AsRef<Process>, file: impl AsRef<OsStr>, mut prog: ProgressSender) -> Result<fixed_stack::IntoIter<(bool, String)>, Error>
|
|
|
|
|
{
|
|
|
|
|
let file = file.as_ref();
|
|
|
|
|
|
|
|
|
@ -56,19 +65,25 @@ async fn do_work(process: impl AsRef<Process>, file: impl AsRef<OsStr>, mut prog
|
|
|
|
|
tokio::spawn(async move {
|
|
|
|
|
let mut stack = fixed_stack::FixedStack::new(100);
|
|
|
|
|
while let Some((err, value)) = rx.recv().await {
|
|
|
|
|
if err {
|
|
|
|
|
cfg_if!{
|
|
|
|
|
if #[cfg(feature="progress")] {
|
|
|
|
|
let value = format!("[{}] {:?}: {}", colour::style(colour!(Color::BrightYellow), "!"), file, colour::style(colour!(Color::Yellow),value));
|
|
|
|
|
if let Err(_) = prog.eprintln(&value[..]).await {
|
|
|
|
|
eprintln!("\n{}", value);
|
|
|
|
|
cfg_if! {
|
|
|
|
|
if #[cfg(feature="collect_err")] {
|
|
|
|
|
stack.push((err, value));
|
|
|
|
|
} else {
|
|
|
|
|
if err {
|
|
|
|
|
cfg_if!{
|
|
|
|
|
if #[cfg(feature="progress")] {
|
|
|
|
|
let value = format!("[{}] {:?}: {}", colour::style(colour!(Color::BrightYellow), "!"), file, colour::style(colour!(Color::Yellow),value));
|
|
|
|
|
if let Err(_) = prog.eprintln(&value[..]).await {
|
|
|
|
|
eprintln!("\n{}", value);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
eprintln!("[{}] {:?}: {}", colour::style(colour!(Color::BrightYellow), "!"), file, colour::style(colour!(Color::Yellow),value));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
eprintln!("[{}] {:?}: {}", colour::style(colour!(Color::BrightYellow), "!"), file, colour::style(colour!(Color::Yellow),value));
|
|
|
|
|
stack.push((false, value));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
stack.push(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
stack
|
|
|
|
@ -78,7 +93,18 @@ async fn do_work(process: impl AsRef<Process>, file: impl AsRef<OsStr>, mut prog
|
|
|
|
|
//let _ = opt_await.await;
|
|
|
|
|
match process::contained_spawn(process, std::iter::once(file), tx).await {
|
|
|
|
|
Ok(_) => Ok(collector.await.expect("Child panic").into_iter()),
|
|
|
|
|
Err(error) => Err(error),
|
|
|
|
|
Err(error) => {
|
|
|
|
|
cfg_if! {
|
|
|
|
|
if #[cfg(feature="collect_err")] {
|
|
|
|
|
Err(Error{
|
|
|
|
|
internal: error,
|
|
|
|
|
stack: collector.await.expect("Child panic"),
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
Err(error)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -88,7 +114,7 @@ where I: IntoIterator<Item=T>,
|
|
|
|
|
T: AsRef<OsStr> + Send + Sync + 'static + Clone,
|
|
|
|
|
U: Into<PathBuf>
|
|
|
|
|
{
|
|
|
|
|
let (tx,mut rx) = mpsc::channel::<(T, fixed_stack::IntoIter<String>, usize)>(children.as_ref().map(|&x| usize::from(x)).unwrap_or(16));
|
|
|
|
|
let (tx,mut rx) = mpsc::channel::<(T, fixed_stack::IntoIter<(bool, String)>, usize)>(children.as_ref().map(|&x| usize::from(x)).unwrap_or(16));
|
|
|
|
|
let semaphore = children.map(|children| Arc::new(Semaphore::new(children.into())));
|
|
|
|
|
let process = Arc::new(Process::new(process, flags.leanify_flags.clone()));
|
|
|
|
|
|
|
|
|
@ -109,16 +135,24 @@ where I: IntoIterator<Item=T>,
|
|
|
|
|
cfg_if!{
|
|
|
|
|
if #[cfg(feature="progress")] {
|
|
|
|
|
let mut builder =progress.builder();
|
|
|
|
|
for line in values.into_iter()
|
|
|
|
|
for (err, line) in values.into_iter()
|
|
|
|
|
{
|
|
|
|
|
let line = format!(" -> ({}) {:?}: {}", i, file.as_ref(), line);
|
|
|
|
|
builder.println(line);
|
|
|
|
|
if err {
|
|
|
|
|
builder.eprintln(format!("[{}] {:?}: {}", colour::style(colour!(Color::BrightYellow), "!"), file.as_ref(), colour::style(colour!(Color::Yellow),line)));
|
|
|
|
|
} else {
|
|
|
|
|
let line = format!(" -> ({}) {:?}: {}", i, file.as_ref(), line);
|
|
|
|
|
builder.println(line);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let _ = builder.send().await;
|
|
|
|
|
} else {
|
|
|
|
|
for line in values.into_iter()
|
|
|
|
|
for (err, line) in values.into_iter()
|
|
|
|
|
{
|
|
|
|
|
println!(" -> ({}) {:?}: {}", i, file.as_ref(), line);
|
|
|
|
|
if err {
|
|
|
|
|
eprintln!("[{}] {:?}: {}", colour::style(colour!(Color::BrightYellow), "!"), file.as_ref(), colour::style(colour!(Color::Yellow),line));
|
|
|
|
|
} else {
|
|
|
|
|
println!(" -> ({}) {:?}: {}", i, file.as_ref(), line);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -152,7 +186,7 @@ where I: IntoIterator<Item=T>,
|
|
|
|
|
} else {
|
|
|
|
|
#[cfg(nightly)] type NoReturn = !;
|
|
|
|
|
#[cfg(not(nightly))] type NoReturn = ();
|
|
|
|
|
(Option::<NoReturn>::None, do_work(process.as_ref(), &filename, ()).await)
|
|
|
|
|
(Option::<NoReturn>::None, do_work(&process, &filename, ()).await)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
@ -160,6 +194,13 @@ where I: IntoIterator<Item=T>,
|
|
|
|
|
match worker.1 {
|
|
|
|
|
Ok(strings) => tx.send((filename, strings, i)).await.map_err(|_| "Child panic").unwrap(),
|
|
|
|
|
Err(error) => {
|
|
|
|
|
#[cfg(feature="collect_err")] let error = {
|
|
|
|
|
let Error{internal, stack} = error;
|
|
|
|
|
|
|
|
|
|
tx.send((filename.clone(), stack.into_iter(), i)).await.map_err(|_| "Child panic").unwrap();
|
|
|
|
|
|
|
|
|
|
internal
|
|
|
|
|
};
|
|
|
|
|
#[cfg(not(feature="progress"))] eprintln!("[{}] {:?}: {}", colour::style(colour!(Color::Yellow),"!"), filename.as_ref(), colour::style(colour!(Color::Yellow), error));
|
|
|
|
|
#[cfg(feature="progress")] let _ = progress.eprintln(format!("[{}] ({}) {:?}: {}", colour::style(colour!(Color::Yellow),"!"),i, filename.as_ref(), colour::style(colour!(Color::Yellow), error))).await
|
|
|
|
|
.or_else(|e| {
|
|
|
|
@ -200,7 +241,7 @@ where I: IntoIterator<Item=T>,
|
|
|
|
|
{
|
|
|
|
|
#[cfg(feature="progress")] progress.eprintln(format!("[e] Child panic {:?}", failed)).await?.await?;
|
|
|
|
|
#[cfg(not(feature="progress"))] eprintln!("[e] Child panic {:?}", failed);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
drop(tx);
|
|
|
|
|
display.await?;
|
|
|
|
|