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).
This commit is contained in:
Mark Rousskov 2020-01-25 14:20:40 -05:00
parent b68b0978ab
commit dc6d219d8f
2 changed files with 6 additions and 1 deletions

View File

@ -95,6 +95,9 @@ pub struct JobQueue<'a, 'cfg> {
/// It is created from JobQueue when we have fully assembled the crate graph /// It is created from JobQueue when we have fully assembled the crate graph
/// (i.e., all package dependencies are known). /// (i.e., all package dependencies are known).
struct DrainState<'a, 'cfg> { struct DrainState<'a, 'cfg> {
// This is the length of the DependencyQueue when starting out
total_units: usize,
queue: DependencyQueue<Unit<'a>, Artifact, Job>, queue: DependencyQueue<Unit<'a>, Artifact, Job>,
tx: Sender<Message>, tx: Sender<Message>,
rx: Receiver<Message>, rx: Receiver<Message>,
@ -341,6 +344,7 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
let (tx, rx) = channel(); let (tx, rx) = channel();
let progress = Progress::with_style("Building", ProgressStyle::Ratio, cx.bcx.config); let progress = Progress::with_style("Building", ProgressStyle::Ratio, cx.bcx.config);
let state = DrainState { let state = DrainState {
total_units: self.queue.len(),
queue: self.queue, queue: self.queue,
tx, tx,
rx, rx,
@ -713,7 +717,7 @@ impl<'a, 'cfg> DrainState<'a, 'cfg> {
.collect::<Vec<_>>(); .collect::<Vec<_>>();
drop(self.progress.tick_now( drop(self.progress.tick_now(
self.finished, self.finished,
self.queue.len(), self.total_units,
&format!(": {}", active_names.join(", ")), &format!(": {}", active_names.join(", ")),
)); ));
} }

View File

@ -224,6 +224,7 @@ impl<'cfg> State<'cfg> {
impl Format { impl Format {
fn progress(&self, cur: usize, max: usize) -> Option<String> { fn progress(&self, cur: usize, max: usize) -> Option<String> {
assert!(cur <= max);
// Render the percentage at the far right and then figure how long the // Render the percentage at the far right and then figure how long the
// progress bar is // progress bar is
let pct = (cur as f64) / (max as f64); let pct = (cur as f64) / (max as f64);