Skip to content

Commit

Permalink
Auto merge of rust-lang#3599 - saethlin:quiet-when-no-change, r=RalfJung
Browse files Browse the repository at this point in the history
Don't print unnecessary sysroot messages

Currently, when running `cargo miri setup`, we always print that a sysroot is being prepared, even if we just bail out of building after checking the hash. So that message is wrong; we didn't actually prepare a sysroot.

We also always print the preparing message for `cargo miri run`, even if no sysroot is prepared.

With this PR, `cargo miri run` prints no sysroot messages when an existing one is reused, and when a redundant `cargo miri setup` is requested, we print:
```
A sysroot for Miri is already available in `/home/ben/.cache/miri`.
```
  • Loading branch information
bors committed May 12, 2024
2 parents 75d531d + cd7527a commit e4f81d1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/tools/miri/cargo-miri/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ dependencies = [

[[package]]
name = "rustc-build-sysroot"
version = "0.4.7"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab1dbbd1bdf65fdac44c885f6cca147ba179108ce284b60a08ccc04b1f1dbac0"
checksum = "de6077473f0c46779b49e4587a81f1b8919e0ec26630409ecfda0ba3259efb43"
dependencies = [
"anyhow",
"rustc_version",
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/cargo-miri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ directories = "5"
rustc_version = "0.4"
serde_json = "1.0.40"
cargo_metadata = "0.18.0"
rustc-build-sysroot = "0.4.6"
rustc-build-sysroot = "0.5.0"

# Enable some feature flags that dev-dependencies need but dependencies
# do not. This makes `./miri install` after `./miri build` faster.
Expand Down
50 changes: 32 additions & 18 deletions src/tools/miri/cargo-miri/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::fmt::Write;
use std::path::PathBuf;
use std::process::{self, Command};

use rustc_build_sysroot::{BuildMode, SysrootBuilder, SysrootConfig};
use rustc_build_sysroot::{BuildMode, SysrootBuilder, SysrootConfig, SysrootStatus};
use rustc_version::VersionMeta;

use crate::util::*;
Expand Down Expand Up @@ -137,32 +137,52 @@ pub fn setup(
// not apply `RUSTFLAGS` to the sysroot either.
let rustflags = &["-Cdebug-assertions=off", "-Coverflow-checks=on"];

// Do the build.
if print_sysroot || quiet {
// Be silent.
} else {
let notify = || {
let mut msg = String::new();
write!(msg, "Preparing a sysroot for Miri (target: {target})").unwrap();
if verbose > 0 {
write!(msg, " in {}", sysroot_dir.display()).unwrap();
}
write!(msg, "...").unwrap();
if only_setup {

if print_sysroot || quiet {
// Be silent.
} else if only_setup {
// We want to be explicit.
eprintln!("{msg}");
} else {
// We want to be quiet, but still let the user know that something is happening.
eprint!("{msg} ");
}
}
SysrootBuilder::new(&sysroot_dir, target)
};

// Do the build.
let status = SysrootBuilder::new(&sysroot_dir, target)
.build_mode(BuildMode::Check)
.rustc_version(rustc_version.clone())
.sysroot_config(sysroot_config)
.rustflags(rustflags)
.cargo(cargo_cmd)
.build_from_source(&rust_src)
.unwrap_or_else(|err| {
.when_build_required(notify)
.build_from_source(&rust_src);
match status {
Ok(SysrootStatus::AlreadyCached) =>
if only_setup && !(print_sysroot || quiet) {
eprintln!(
"A sysroot for Miri is already available in `{}`.",
sysroot_dir.display()
);
},
Ok(SysrootStatus::SysrootBuilt) => {
if print_sysroot || quiet {
// Be silent.
} else if only_setup {
eprintln!("A sysroot for Miri is now available in `{}`.", sysroot_dir.display());
} else {
eprintln!("done");
}
}
Err(err) =>
if print_sysroot {
show_error!("failed to build sysroot")
} else if only_setup {
Expand All @@ -171,15 +191,9 @@ pub fn setup(
show_error!(
"failed to build sysroot; run `cargo miri setup` to see the error details"
)
}
});
if print_sysroot || quiet {
// Be silent.
} else if only_setup {
eprintln!("A sysroot for Miri is now available in `{}`.", sysroot_dir.display());
} else {
eprintln!("done");
},
}

if print_sysroot {
// Print just the sysroot and nothing else to stdout; this way we do not need any escaping.
println!("{}", sysroot_dir.display());
Expand Down

0 comments on commit e4f81d1

Please sign in to comment.