Skip to content

Commit 2584507

Browse files
committed
Preserve consistent output whether or not CI is set
1 parent 28f4f84 commit 2584507

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/bin/cargo-miri.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,9 @@ fn xargo_version() -> Option<(u32, u32, u32)> {
247247
Some((major, minor, patch))
248248
}
249249

250-
fn ask_to_run(mut cmd: Command, ask: bool, text: &str) {
250+
fn ask_to_run(mut cmd: Command, subcommand: MiriCommand, text: &str) {
251+
// Disable interactive prompts in CI (GitHub Actions, Travis, AppVeyor, etc).
252+
let ask = subcommand != MiriCommand::Setup && env::var_os("CI").is_none();
251253
if ask {
252254
let mut buf = String::new();
253255
print!("I will run `{:?}` to {}. Proceed? [Y/n] ", cmd, text);
@@ -271,9 +273,9 @@ fn ask_to_run(mut cmd: Command, ask: bool, text: &str) {
271273
/// Performs the setup required to make `cargo miri` work: Getting a custom-built libstd. Then sets
272274
/// `MIRI_SYSROOT`. Skipped if `MIRI_SYSROOT` is already set, in which case we expect the user has
273275
/// done all this already.
274-
fn setup(ask_user: bool) {
276+
fn setup(subcommand: MiriCommand) {
275277
if std::env::var("MIRI_SYSROOT").is_ok() {
276-
if !ask_user {
278+
if subcommand == MiriCommand::Setup {
277279
println!("WARNING: MIRI_SYSROOT already set, not doing anything.")
278280
}
279281
return;
@@ -287,7 +289,7 @@ fn setup(ask_user: bool) {
287289
}
288290
let mut cmd = cargo();
289291
cmd.args(&["install", "xargo", "-f"]);
290-
ask_to_run(cmd, ask_user, "install a recent enough xargo");
292+
ask_to_run(cmd, subcommand, "install a recent enough xargo");
291293
}
292294

293295
// Determine where the rust sources are located. `XARGO_RUST_SRC` env var trumps everything.
@@ -310,7 +312,7 @@ fn setup(ask_user: bool) {
310312
cmd.args(&["component", "add", "rust-src"]);
311313
ask_to_run(
312314
cmd,
313-
ask_user,
315+
subcommand,
314316
"install the rustc-src component for the selected toolchain",
315317
);
316318
}
@@ -361,7 +363,8 @@ path = "lib.rs"
361363
File::create(dir.join("lib.rs")).unwrap();
362364
// Prepare xargo invocation.
363365
let target = get_arg_flag_value("--target");
364-
let print_sysroot = !ask_user && has_arg_flag("--print-sysroot"); // whether we just print the sysroot path
366+
let print_sysroot = subcommand == MiriCommand::Setup
367+
&& has_arg_flag("--print-sysroot"); // whether we just print the sysroot path
365368
let mut command = xargo_check();
366369
command.arg("build").arg("-q");
367370
command.current_dir(&dir);
@@ -389,7 +392,7 @@ path = "lib.rs"
389392
if print_sysroot {
390393
// Print just the sysroot and nothing else; this way we do not need any escaping.
391394
println!("{}", sysroot.display());
392-
} else if !ask_user {
395+
} else if subcommand == MiriCommand::Setup {
393396
println!("A libstd for Miri is now available in `{}`.", sysroot.display());
394397
}
395398
}
@@ -436,9 +439,7 @@ fn in_cargo_miri() {
436439
test_sysroot_consistency();
437440

438441
// We always setup.
439-
// Disable interactive prompts in CI (GitHub Actions, Travis, AppVeyor, etc).
440-
let ask = subcommand != MiriCommand::Setup && env::var_os("CI").is_none();
441-
setup(ask);
442+
setup(subcommand);
442443
if subcommand == MiriCommand::Setup {
443444
// Stop here.
444445
return;

0 commit comments

Comments
 (0)