Skip to content

Commit 50032b9

Browse files
committed
Auto merge of #5828 - kennytm:compile-progress-names, r=alexcrichton
-Zcompile-progress: Use the target name in the progress bar when building a test/binary. Thus fixes hilarious output like https://twitter.com/ManishEarth/status/1015479576670027776. New output: https://asciinema.org/a/F1rkCk0bTWKQMr1NEScia3IYx
2 parents db48c63 + a40a5c7 commit 50032b9

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/cargo/core/compiler/job_queue.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crossbeam_utils::thread::Scope;
1111
use jobserver::{Acquired, HelperThread};
1212

1313
use core::profiles::Profile;
14-
use core::{PackageId, Target};
14+
use core::{PackageId, Target, TargetKind};
1515
use handle_error;
1616
use util::{internal, profile, CargoResult, CargoResultExt, ProcessBuilder};
1717
use util::{Config, DependencyQueue, Dirty, Fresh, Freshness};
@@ -57,6 +57,27 @@ struct Key<'a> {
5757
mode: CompileMode,
5858
}
5959

60+
impl<'a> Key<'a> {
61+
fn name_for_progress(&self) -> String {
62+
let pkg_name = self.pkg.name();
63+
match self.mode {
64+
CompileMode::Doc { .. } => format!("{}(doc)", pkg_name),
65+
CompileMode::RunCustomBuild => format!("{}(build)", pkg_name),
66+
_ => {
67+
let annotation = match self.target.kind() {
68+
TargetKind::Lib(_) => return pkg_name.to_string(),
69+
TargetKind::CustomBuild => return format!("{}(build.rs)", pkg_name),
70+
TargetKind::Bin => "bin",
71+
TargetKind::Test => "test",
72+
TargetKind::Bench => "bench",
73+
TargetKind::ExampleBin | TargetKind::ExampleLib(_) => "example",
74+
};
75+
format!("{}({})", self.target.name(), annotation)
76+
}
77+
}
78+
}
79+
}
80+
6081
pub struct JobState<'a> {
6182
tx: Sender<Message<'a>>,
6283
}
@@ -254,10 +275,9 @@ impl<'a> JobQueue<'a> {
254275

255276
if progress_maybe_changed {
256277
let count = total - self.queue.len();
257-
let active_names = self.active.iter().map(|key| match key.mode {
258-
CompileMode::Doc { .. } => format!("{}(doc)", key.pkg.name()),
259-
_ => key.pkg.name().to_string(),
260-
}).collect::<Vec<_>>();
278+
let active_names = self.active.iter()
279+
.map(Key::name_for_progress)
280+
.collect::<Vec<_>>();
261281
drop(progress.tick_now(count, total, &format!(": {}", active_names.join(", "))));
262282
}
263283
let event = self.rx.recv().unwrap();

0 commit comments

Comments
 (0)