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

Stabilize -Zcompile-progress. #5995

Merged
merged 3 commits into from Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion src/bin/cargo/cli.rs
Expand Up @@ -34,7 +34,6 @@ 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]'"
);
Expand Down
3 changes: 0 additions & 3 deletions src/cargo/core/compiler/job_queue.rs
Expand Up @@ -237,9 +237,6 @@ impl<'a> JobQueue<'a> {
// 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);
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
Expand Down
32 changes: 11 additions & 21 deletions src/cargo/core/compiler/mod.rs
Expand Up @@ -10,11 +10,10 @@ use serde_json;

use core::manifest::TargetSourcePath;
use core::profiles::{Lto, Profile};
use core::shell::ColorChoice;
use core::{PackageId, Target};
use util::errors::{CargoResult, CargoResultExt, Internal};
use util::paths;
use util::{self, machine_message, Freshness, ProcessBuilder};
use util::{self, machine_message, Freshness, ProcessBuilder, process};
use util::{internal, join_paths, profile};

use self::build_plan::BuildPlan;
Expand Down Expand Up @@ -241,8 +240,6 @@ fn rustc<'a, 'cfg>(
.unwrap_or_else(|| cx.bcx.config.cwd())
.to_path_buf();

let should_capture_output = cx.bcx.config.cli_unstable().compile_progress;

return Ok(Work::new(move |state| {
// Only at runtime have we discovered what the extra -L and -l
// arguments are for native libraries, so we process those here. We
Expand Down Expand Up @@ -292,12 +289,7 @@ fn rustc<'a, 'cfg>(
} else if build_plan {
state.build_plan(buildkey, rustc.clone(), outputs.clone());
} else {
let exec_result = if should_capture_output {
exec.exec_and_capture_output(rustc, &package_id, &target, mode, state)
} else {
exec.exec(rustc, &package_id, &target, mode)
};
exec_result
exec.exec_and_capture_output(rustc, &package_id, &target, mode, state)
.map_err(Internal::new)
.chain_err(|| format!("Could not compile `{}`.", name))?;
}
Expand Down Expand Up @@ -591,7 +583,12 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
rustdoc.arg("--crate-name").arg(&unit.target.crate_name());
add_path_args(bcx, unit, &mut rustdoc);
add_cap_lints(bcx, unit, &mut rustdoc);
add_color(bcx, &mut rustdoc);

let mut can_add_color_process = process(&*bcx.config.rustdoc()?);
can_add_color_process.args(&["--color", "never", "-V"]);
if bcx.rustc.cached_success(&can_add_color_process)? {
add_color(bcx, &mut rustdoc);
}

if unit.kind != Kind::Host {
if let Some(ref target) = bcx.build_config.requested_target {
Expand Down Expand Up @@ -629,8 +626,6 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
let package_id = unit.pkg.package_id().clone();
let target = unit.target.clone();

let should_capture_output = cx.bcx.config.cli_unstable().compile_progress;

Ok(Work::new(move |state| {
if let Some(output) = build_state.outputs.lock().unwrap().get(&key) {
for cfg in output.cfgs.iter() {
Expand All @@ -649,10 +644,8 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
&mut |line| json_stderr(line, &package_id, &target),
false,
).map(drop)
} else if should_capture_output {
state.capture_output(&rustdoc, false).map(drop)
} else {
rustdoc.exec()
state.capture_output(&rustdoc, false).map(drop)
};
exec_result.chain_err(|| format!("Could not document `{}`.", name))?;
Ok(())
Expand Down Expand Up @@ -709,12 +702,9 @@ fn add_cap_lints(bcx: &BuildContext, unit: &Unit, cmd: &mut ProcessBuilder) {
}

fn add_color(bcx: &BuildContext, cmd: &mut ProcessBuilder) {
let capture_output = bcx.config.cli_unstable().compile_progress;
let shell = bcx.config.shell();
if capture_output || shell.color_choice() != ColorChoice::CargoAuto {
let color = if shell.supports_color() { "always" } else { "never" };
cmd.args(&["--color", color]);
}
let color = if shell.supports_color() { "always" } else { "never" };
cmd.args(&["--color", color]);
}

fn add_error_format(bcx: &BuildContext, cmd: &mut ProcessBuilder) {
Expand Down
2 changes: 0 additions & 2 deletions src/cargo/core/features.rs
Expand Up @@ -318,7 +318,6 @@ pub struct CliUnstable {
pub package_features: bool,
pub advanced_env: bool,
pub config_profile: bool,
pub compile_progress: bool,
}

impl CliUnstable {
Expand Down Expand Up @@ -355,7 +354,6 @@ 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),
}

Expand Down
29 changes: 29 additions & 0 deletions src/cargo/util/rustc.rs
Expand Up @@ -4,6 +4,7 @@ use std::path::{Path, PathBuf};
use std::hash::{Hash, Hasher, SipHasher};
use std::collections::hash_map::{Entry, HashMap};
use std::sync::Mutex;
use std::process::Stdio;
use std::env;

use serde_json;
Expand Down Expand Up @@ -83,6 +84,10 @@ impl Rustc {
pub fn cached_output(&self, cmd: &ProcessBuilder) -> CargoResult<(String, String)> {
self.cache.lock().unwrap().cached_output(cmd)
}

pub fn cached_success(&self, cmd: &ProcessBuilder) -> CargoResult<bool> {
self.cache.lock().unwrap().cached_success(cmd)
}
}

/// It is a well known that `rustc` is not the fastest compiler in the world.
Expand All @@ -104,6 +109,7 @@ struct Cache {
struct CacheData {
rustc_fingerprint: u64,
outputs: HashMap<u64, (String, String)>,
successes: HashMap<u64, bool>,
}

impl Cache {
Expand All @@ -113,6 +119,7 @@ impl Cache {
let empty = CacheData {
rustc_fingerprint,
outputs: HashMap::new(),
successes: HashMap::new(),
};
let mut dirty = true;
let data = match read(&cache_location) {
Expand Down Expand Up @@ -177,6 +184,28 @@ impl Cache {
}
}
}

fn cached_success(&mut self, cmd: &ProcessBuilder) -> CargoResult<bool> {
let key = process_fingerprint(cmd);
match self.data.successes.entry(key) {
Entry::Occupied(entry) => {
info!("rustc info cache hit");
Ok(*entry.get())
}
Entry::Vacant(entry) => {
info!("rustc info cache miss");
let success = cmd
.build_command()
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()?
.success();
entry.insert(success);
self.dirty = true;
Ok(success)
}
}
}
}

impl Drop for Cache {
Expand Down
16 changes: 0 additions & 16 deletions src/doc/src/reference/unstable.md
Expand Up @@ -294,22 +294,6 @@ 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...
```

### default-run
* Original issue: [#2200](https://github.com/rust-lang/cargo/issues/2200)

Expand Down
52 changes: 26 additions & 26 deletions tests/testsuite/build.rs
Expand Up @@ -1261,14 +1261,14 @@ fn cargo_default_env_metadata_env_var() {
.with_stderr(&format!(
"\
[COMPILING] bar v0.0.1 ([CWD]/bar)
[RUNNING] `rustc --crate-name bar bar/src/lib.rs --crate-type dylib \
[RUNNING] `rustc --crate-name bar bar/src/lib.rs --color never --crate-type dylib \
--emit=dep-info,link \
-C prefer-dynamic -C debuginfo=2 \
-C metadata=[..] \
--out-dir [..] \
-L dependency=[CWD]/target/debug/deps`
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc --crate-name foo src/lib.rs --crate-type lib \
[RUNNING] `rustc --crate-name foo src/lib.rs --color never --crate-type lib \
--emit=dep-info,link -C debuginfo=2 \
-C metadata=[..] \
-C extra-filename=[..] \
Expand All @@ -1288,14 +1288,14 @@ fn cargo_default_env_metadata_env_var() {
.with_stderr(&format!(
"\
[COMPILING] bar v0.0.1 ([CWD]/bar)
[RUNNING] `rustc --crate-name bar bar/src/lib.rs --crate-type dylib \
[RUNNING] `rustc --crate-name bar bar/src/lib.rs --color never --crate-type dylib \
--emit=dep-info,link \
-C prefer-dynamic -C debuginfo=2 \
-C metadata=[..] \
--out-dir [..] \
-L dependency=[CWD]/target/debug/deps`
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc --crate-name foo src/lib.rs --crate-type lib \
[RUNNING] `rustc --crate-name foo src/lib.rs --color never --crate-type lib \
--emit=dep-info,link -C debuginfo=2 \
-C metadata=[..] \
-C extra-filename=[..] \
Expand Down Expand Up @@ -1616,7 +1616,7 @@ fn lto_build() {
.with_stderr(
"\
[COMPILING] test v0.0.0 ([CWD])
[RUNNING] `rustc --crate-name test src/main.rs --crate-type bin \
[RUNNING] `rustc --crate-name test src/main.rs --color never --crate-type bin \
--emit=dep-info,link \
-C opt-level=3 \
-C lto \
Expand All @@ -1635,7 +1635,7 @@ fn verbose_build() {
.with_stderr(
"\
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc --crate-name foo src/lib.rs --crate-type lib \
[RUNNING] `rustc --crate-name foo src/lib.rs --color never --crate-type lib \
--emit=dep-info,link -C debuginfo=2 \
-C metadata=[..] \
--out-dir [..] \
Expand All @@ -1652,7 +1652,7 @@ fn verbose_release_build() {
.with_stderr(
"\
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc --crate-name foo src/lib.rs --crate-type lib \
[RUNNING] `rustc --crate-name foo src/lib.rs --color never --crate-type lib \
--emit=dep-info,link \
-C opt-level=3 \
-C metadata=[..] \
Expand Down Expand Up @@ -1698,7 +1698,7 @@ fn verbose_release_build_deps() {
.with_stderr(&format!(
"\
[COMPILING] foo v0.0.0 ([CWD]/foo)
[RUNNING] `rustc --crate-name foo foo/src/lib.rs \
[RUNNING] `rustc --crate-name foo foo/src/lib.rs --color never \
--crate-type dylib --crate-type rlib \
--emit=dep-info,link \
-C prefer-dynamic \
Expand All @@ -1707,7 +1707,7 @@ fn verbose_release_build_deps() {
--out-dir [..] \
-L dependency=[CWD]/target/release/deps`
[COMPILING] test v0.0.0 ([CWD])
[RUNNING] `rustc --crate-name test src/lib.rs --crate-type lib \
[RUNNING] `rustc --crate-name test src/lib.rs --color never --crate-type lib \
--emit=dep-info,link \
-C opt-level=3 \
-C metadata=[..] \
Expand Down Expand Up @@ -4099,41 +4099,41 @@ fn build_filter_infer_profile() {
p.cargo("build -v")
.with_stderr_contains(
"\
[RUNNING] `rustc --crate-name foo src/lib.rs --crate-type lib \
[RUNNING] `rustc --crate-name foo src/lib.rs --color never --crate-type lib \
--emit=dep-info,link[..]",
).with_stderr_contains(
"\
[RUNNING] `rustc --crate-name foo src/main.rs --crate-type bin \
[RUNNING] `rustc --crate-name foo src/main.rs --color never --crate-type bin \
--emit=dep-info,link[..]",
).run();

p.root().join("target").rm_rf();
p.cargo("build -v --test=t1")
.with_stderr_contains(
"\
[RUNNING] `rustc --crate-name foo src/lib.rs --crate-type lib \
[RUNNING] `rustc --crate-name foo src/lib.rs --color never --crate-type lib \
--emit=dep-info,link[..]",
).with_stderr_contains(
"[RUNNING] `rustc --crate-name t1 tests/t1.rs --emit=dep-info,link[..]",
"[RUNNING] `rustc --crate-name t1 tests/t1.rs --color never --emit=dep-info,link[..]",
).with_stderr_contains(
"\
[RUNNING] `rustc --crate-name foo src/main.rs --crate-type bin \
[RUNNING] `rustc --crate-name foo src/main.rs --color never --crate-type bin \
--emit=dep-info,link[..]",
).run();

p.root().join("target").rm_rf();
p.cargo("build -v --bench=b1")
.with_stderr_contains(
"\
[RUNNING] `rustc --crate-name foo src/lib.rs --crate-type lib \
[RUNNING] `rustc --crate-name foo src/lib.rs --color never --crate-type lib \
--emit=dep-info,link[..]",
).with_stderr_contains(
"\
[RUNNING] `rustc --crate-name b1 benches/b1.rs --emit=dep-info,link \
[RUNNING] `rustc --crate-name b1 benches/b1.rs --color never --emit=dep-info,link \
-C opt-level=3[..]",
).with_stderr_contains(
"\
[RUNNING] `rustc --crate-name foo src/main.rs --crate-type bin \
[RUNNING] `rustc --crate-name foo src/main.rs --color never --crate-type bin \
--emit=dep-info,link[..]",
).run();
}
Expand All @@ -4144,15 +4144,15 @@ fn targets_selected_default() {
p.cargo("build -v")
// bin
.with_stderr_contains("\
[RUNNING] `rustc --crate-name foo src/main.rs --crate-type bin \
[RUNNING] `rustc --crate-name foo src/main.rs --color never --crate-type bin \
--emit=dep-info,link[..]")
// bench
.with_stderr_does_not_contain("\
[RUNNING] `rustc --crate-name foo src/main.rs --emit=dep-info,link \
[RUNNING] `rustc --crate-name foo src/main.rs --color never --emit=dep-info,link \
-C opt-level=3 --test [..]")
// unit test
.with_stderr_does_not_contain("\
[RUNNING] `rustc --crate-name foo src/main.rs --emit=dep-info,link \
[RUNNING] `rustc --crate-name foo src/main.rs --color never --emit=dep-info,link \
-C debuginfo=2 --test [..]").run();
}

Expand All @@ -4162,15 +4162,15 @@ fn targets_selected_all() {
p.cargo("build -v --all-targets")
// bin
.with_stderr_contains("\
[RUNNING] `rustc --crate-name foo src/main.rs --crate-type bin \
[RUNNING] `rustc --crate-name foo src/main.rs --color never --crate-type bin \
--emit=dep-info,link[..]")
// bench
.with_stderr_contains("\
[RUNNING] `rustc --crate-name foo src/main.rs --emit=dep-info,link \
[RUNNING] `rustc --crate-name foo src/main.rs --color never --emit=dep-info,link \
-C opt-level=3 --test [..]")
// unit test
.with_stderr_contains("\
[RUNNING] `rustc --crate-name foo src/main.rs --emit=dep-info,link \
[RUNNING] `rustc --crate-name foo src/main.rs --color never --emit=dep-info,link \
-C debuginfo=2 --test [..]").run();
}

Expand All @@ -4180,15 +4180,15 @@ fn all_targets_no_lib() {
p.cargo("build -v --all-targets")
// bin
.with_stderr_contains("\
[RUNNING] `rustc --crate-name foo src/main.rs --crate-type bin \
[RUNNING] `rustc --crate-name foo src/main.rs --color never --crate-type bin \
--emit=dep-info,link[..]")
// bench
.with_stderr_contains("\
[RUNNING] `rustc --crate-name foo src/main.rs --emit=dep-info,link \
[RUNNING] `rustc --crate-name foo src/main.rs --color never --emit=dep-info,link \
-C opt-level=3 --test [..]")
// unit test
.with_stderr_contains("\
[RUNNING] `rustc --crate-name foo src/main.rs --emit=dep-info,link \
[RUNNING] `rustc --crate-name foo src/main.rs --color never --emit=dep-info,link \
-C debuginfo=2 --test [..]").run();
}

Expand Down