Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Displays a one line progress of what crates are currently built. #5620

Merged
merged 3 commits into from
Jun 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ termcolor = "0.3"
toml = "0.4.2"
url = "1.1"
clap = "2.31.2"
unicode-width = "0.1.5"

# Not actually needed right now but required to make sure that rls/cargo build
# with the same set of features in rust-lang/rust
Expand Down
44 changes: 32 additions & 12 deletions src/cargo/core/compiler/job_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +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, ProgressStyle};

use super::job::Job;
use super::{BuildContext, BuildPlan, CompileMode, Context, Kind, Unit};
Expand All @@ -28,7 +29,7 @@ pub struct JobQueue<'a> {
queue: DependencyQueue<Key<'a>, Vec<(Job, Freshness)>>,
tx: Sender<Message<'a>>,
rx: Receiver<Message<'a>>,
active: usize,
active: Vec<Key<'a>>,
pending: HashMap<Key<'a>, PendingBuild>,
compiled: HashSet<&'a PackageId>,
documented: HashSet<&'a PackageId>,
Expand Down Expand Up @@ -98,7 +99,7 @@ impl<'a> JobQueue<'a> {
queue: DependencyQueue::new(),
tx,
rx,
active: 0,
active: Vec::new(),
pending: HashMap::new(),
compiled: HashSet::new(),
documented: HashSet::new(),
Expand Down Expand Up @@ -180,6 +181,8 @@ 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::with_style("Building", ProgressStyle::Ratio, cx.bcx.config);
let total = self.queue.len();
loop {
// Dequeue as much work as we can, learning about everything
// possible that can run. Note that this is also the point where we
Expand All @@ -196,7 +199,7 @@ impl<'a> JobQueue<'a> {
);
for (job, f) in jobs {
queue.push((key, job, f.combine(fresh)));
if self.active + queue.len() > 0 {
if !self.active.is_empty() || !queue.is_empty() {
jobserver_helper.request_token();
}
}
Expand All @@ -205,14 +208,14 @@ impl<'a> JobQueue<'a> {
// Now that we've learned of all possible work that we can execute
// try to spawn it so long as we've got a jobserver token which says
// we're able to perform some parallel work.
while error.is_none() && self.active < tokens.len() + 1 && !queue.is_empty() {
while error.is_none() && self.active.len() < tokens.len() + 1 && !queue.is_empty() {
let (key, job, fresh) = queue.remove(0);
self.run(key, fresh, job, cx.bcx.config, scope, build_plan)?;
}

// If after all that we're not actually running anything then we're
// done!
if self.active == 0 {
if self.active.is_empty() {
break;
}

Expand All @@ -221,9 +224,18 @@ impl<'a> JobQueue<'a> {
// jobserver interface is architected we may acquire a token that we
// don't actually use, and if this happens just relinquish it back
// to the jobserver itself.
tokens.truncate(self.active - 1);

match self.rx.recv().unwrap() {
tokens.truncate(self.active.len() - 1);

let count = total - self.queue.len();
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<_>>();
drop(progress.tick_now(count, total, &format!(": {}", active_names.join(", "))));
let event = self.rx.recv().unwrap();
progress.clear();

match event {
Message::Run(cmd) => {
cx.bcx
.config
Expand All @@ -245,8 +257,15 @@ impl<'a> JobQueue<'a> {
}
Message::Finish(key, result) => {
info!("end: {:?}", key);
self.active -= 1;
if self.active > 0 {

// self.active.remove_item(&key); // <- switch to this when stabilized.
let pos = self
.active
.iter()
.position(|k| *k == key)
.expect("an unrecorded package has finished compiling");
self.active.remove(pos);
if !self.active.is_empty() {
assert!(!tokens.is_empty());
drop(tokens.pop());
}
Expand All @@ -256,7 +275,7 @@ impl<'a> JobQueue<'a> {
let msg = "The following warnings were emitted during compilation:";
self.emit_warnings(Some(msg), &key, cx)?;

if self.active > 0 {
if !self.active.is_empty() {
error = Some(format_err!("build failed"));
handle_error(e, &mut *cx.bcx.config.shell());
cx.bcx.config.shell().warn(
Expand All @@ -274,6 +293,7 @@ impl<'a> JobQueue<'a> {
}
}
}
drop(progress);

let build_type = if self.is_release { "release" } else { "dev" };
// NOTE: This may be a bit inaccurate, since this may not display the
Expand Down Expand Up @@ -334,7 +354,7 @@ impl<'a> JobQueue<'a> {
) -> CargoResult<()> {
info!("start: {:?}", key);

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

let my_tx = self.tx.clone();
Expand Down
1 change: 1 addition & 0 deletions src/cargo/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ extern crate tar;
extern crate tempfile;
extern crate termcolor;
extern crate toml;
extern crate unicode_width;
extern crate url;

use std::fmt;
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
Loading