Skip to content

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

Merged
bors merged 3 commits into
rust-lang:masterfrom
kennytm:compile-progress
Jun 29, 2018
Merged

Displays a one line progress of what crates are currently built.#5620
bors merged 3 commits into
rust-lang:masterfrom
kennytm:compile-progress

Conversation

@kennytm

@kennytm kennytm commented Jun 8, 2018

Copy link
Copy Markdown
Member

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

@rust-highfive

Copy link
Copy Markdown

r? @matklad

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton alexcrichton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty awesome, thanks so much for implementing this @kennytm! I've long wanted to make Cargo's progress indicators more user-friendly (or have them at all!)

Would it be possible to perhaps have different modes on the progress bar? Downloads I think are best done with a percentage but the number of targets being built (sort of rustc invocations?) may be best done as a discrete number like "18/25" maybe?

Comment thread src/cargo/core/compiler/job_queue.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this may actually be easier to read as a Vec perhaps? That way names don't jump around but they should always be in the same place relative to other names. Should this also perhaps use a HashSet to deduplicate when we're building multiple targets for one crate?

@kennytm kennytm force-pushed the compile-progress branch from 22133eb to a753b50 Compare June 28, 2018 21:16
@kennytm

kennytm commented Jun 28, 2018

Copy link
Copy Markdown
Member Author

@alexcrichton

Copy link
Copy Markdown
Member

Looks perfect to me!

@matklad any thoughts on this? Or shall I r+?

Comment thread src/cargo/core/compiler/job_queue.rs Outdated
if self.active > 0 {

// self.active.remove_item(&key); // <- switch to this when stabilized.
if let Some(pos) = self.active.iter().position(|k| *k == key) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if let some looks suspicious to me. It should never fail, right? If that’s the case, let’s replace it with expect? If we later make a bug somewhere around here, expect would be much easier to debug.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do :)

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),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: let’s move pct calculation inside the match arm to minimize scope?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matklad The pct is later used to calculate the size of the progress bar, so no.

Comment thread src/cargo/util/progress.rs Outdated
if avail_msg_len >= msg.len() + 3 {
string.push_str(&msg);
} else if avail_msg_len >= 4 {
string.push_str(&msg[..(avail_msg_len - 3)]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crate names can be non-ascii:

~/tmp
λ cargo new "привет-мир"
     Created binary (application) `привет-мир` project

~/tmp
λ cd привет-мир

~/tmp/привет-мир master*
λ cargo run
   Compiling привет-мир v0.1.0 (file:///home/matklad/tmp/%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82-%D0%BC%D0%B8%D1%80)
    Finished dev [unoptimized + debuginfo] target(s) in 0.99 secs
     Running `target/debug/привет-мир`
Hello, world!

So I think this might fail at run time with utf8-boundary error :-) If we fix this, might be a good idea to write a unit-test for this formatting function as well.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thanks. Since this is a UI component we should limit by the display width, which counts by grapheme cluster and each cluster's width can be 1 or 2 spaces (half width or full width) long 💀. Since your Cargo.lock already depends on unicode-width via clap, I'll just add this dependency.

Comment thread src/cargo/core/compiler/job_queue.rs Outdated
match self.rx.recv().unwrap() {
tokens.truncate(self.active.len() - 1);

let count = queue_len - self.queue.len();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Micronit: queue.len() - queueue_len looks funny. Perhaps, rename it to total -self.que.len()?

@matklad

matklad commented Jun 29, 2018

Copy link
Copy Markdown
Contributor

@bors r+

Awesome tests!

@bors

bors commented Jun 29, 2018

Copy link
Copy Markdown
Contributor

📌 Commit a8081a0 has been approved by matklad

@bors

bors commented Jun 29, 2018

Copy link
Copy Markdown
Contributor

⌛ Testing commit a8081a0 with merge a356813...

bors added a commit that referenced this pull request Jun 29, 2018
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)
@bors

bors commented Jun 29, 2018

Copy link
Copy Markdown
Contributor

☀️ Test successful - status-appveyor, status-travis
Approved by: matklad
Pushing a356813 to master...

@bors bors merged commit a8081a0 into rust-lang:master Jun 29, 2018
@kennytm kennytm deleted the compile-progress branch June 29, 2018 19:16
@ehuss ehuss added this to the 1.29.0 milestone Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants