From dc6d219d8f05e1c4369f28b388a3c97cbdb84351 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sat, 25 Jan 2020 14:20:40 -0500 Subject: [PATCH] Store maximum queue length Previously, the queue length was constantly decreasing as we built crates, which meant that we were incorrectly displaying the progress bar. In debug builds, this even led to panics (due to underflow on subtraction). --- src/cargo/core/compiler/job_queue.rs | 6 +++++- src/cargo/util/progress.rs | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cargo/core/compiler/job_queue.rs b/src/cargo/core/compiler/job_queue.rs index fd86611bcc5..55832cb906a 100644 --- a/src/cargo/core/compiler/job_queue.rs +++ b/src/cargo/core/compiler/job_queue.rs @@ -95,6 +95,9 @@ pub struct JobQueue<'a, 'cfg> { /// It is created from JobQueue when we have fully assembled the crate graph /// (i.e., all package dependencies are known). struct DrainState<'a, 'cfg> { + // This is the length of the DependencyQueue when starting out + total_units: usize, + queue: DependencyQueue, Artifact, Job>, tx: Sender, rx: Receiver, @@ -341,6 +344,7 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> { let (tx, rx) = channel(); let progress = Progress::with_style("Building", ProgressStyle::Ratio, cx.bcx.config); let state = DrainState { + total_units: self.queue.len(), queue: self.queue, tx, rx, @@ -713,7 +717,7 @@ impl<'a, 'cfg> DrainState<'a, 'cfg> { .collect::>(); drop(self.progress.tick_now( self.finished, - self.queue.len(), + self.total_units, &format!(": {}", active_names.join(", ")), )); } diff --git a/src/cargo/util/progress.rs b/src/cargo/util/progress.rs index 05715e4fe32..d62600379cb 100644 --- a/src/cargo/util/progress.rs +++ b/src/cargo/util/progress.rs @@ -224,6 +224,7 @@ impl<'cfg> State<'cfg> { impl Format { fn progress(&self, cur: usize, max: usize) -> Option { + assert!(cur <= max); // Render the percentage at the far right and then figure how long the // progress bar is let pct = (cur as f64) / (max as f64);