Skip to content

Commit e4f81d1

Browse files
committed
Auto merge of #3599 - saethlin:quiet-when-no-change, r=RalfJung
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`. ```
2 parents 75d531d + cd7527a commit e4f81d1

File tree

3 files changed

+35
-21
lines changed

3 files changed

+35
-21
lines changed

src/tools/miri/cargo-miri/Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ dependencies = [
178178

179179
[[package]]
180180
name = "rustc-build-sysroot"
181-
version = "0.4.7"
181+
version = "0.5.0"
182182
source = "registry+https://github.com/rust-lang/crates.io-index"
183-
checksum = "ab1dbbd1bdf65fdac44c885f6cca147ba179108ce284b60a08ccc04b1f1dbac0"
183+
checksum = "de6077473f0c46779b49e4587a81f1b8919e0ec26630409ecfda0ba3259efb43"
184184
dependencies = [
185185
"anyhow",
186186
"rustc_version",

src/tools/miri/cargo-miri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ directories = "5"
1818
rustc_version = "0.4"
1919
serde_json = "1.0.40"
2020
cargo_metadata = "0.18.0"
21-
rustc-build-sysroot = "0.4.6"
21+
rustc-build-sysroot = "0.5.0"
2222

2323
# Enable some feature flags that dev-dependencies need but dependencies
2424
# do not. This makes `./miri install` after `./miri build` faster.

src/tools/miri/cargo-miri/src/setup.rs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::fmt::Write;
66
use std::path::PathBuf;
77
use std::process::{self, Command};
88

9-
use rustc_build_sysroot::{BuildMode, SysrootBuilder, SysrootConfig};
9+
use rustc_build_sysroot::{BuildMode, SysrootBuilder, SysrootConfig, SysrootStatus};
1010
use rustc_version::VersionMeta;
1111

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

140-
// Do the build.
141-
if print_sysroot || quiet {
142-
// Be silent.
143-
} else {
140+
let notify = || {
144141
let mut msg = String::new();
145142
write!(msg, "Preparing a sysroot for Miri (target: {target})").unwrap();
146143
if verbose > 0 {
147144
write!(msg, " in {}", sysroot_dir.display()).unwrap();
148145
}
149146
write!(msg, "...").unwrap();
150-
if only_setup {
147+
148+
if print_sysroot || quiet {
149+
// Be silent.
150+
} else if only_setup {
151151
// We want to be explicit.
152152
eprintln!("{msg}");
153153
} else {
154154
// We want to be quiet, but still let the user know that something is happening.
155155
eprint!("{msg} ");
156156
}
157-
}
158-
SysrootBuilder::new(&sysroot_dir, target)
157+
};
158+
159+
// Do the build.
160+
let status = SysrootBuilder::new(&sysroot_dir, target)
159161
.build_mode(BuildMode::Check)
160162
.rustc_version(rustc_version.clone())
161163
.sysroot_config(sysroot_config)
162164
.rustflags(rustflags)
163165
.cargo(cargo_cmd)
164-
.build_from_source(&rust_src)
165-
.unwrap_or_else(|err| {
166+
.when_build_required(notify)
167+
.build_from_source(&rust_src);
168+
match status {
169+
Ok(SysrootStatus::AlreadyCached) =>
170+
if only_setup && !(print_sysroot || quiet) {
171+
eprintln!(
172+
"A sysroot for Miri is already available in `{}`.",
173+
sysroot_dir.display()
174+
);
175+
},
176+
Ok(SysrootStatus::SysrootBuilt) => {
177+
if print_sysroot || quiet {
178+
// Be silent.
179+
} else if only_setup {
180+
eprintln!("A sysroot for Miri is now available in `{}`.", sysroot_dir.display());
181+
} else {
182+
eprintln!("done");
183+
}
184+
}
185+
Err(err) =>
166186
if print_sysroot {
167187
show_error!("failed to build sysroot")
168188
} else if only_setup {
@@ -171,15 +191,9 @@ pub fn setup(
171191
show_error!(
172192
"failed to build sysroot; run `cargo miri setup` to see the error details"
173193
)
174-
}
175-
});
176-
if print_sysroot || quiet {
177-
// Be silent.
178-
} else if only_setup {
179-
eprintln!("A sysroot for Miri is now available in `{}`.", sysroot_dir.display());
180-
} else {
181-
eprintln!("done");
194+
},
182195
}
196+
183197
if print_sysroot {
184198
// Print just the sysroot and nothing else to stdout; this way we do not need any escaping.
185199
println!("{}", sysroot_dir.display());

0 commit comments

Comments
 (0)