Skip to content

lintcheck: use multithreading unless --fix or --recursive is used #10458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions lintcheck/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
use clap::Parser;
use std::path::PathBuf;
use std::{num::NonZeroUsize, path::PathBuf};

#[derive(Clone, Debug, Parser)]
pub(crate) struct LintcheckConfig {
/// Number of threads to use, 0 automatic choice
#[clap(long = "jobs", short = 'j', value_name = "N", default_value_t = 1)]
/// Number of threads to use (default: all unless --fix or --recursive)
#[clap(
long = "jobs",
short = 'j',
value_name = "N",
default_value_t = 0,
hide_default_value = true
)]
pub max_jobs: usize,
/// Set the path for a crates.toml where lintcheck should read the sources from
#[clap(
Expand Down Expand Up @@ -51,8 +57,11 @@ impl LintcheckConfig {

// look at the --threads arg, if 0 is passed, use the threads count
if config.max_jobs == 0 {
// automatic choice
config.max_jobs = std::thread::available_parallelism().map_or(1, |n| n.get());
config.max_jobs = if config.fix || config.recursive {
1
} else {
std::thread::available_parallelism().map_or(1, NonZeroUsize::get)
};
};

for lint_name in &mut config.lint_filter {
Expand Down