Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 4de9136

Browse files
committed
Guess package name in progress when reusing build plan
1 parent 3a39ba3 commit 4de9136

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/build/plan.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,15 @@ impl PackageMap {
471471
#[derive(Debug)]
472472
crate struct JobQueue(Vec<ProcessBuilder>);
473473

474+
fn proc_arg<T: AsRef<OsStr>>(prc: &ProcessBuilder, key: T) -> Option<&std::ffi::OsStr> {
475+
let args = prc.get_args();
476+
args.iter().enumerate()
477+
.find(|(_, arg)| arg.as_os_str() == key.as_ref())
478+
.map(|(idx, _)| idx + 1)
479+
.and_then(|idx| args.get(idx))
480+
.map(|x| x.as_os_str())
481+
}
482+
474483
impl JobQueue {
475484
crate fn dequeue(&mut self) -> Option<ProcessBuilder> {
476485
self.0.pop()
@@ -514,16 +523,19 @@ impl JobQueue {
514523
.expect("cannot stringify job program");
515524
args.insert(0, program.clone());
516525

517-
// Send a window/progress notification. At this point we know the percentage
518-
// started out of the entire cached build.
519-
// FIXME. We could communicate the "program" being built here, but
520-
// it seems window/progress notification should have message OR percentage.
526+
// Send a window/progress notification.
521527
{
522-
// divide by zero is avoided by earlier assert!
523-
let percentage = compiler_messages.len() as f64 / self.0.len() as f64;
524-
progress_sender
525-
.send(ProgressUpdate::Percentage(percentage))
526-
.expect("Failed to send progress update");
528+
let crate_name = proc_arg(&job, "--crate-name").and_then(|x| x.to_str());
529+
let update = match crate_name {
530+
Some(name) => ProgressUpdate::Message(name.to_owned()),
531+
None => {
532+
// divide by zero is avoided by earlier assert!
533+
let percentage = compiler_messages.len() as f64 / self.0.len() as f64;
534+
ProgressUpdate::Percentage(percentage)
535+
}
536+
};
537+
538+
progress_sender.send(update).expect("Failed to send progress update");
527539
}
528540

529541
match super::rustc::rustc(

0 commit comments

Comments
 (0)