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

Conversation

kennytm
Copy link
Member

@kennytm kennytm commented Jun 8, 2018

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

r? @matklad

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

Copy link
Member

@alexcrichton alexcrichton left a comment

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?

CompileMode::Doc { .. } => format!("{}(doc)", key.pkg.name()),
_ => key.pkg.name().to_string(),
}).collect::<Vec<_>>();
active_names.sort_unstable();
Copy link
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
Copy link
Member Author

kennytm commented Jun 28, 2018

@alexcrichton
Copy link
Member

Looks perfect to me!

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

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
Member

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
Member Author

Choose a reason for hiding this comment

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

Will do :)


// Render the percentage at the far right and then figure how long the
// 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),
Copy link
Member

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
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.

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
Member

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
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.

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

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

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
Copy link
Member

matklad commented Jun 29, 2018

@bors r+

Awesome tests!

@bors
Copy link
Contributor

bors commented Jun 29, 2018

📌 Commit a8081a0 has been approved by matklad

@bors
Copy link
Contributor

bors commented Jun 29, 2018

⌛ 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
Copy link
Contributor

bors commented Jun 29, 2018

☀️ 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