Skip to content

Commit a753b50

Browse files
committed
Addressed comments.
1 parent 3dbe701 commit a753b50

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

src/cargo/core/compiler/job_queue.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use core::{PackageId, Target};
1414
use handle_error;
1515
use util::{internal, profile, CargoResult, CargoResultExt, ProcessBuilder};
1616
use util::{Config, DependencyQueue, Dirty, Fresh, Freshness};
17-
use util::Progress;
17+
use util::{Progress, ProgressStyle};
1818

1919
use super::job::Job;
2020
use super::{BuildContext, BuildPlan, CompileMode, Context, Kind, Unit};
@@ -29,7 +29,7 @@ pub struct JobQueue<'a> {
2929
queue: DependencyQueue<Key<'a>, Vec<(Job, Freshness)>>,
3030
tx: Sender<Message<'a>>,
3131
rx: Receiver<Message<'a>>,
32-
active: HashSet<Key<'a>>,
32+
active: Vec<Key<'a>>,
3333
pending: HashMap<Key<'a>, PendingBuild>,
3434
compiled: HashSet<&'a PackageId>,
3535
documented: HashSet<&'a PackageId>,
@@ -99,7 +99,7 @@ impl<'a> JobQueue<'a> {
9999
queue: DependencyQueue::new(),
100100
tx,
101101
rx,
102-
active: HashSet::new(),
102+
active: Vec::new(),
103103
pending: HashMap::new(),
104104
compiled: HashSet::new(),
105105
documented: HashSet::new(),
@@ -181,7 +181,7 @@ impl<'a> JobQueue<'a> {
181181
// successful and otherwise wait for pending work to finish if it failed
182182
// and then immediately return.
183183
let mut error = None;
184-
let mut progress = Progress::new("Building", cx.bcx.config);
184+
let mut progress = Progress::with_style("Building", ProgressStyle::Ratio, cx.bcx.config);
185185
let queue_len = self.queue.len();
186186
loop {
187187
// Dequeue as much work as we can, learning about everything
@@ -227,11 +227,10 @@ impl<'a> JobQueue<'a> {
227227
tokens.truncate(self.active.len() - 1);
228228

229229
let count = queue_len - self.queue.len();
230-
let mut active_names = self.active.iter().map(|key| match key.mode {
230+
let active_names = self.active.iter().map(|key| match key.mode {
231231
CompileMode::Doc { .. } => format!("{}(doc)", key.pkg.name()),
232232
_ => key.pkg.name().to_string(),
233233
}).collect::<Vec<_>>();
234-
active_names.sort_unstable();
235234
drop(progress.tick_now(count, queue_len, format!(": {}", active_names.join(", "))));
236235
let event = self.rx.recv().unwrap();
237236
progress.clear();
@@ -259,7 +258,10 @@ impl<'a> JobQueue<'a> {
259258
Message::Finish(key, result) => {
260259
info!("end: {:?}", key);
261260

262-
self.active.remove(&key);
261+
// self.active.remove_item(&key); // <- switch to this when stabilized.
262+
if let Some(pos) = self.active.iter().position(|k| *k == key) {
263+
self.active.remove(pos);
264+
}
263265
if !self.active.is_empty() {
264266
assert!(!tokens.is_empty());
265267
drop(tokens.pop());
@@ -349,7 +351,7 @@ impl<'a> JobQueue<'a> {
349351
) -> CargoResult<()> {
350352
info!("start: {:?}", key);
351353

352-
self.active.insert(key);
354+
self.active.push(key);
353355
*self.counts.get_mut(key.pkg).unwrap() -= 1;
354356

355357
let my_tx = self.tx.clone();

src/cargo/util/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub use self::to_semver::ToSemver;
1717
pub use self::to_url::ToUrl;
1818
pub use self::vcs::{FossilRepo, GitRepo, HgRepo, PijulRepo};
1919
pub use self::read2::read2;
20-
pub use self::progress::Progress;
20+
pub use self::progress::{Progress, ProgressStyle};
2121

2222
pub mod config;
2323
pub mod errors;

src/cargo/util/progress.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ pub struct Progress<'cfg> {
99
state: Option<State<'cfg>>,
1010
}
1111

12+
pub enum ProgressStyle {
13+
Percentage,
14+
Ratio,
15+
}
16+
1217
struct State<'cfg> {
1318
config: &'cfg Config,
19+
style: ProgressStyle,
1420
max_width: usize,
1521
width: usize,
1622
first: bool,
@@ -20,7 +26,7 @@ struct State<'cfg> {
2026
}
2127

2228
impl<'cfg> Progress<'cfg> {
23-
pub fn new(name: &str, cfg: &'cfg Config) -> Progress<'cfg> {
29+
pub fn with_style(name: &str, style: ProgressStyle, cfg: &'cfg Config) -> Progress<'cfg> {
2430
// report no progress when -q (for quiet) or TERM=dumb are set
2531
let dumb = match env::var("TERM") {
2632
Ok(term) => term == "dumb",
@@ -33,6 +39,7 @@ impl<'cfg> Progress<'cfg> {
3339
Progress {
3440
state: cfg.shell().err_width().map(|n| State {
3541
config: cfg,
42+
style,
3643
max_width: n,
3744
width: cmp::min(n, 80),
3845
first: true,
@@ -43,6 +50,10 @@ impl<'cfg> Progress<'cfg> {
4350
}
4451
}
4552

53+
pub fn new(name: &str, cfg: &'cfg Config) -> Progress<'cfg> {
54+
Self::with_style(name, ProgressStyle::Percentage, cfg)
55+
}
56+
4657
pub fn tick(&mut self, cur: usize, max: usize) -> CargoResult<()> {
4758
match self.state {
4859
Some(ref mut s) => s.tick(cur, max, String::new(), true),
@@ -102,7 +113,10 @@ impl<'cfg> State<'cfg> {
102113
// progress bar is
103114
let pct = (cur as f64) / (max as f64);
104115
let pct = if !pct.is_finite() { 0.0 } else { pct };
105-
let stats = format!(" {:6.02}%", pct * 100.0);
116+
let stats = match self.style {
117+
ProgressStyle::Percentage => format!(" {:6.02}%", pct * 100.0),
118+
ProgressStyle::Ratio => format!(" {}/{}", cur, max),
119+
};
106120
let extra_len = stats.len() + 2 /* [ and ] */ + 15 /* status header */;
107121
let display_width = match self.width.checked_sub(extra_len) {
108122
Some(n) => n,

0 commit comments

Comments
 (0)