From 6ce90874505539d7911ae9aff3a8f0ab0bac4b2f Mon Sep 17 00:00:00 2001 From: kennytm Date: Thu, 12 Jul 2018 11:10:00 +0800 Subject: [PATCH 1/2] Bring back the compile progress bar as an -Z option. --- src/bin/cargo/cli.rs | 1 + src/cargo/core/compiler/job_queue.rs | 4 +++- src/cargo/core/features.rs | 2 ++ src/doc/src/reference/unstable.md | 16 ++++++++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/bin/cargo/cli.rs b/src/bin/cargo/cli.rs index 41d99292368..a32e01626ed 100644 --- a/src/bin/cargo/cli.rs +++ b/src/bin/cargo/cli.rs @@ -22,6 +22,7 @@ Available unstable (nightly-only) flags: -Z offline -- Offline mode that does not perform network requests -Z unstable-options -- Allow the usage of unstable options such as --registry -Z config-profile -- Read profiles from .cargo/config files + -Z compile-progress -- Display a progress bar while compiling Run with 'cargo -Z [FLAG] [SUBCOMMAND]'" ); diff --git a/src/cargo/core/compiler/job_queue.rs b/src/cargo/core/compiler/job_queue.rs index e5b1f8eb214..5d1afa7f12f 100644 --- a/src/cargo/core/compiler/job_queue.rs +++ b/src/cargo/core/compiler/job_queue.rs @@ -195,7 +195,9 @@ impl<'a> JobQueue<'a> { // we're at it. let mut error = None; let mut progress = Progress::with_style("Building", ProgressStyle::Ratio, cx.bcx.config); - progress.disable(); + if !cx.bcx.config.cli_unstable().compile_progress { + progress.disable(); + } let total = self.queue.len(); loop { // Dequeue as much work as we can, learning about everything diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index d04f1b2ee68..fdbc7d7d4b2 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -311,6 +311,7 @@ pub struct CliUnstable { pub package_features: bool, pub advanced_env: bool, pub config_profile: bool, + pub compile_progress: bool, } impl CliUnstable { @@ -347,6 +348,7 @@ impl CliUnstable { "package-features" => self.package_features = true, "advanced-env" => self.advanced_env = true, "config-profile" => self.config_profile = true, + "compile-progress" => self.compile_progress = true, _ => bail!("unknown `-Z` flag specified: {}", k), } diff --git a/src/doc/src/reference/unstable.md b/src/doc/src/reference/unstable.md index a7345fcbc2f..c3a29869a23 100644 --- a/src/doc/src/reference/unstable.md +++ b/src/doc/src/reference/unstable.md @@ -292,3 +292,19 @@ Example: ``` cargo +nightly build --build-plan -Z unstable-options ``` + +### Compile progress +* Tracking Issue: [rust-lang/cargo#2536](https://github.com/rust-lang/cargo/issues/2536) + +The `-Z compile-progress` flag enables a progress bar while compiling. + +```console +$ cargo +nightly build -Z compile-progress + Compiling libc v0.2.41 + Compiling void v1.0.2 + Compiling lazy_static v1.0.1 + Compiling regex v1.0.0 + Compiling ucd-util v0.1.1 + Compiling utf8-ranges v1.0.0 + Building [=======> ] 2/14: libc, regex, uc... +``` From 9612be6803423c490b73b9610695884b605ca27f Mon Sep 17 00:00:00 2001 From: kennytm Date: Thu, 12 Jul 2018 11:59:35 +0800 Subject: [PATCH 2/2] Compile progress: Do not update when a build script prints something. Fix #5697. There may still be some little flickering, but should be much less severe than before. --- src/cargo/core/compiler/job_queue.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/cargo/core/compiler/job_queue.rs b/src/cargo/core/compiler/job_queue.rs index 5d1afa7f12f..98e0ca0f75e 100644 --- a/src/cargo/core/compiler/job_queue.rs +++ b/src/cargo/core/compiler/job_queue.rs @@ -190,11 +190,10 @@ impl<'a> JobQueue<'a> { // bar we'll need to probably capture the stderr of rustc and // capture compiler error messages, but that also means // reproducing rustc's styling of error messages which is - // currently a pretty big task. This is issue #5695. Note that - // when reenabling it'd also probably be good to fix #5697 while - // we're at it. + // currently a pretty big task. This is issue #5695. let mut error = None; let mut progress = Progress::with_style("Building", ProgressStyle::Ratio, cx.bcx.config); + let mut progress_maybe_changed = true; // avoid flickering due to build script if !cx.bcx.config.cli_unstable().compile_progress { progress.disable(); } @@ -242,14 +241,23 @@ impl<'a> JobQueue<'a> { // to the jobserver itself. tokens.truncate(self.active.len() - 1); - let count = total - self.queue.len(); - let active_names = self.active.iter().map(|key| match key.mode { - CompileMode::Doc { .. } => format!("{}(doc)", key.pkg.name()), - _ => key.pkg.name().to_string(), - }).collect::>(); - drop(progress.tick_now(count, total, &format!(": {}", active_names.join(", ")))); + if progress_maybe_changed { + let count = total - self.queue.len(); + let active_names = self.active.iter().map(|key| match key.mode { + CompileMode::Doc { .. } => format!("{}(doc)", key.pkg.name()), + _ => key.pkg.name().to_string(), + }).collect::>(); + drop(progress.tick_now(count, total, &format!(": {}", active_names.join(", ")))); + } let event = self.rx.recv().unwrap(); - progress.clear(); + + progress_maybe_changed = match event { + Message::Stdout(_) | Message::Stderr(_) => cx.bcx.config.extra_verbose(), + _ => true, + }; + if progress_maybe_changed { + progress.clear(); + } match event { Message::Run(cmd) => {