Skip to content

Commit a356813

Browse files
committed
Auto merge of #5620 - kennytm:compile-progress, r=matklad
Displays a one line progress of what crates are currently built. cc #2536, #3448. The change is based on #3451, but uses the progress bar introduced in #4646 instead. The percentage is simply the number of crates processed ÷ total crates count, which is inaccurate but better than nothing. Output looks like: [![asciicast](https://asciinema.org/a/YTiBAz4K4vfidNTAnehtyH46l.png)](https://asciinema.org/a/YTiBAz4K4vfidNTAnehtyH46l)
2 parents 7139192 + a8081a0 commit a356813

File tree

5 files changed

+249
-41
lines changed

5 files changed

+249
-41
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ termcolor = "0.3"
5353
toml = "0.4.2"
5454
url = "1.1"
5555
clap = "2.31.2"
56+
unicode-width = "0.1.5"
5657

5758
# Not actually needed right now but required to make sure that rls/cargo build
5859
# with the same set of features in rust-lang/rust

src/cargo/core/compiler/job_queue.rs

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +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, ProgressStyle};
1718

1819
use super::job::Job;
1920
use super::{BuildContext, BuildPlan, CompileMode, Context, Kind, Unit};
@@ -28,7 +29,7 @@ pub struct JobQueue<'a> {
2829
queue: DependencyQueue<Key<'a>, Vec<(Job, Freshness)>>,
2930
tx: Sender<Message<'a>>,
3031
rx: Receiver<Message<'a>>,
31-
active: usize,
32+
active: Vec<Key<'a>>,
3233
pending: HashMap<Key<'a>, PendingBuild>,
3334
compiled: HashSet<&'a PackageId>,
3435
documented: HashSet<&'a PackageId>,
@@ -98,7 +99,7 @@ impl<'a> JobQueue<'a> {
9899
queue: DependencyQueue::new(),
99100
tx,
100101
rx,
101-
active: 0,
102+
active: Vec::new(),
102103
pending: HashMap::new(),
103104
compiled: HashSet::new(),
104105
documented: HashSet::new(),
@@ -180,6 +181,8 @@ impl<'a> JobQueue<'a> {
180181
// successful and otherwise wait for pending work to finish if it failed
181182
// and then immediately return.
182183
let mut error = None;
184+
let mut progress = Progress::with_style("Building", ProgressStyle::Ratio, cx.bcx.config);
185+
let total = self.queue.len();
183186
loop {
184187
// Dequeue as much work as we can, learning about everything
185188
// possible that can run. Note that this is also the point where we
@@ -196,7 +199,7 @@ impl<'a> JobQueue<'a> {
196199
);
197200
for (job, f) in jobs {
198201
queue.push((key, job, f.combine(fresh)));
199-
if self.active + queue.len() > 0 {
202+
if !self.active.is_empty() || !queue.is_empty() {
200203
jobserver_helper.request_token();
201204
}
202205
}
@@ -205,14 +208,14 @@ impl<'a> JobQueue<'a> {
205208
// Now that we've learned of all possible work that we can execute
206209
// try to spawn it so long as we've got a jobserver token which says
207210
// we're able to perform some parallel work.
208-
while error.is_none() && self.active < tokens.len() + 1 && !queue.is_empty() {
211+
while error.is_none() && self.active.len() < tokens.len() + 1 && !queue.is_empty() {
209212
let (key, job, fresh) = queue.remove(0);
210213
self.run(key, fresh, job, cx.bcx.config, scope, build_plan)?;
211214
}
212215

213216
// If after all that we're not actually running anything then we're
214217
// done!
215-
if self.active == 0 {
218+
if self.active.is_empty() {
216219
break;
217220
}
218221

@@ -221,9 +224,18 @@ impl<'a> JobQueue<'a> {
221224
// jobserver interface is architected we may acquire a token that we
222225
// don't actually use, and if this happens just relinquish it back
223226
// to the jobserver itself.
224-
tokens.truncate(self.active - 1);
225-
226-
match self.rx.recv().unwrap() {
227+
tokens.truncate(self.active.len() - 1);
228+
229+
let count = total - self.queue.len();
230+
let active_names = self.active.iter().map(|key| match key.mode {
231+
CompileMode::Doc { .. } => format!("{}(doc)", key.pkg.name()),
232+
_ => key.pkg.name().to_string(),
233+
}).collect::<Vec<_>>();
234+
drop(progress.tick_now(count, total, &format!(": {}", active_names.join(", "))));
235+
let event = self.rx.recv().unwrap();
236+
progress.clear();
237+
238+
match event {
227239
Message::Run(cmd) => {
228240
cx.bcx
229241
.config
@@ -245,8 +257,15 @@ impl<'a> JobQueue<'a> {
245257
}
246258
Message::Finish(key, result) => {
247259
info!("end: {:?}", key);
248-
self.active -= 1;
249-
if self.active > 0 {
260+
261+
// self.active.remove_item(&key); // <- switch to this when stabilized.
262+
let pos = self
263+
.active
264+
.iter()
265+
.position(|k| *k == key)
266+
.expect("an unrecorded package has finished compiling");
267+
self.active.remove(pos);
268+
if !self.active.is_empty() {
250269
assert!(!tokens.is_empty());
251270
drop(tokens.pop());
252271
}
@@ -256,7 +275,7 @@ impl<'a> JobQueue<'a> {
256275
let msg = "The following warnings were emitted during compilation:";
257276
self.emit_warnings(Some(msg), &key, cx)?;
258277

259-
if self.active > 0 {
278+
if !self.active.is_empty() {
260279
error = Some(format_err!("build failed"));
261280
handle_error(e, &mut *cx.bcx.config.shell());
262281
cx.bcx.config.shell().warn(
@@ -274,6 +293,7 @@ impl<'a> JobQueue<'a> {
274293
}
275294
}
276295
}
296+
drop(progress);
277297

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

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

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

src/cargo/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ extern crate tar;
4444
extern crate tempfile;
4545
extern crate termcolor;
4646
extern crate toml;
47+
extern crate unicode_width;
4748
extern crate url;
4849

4950
use std::fmt;

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;

0 commit comments

Comments
 (0)