Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 8499a32

Browse files
committed
lintcheck: add -j <N> option to configure threads.
defaults to 1 -j 0 choses the number of threads automtically (= number of physical cores)
1 parent 22aeec0 commit 8499a32

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

clippy_dev/src/lintcheck.rs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,19 @@ impl Crate {
229229
// "loop" the index within 0..thread_limit
230230
let target_dir_index = index % thread_limit;
231231
let perc = ((index * 100) as f32 / total_crates_to_lint as f32) as u8;
232-
println!(
233-
"{}/{} {}% Linting {} {} in target dir {:?}",
234-
index, total_crates_to_lint, perc, &self.name, &self.version, target_dir_index
235-
);
232+
233+
if thread_limit == 1 {
234+
println!(
235+
"{}/{} {}% Linting {} {}",
236+
index, total_crates_to_lint, perc, &self.name, &self.version
237+
);
238+
} else {
239+
println!(
240+
"{}/{} {}% Linting {} {} in target dir {:?}",
241+
index, total_crates_to_lint, perc, &self.name, &self.version, target_dir_index
242+
);
243+
}
244+
236245
let cargo_clippy_path = std::fs::canonicalize(cargo_clippy_path).unwrap();
237246

238247
let shared_target_dir = clippy_project_root().join("target/lintcheck/shared_target_dir");
@@ -492,8 +501,23 @@ pub fn run(clap_config: &ArgMatches) {
492501
// This helps when we check many small crates with dep-trees that don't have a lot of branches in
493502
// order to achive some kind of parallelism
494503

495-
// Rayon seems to return thread count so half that for core count
496-
let num_cpus: usize = rayon::current_num_threads() / 2;
504+
// by default, use a single thread
505+
let num_cpus = match clap_config.value_of("threads") {
506+
Some(threads) => {
507+
let threads: usize = threads
508+
.parse()
509+
.expect(&format!("Failed to parse '{}' to a digit", threads));
510+
if threads == 0 {
511+
// automatic choice
512+
// Rayon seems to return thread count so half that for core count
513+
(rayon::current_num_threads() / 2) as usize
514+
} else {
515+
threads
516+
}
517+
},
518+
// no -j passed, use a single thread
519+
None => 1,
520+
};
497521

498522
let num_crates = crates.len();
499523

clippy_dev/src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ fn get_clap_config<'a>() -> ArgMatches<'a> {
6969
.value_name("CRATES-SOURCES-TOML-PATH")
7070
.long("crates-toml")
7171
.help("set the path for a crates.toml where lintcheck should read the sources from"),
72+
)
73+
.arg(
74+
Arg::with_name("threads")
75+
.takes_value(true)
76+
.value_name("N")
77+
.short("j")
78+
.long("jobs")
79+
.help("number of threads to use, 0 automatic choice"),
7280
);
7381

7482
let app = App::new("Clippy developer tooling")

0 commit comments

Comments
 (0)