Skip to content

Commit 4974734

Browse files
committed
lintcheck: show progress percentage in the "Linting..." message
1 parent d198551 commit 4974734

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

clippy_dev/src/lintcheck.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,17 @@ impl Crate {
222222
cargo_clippy_path: &PathBuf,
223223
target_dir_index: &AtomicUsize,
224224
thread_limit: usize,
225+
total_crates_to_lint: usize,
225226
) -> Vec<ClippyWarning> {
226227
// advance the atomic index by one
227-
let idx = target_dir_index.fetch_add(1, Ordering::SeqCst);
228+
let index = target_dir_index.fetch_add(1, Ordering::SeqCst);
228229
// "loop" the index within 0..thread_limit
229-
let idx = idx % thread_limit;
230-
println!("Linting {} {} in target dir {:?}", &self.name, &self.version, idx);
230+
let target_dir_index = index % thread_limit;
231+
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+
);
231236
let cargo_clippy_path = std::fs::canonicalize(cargo_clippy_path).unwrap();
232237

233238
let shared_target_dir = clippy_project_root().join("target/lintcheck/shared_target_dir");
@@ -244,7 +249,10 @@ impl Crate {
244249

245250
let all_output = std::process::Command::new(&cargo_clippy_path)
246251
// use the looping index to create individual target dirs
247-
.env("CARGO_TARGET_DIR", shared_target_dir.join(format!("_{:?}", idx)))
252+
.env(
253+
"CARGO_TARGET_DIR",
254+
shared_target_dir.join(format!("_{:?}", target_dir_index)),
255+
)
248256
// lint warnings will look like this:
249257
// src/cargo/ops/cargo_compile.rs:127:35: warning: usage of `FromIterator::from_iter`
250258
.args(&args)
@@ -466,7 +474,7 @@ pub fn run(clap_config: &ArgMatches) {
466474
.into_iter()
467475
.map(|krate| krate.download_and_extract())
468476
.filter(|krate| krate.name == only_one_crate)
469-
.map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &AtomicUsize::new(0), 1))
477+
.map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &AtomicUsize::new(0), 1, 1))
470478
.flatten()
471479
.collect()
472480
} else {
@@ -484,11 +492,13 @@ pub fn run(clap_config: &ArgMatches) {
484492
// Rayon seems to return thread count so half that for core count
485493
let num_cpus: usize = rayon::current_num_threads() / 2;
486494

495+
let num_crates = crates.len();
496+
487497
// check all crates (default)
488498
crates
489499
.into_par_iter()
490500
.map(|krate| krate.download_and_extract())
491-
.map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &counter, num_cpus))
501+
.map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &counter, num_cpus, num_crates))
492502
.flatten()
493503
.collect()
494504
};

lintcheck-logs/lintcheck_crates_logs.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
clippy 0.1.52 (2f815ecd0 2021-02-18)
1+
clippy 0.1.52 (bb5f9d18a 2021-02-19)
22

33
cargo-0.49.0/build.rs:1:null clippy::cargo_common_metadata "package `cargo` is missing `package.categories` metadata"
44
cargo-0.49.0/build.rs:1:null clippy::cargo_common_metadata "package `cargo` is missing `package.keywords` metadata"

0 commit comments

Comments
 (0)