Skip to content

Commit

Permalink
Addressed comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytm committed Jun 28, 2018
1 parent 3dbe701 commit a753b50
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
18 changes: 10 additions & 8 deletions src/cargo/core/compiler/job_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use core::{PackageId, Target};
use handle_error;
use util::{internal, profile, CargoResult, CargoResultExt, ProcessBuilder};
use util::{Config, DependencyQueue, Dirty, Fresh, Freshness};
use util::Progress;
use util::{Progress, ProgressStyle};

use super::job::Job;
use super::{BuildContext, BuildPlan, CompileMode, Context, Kind, Unit};
Expand All @@ -29,7 +29,7 @@ pub struct JobQueue<'a> {
queue: DependencyQueue<Key<'a>, Vec<(Job, Freshness)>>,
tx: Sender<Message<'a>>,
rx: Receiver<Message<'a>>,
active: HashSet<Key<'a>>,
active: Vec<Key<'a>>,
pending: HashMap<Key<'a>, PendingBuild>,
compiled: HashSet<&'a PackageId>,
documented: HashSet<&'a PackageId>,
Expand Down Expand Up @@ -99,7 +99,7 @@ impl<'a> JobQueue<'a> {
queue: DependencyQueue::new(),
tx,
rx,
active: HashSet::new(),
active: Vec::new(),
pending: HashMap::new(),
compiled: HashSet::new(),
documented: HashSet::new(),
Expand Down Expand Up @@ -181,7 +181,7 @@ impl<'a> JobQueue<'a> {
// successful and otherwise wait for pending work to finish if it failed
// and then immediately return.
let mut error = None;
let mut progress = Progress::new("Building", cx.bcx.config);
let mut progress = Progress::with_style("Building", ProgressStyle::Ratio, cx.bcx.config);
let queue_len = self.queue.len();
loop {
// Dequeue as much work as we can, learning about everything
Expand Down Expand Up @@ -227,11 +227,10 @@ impl<'a> JobQueue<'a> {
tokens.truncate(self.active.len() - 1);

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

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

self.active.insert(key);
self.active.push(key);
*self.counts.get_mut(key.pkg).unwrap() -= 1;

let my_tx = self.tx.clone();
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub use self::to_semver::ToSemver;
pub use self::to_url::ToUrl;
pub use self::vcs::{FossilRepo, GitRepo, HgRepo, PijulRepo};
pub use self::read2::read2;
pub use self::progress::Progress;
pub use self::progress::{Progress, ProgressStyle};

pub mod config;
pub mod errors;
Expand Down
18 changes: 16 additions & 2 deletions src/cargo/util/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ pub struct Progress<'cfg> {
state: Option<State<'cfg>>,
}

pub enum ProgressStyle {
Percentage,
Ratio,
}

struct State<'cfg> {
config: &'cfg Config,
style: ProgressStyle,
max_width: usize,
width: usize,
first: bool,
Expand All @@ -20,7 +26,7 @@ struct State<'cfg> {
}

impl<'cfg> Progress<'cfg> {
pub fn new(name: &str, cfg: &'cfg Config) -> Progress<'cfg> {
pub fn with_style(name: &str, style: ProgressStyle, cfg: &'cfg Config) -> Progress<'cfg> {
// report no progress when -q (for quiet) or TERM=dumb are set
let dumb = match env::var("TERM") {
Ok(term) => term == "dumb",
Expand All @@ -33,6 +39,7 @@ impl<'cfg> Progress<'cfg> {
Progress {
state: cfg.shell().err_width().map(|n| State {
config: cfg,
style,
max_width: n,
width: cmp::min(n, 80),
first: true,
Expand All @@ -43,6 +50,10 @@ impl<'cfg> Progress<'cfg> {
}
}

pub fn new(name: &str, cfg: &'cfg Config) -> Progress<'cfg> {
Self::with_style(name, ProgressStyle::Percentage, cfg)
}

pub fn tick(&mut self, cur: usize, max: usize) -> CargoResult<()> {
match self.state {
Some(ref mut s) => s.tick(cur, max, String::new(), true),
Expand Down Expand Up @@ -102,7 +113,10 @@ impl<'cfg> State<'cfg> {
// progress bar is
let pct = (cur as f64) / (max as f64);
let pct = if !pct.is_finite() { 0.0 } else { pct };
let stats = format!(" {:6.02}%", pct * 100.0);
let stats = match self.style {
ProgressStyle::Percentage => format!(" {:6.02}%", pct * 100.0),
ProgressStyle::Ratio => format!(" {}/{}", cur, max),
};
let extra_len = stats.len() + 2 /* [ and ] */ + 15 /* status header */;
let display_width = match self.width.checked_sub(extra_len) {
Some(n) => n,
Expand Down

0 comments on commit a753b50

Please sign in to comment.