Skip to content

Commit 2071040

Browse files
committed
limit tidy parallelism by taking -j into account
1 parent 77d1185 commit 2071040

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/bootstrap/test.rs

+1
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ impl Step for Tidy {
782782
cmd.arg(&builder.src);
783783
cmd.arg(&builder.initial_cargo);
784784
cmd.arg(&builder.out);
785+
cmd.arg(builder.jobs().to_string());
785786
if builder.is_verbose() {
786787
cmd.arg("--verbose");
787788
}

src/tools/tidy/src/main.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,23 @@
66
77
use tidy::*;
88

9-
use crossbeam_utils::thread::scope;
9+
use crossbeam_utils::thread::{scope, ScopedJoinHandle};
10+
use std::collections::VecDeque;
1011
use std::env;
12+
use std::num::NonZeroUsize;
1113
use std::path::PathBuf;
1214
use std::process;
15+
use std::str::FromStr;
1316
use std::sync::atomic::{AtomicBool, Ordering};
1417

1518
fn main() {
1619
let root_path: PathBuf = env::args_os().nth(1).expect("need path to root of repo").into();
1720
let cargo: PathBuf = env::args_os().nth(2).expect("need path to cargo").into();
1821
let output_directory: PathBuf =
1922
env::args_os().nth(3).expect("need path to output directory").into();
23+
let concurrency: NonZeroUsize =
24+
FromStr::from_str(&env::args().nth(4).expect("need concurrency"))
25+
.expect("concurrency must be a number");
2026

2127
let src_path = root_path.join("src");
2228
let library_path = root_path.join("library");
@@ -29,15 +35,23 @@ fn main() {
2935
let bad = std::sync::Arc::new(AtomicBool::new(false));
3036

3137
scope(|s| {
38+
let mut handles: VecDeque<ScopedJoinHandle<'_, ()>> =
39+
VecDeque::with_capacity(concurrency.get());
40+
3241
macro_rules! check {
3342
($p:ident $(, $args:expr)* ) => {
34-
s.spawn(|_| {
43+
while handles.len() >= concurrency.get() {
44+
handles.pop_front().unwrap().join().unwrap();
45+
}
46+
47+
let handle = s.spawn(|_| {
3548
let mut flag = false;
3649
$p::check($($args),* , &mut flag);
3750
if (flag) {
3851
bad.store(true, Ordering::Relaxed);
3952
}
4053
});
54+
handles.push_back(handle);
4155
}
4256
}
4357

@@ -74,6 +88,9 @@ fn main() {
7488
check!(edition, &library_path);
7589

7690
let collected = {
91+
while handles.len() >= concurrency.get() {
92+
handles.pop_front().unwrap().join().unwrap();
93+
}
7794
let mut flag = false;
7895
let r = features::check(&src_path, &compiler_path, &library_path, &mut flag, verbose);
7996
if flag {

0 commit comments

Comments
 (0)