Skip to content

Commit cf3868b

Browse files
committed
Auto merge of #1358 - dtolnay:ci, r=RalfJung
Disable interactive prompts in CI Closes #1357.
2 parents 7c73dc3 + a4dd463 commit cf3868b

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,11 @@ MIRI_NIGHTLY=nightly-$(curl -s https://rust-lang.github.io/rustup-components-his
127127
echo "Installing latest nightly with Miri: $MIRI_NIGHTLY"
128128
rustup set profile minimal
129129
rustup default "$MIRI_NIGHTLY"
130-
131130
rustup component add miri
132-
cargo miri setup
133131

134132
cargo miri test
135133
```
136134

137-
We use `cargo miri setup` to avoid getting interactive questions about the extra
138-
setup needed for Miri.
139-
140135
### Common Problems
141136

142137
When using the above instructions, you may encounter a number of confusing compiler

src/bin/cargo-miri.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![feature(inner_deref)]
22

3+
use std::env;
34
use std::fs::{self, File};
45
use std::io::{self, BufRead, Write};
56
use std::ops::Not;
@@ -247,7 +248,8 @@ fn xargo_version() -> Option<(u32, u32, u32)> {
247248
}
248249

249250
fn ask_to_run(mut cmd: Command, ask: bool, text: &str) {
250-
if ask {
251+
// Disable interactive prompts in CI (GitHub Actions, Travis, AppVeyor, etc).
252+
if ask && env::var_os("CI").is_none() {
251253
let mut buf = String::new();
252254
print!("I will run `{:?}` to {}. Proceed? [Y/n] ", cmd, text);
253255
io::stdout().flush().unwrap();
@@ -270,14 +272,18 @@ fn ask_to_run(mut cmd: Command, ask: bool, text: &str) {
270272
/// Performs the setup required to make `cargo miri` work: Getting a custom-built libstd. Then sets
271273
/// `MIRI_SYSROOT`. Skipped if `MIRI_SYSROOT` is already set, in which case we expect the user has
272274
/// done all this already.
273-
fn setup(ask_user: bool) {
275+
fn setup(subcommand: MiriCommand) {
274276
if std::env::var("MIRI_SYSROOT").is_ok() {
275-
if !ask_user {
277+
if subcommand == MiriCommand::Setup {
276278
println!("WARNING: MIRI_SYSROOT already set, not doing anything.")
277279
}
278280
return;
279281
}
280282

283+
// Subcommands other than `setup` will do a setup if necessary, but
284+
// interactively confirm first.
285+
let ask_user = subcommand != MiriCommand::Setup;
286+
281287
// First, we need xargo.
282288
if xargo_version().map_or(true, |v| v < XARGO_MIN_VERSION) {
283289
if std::env::var("XARGO_CHECK").is_ok() {
@@ -360,7 +366,8 @@ path = "lib.rs"
360366
File::create(dir.join("lib.rs")).unwrap();
361367
// Prepare xargo invocation.
362368
let target = get_arg_flag_value("--target");
363-
let print_sysroot = !ask_user && has_arg_flag("--print-sysroot"); // whether we just print the sysroot path
369+
let print_sysroot = subcommand == MiriCommand::Setup
370+
&& has_arg_flag("--print-sysroot"); // whether we just print the sysroot path
364371
let mut command = xargo_check();
365372
command.arg("build").arg("-q");
366373
command.current_dir(&dir);
@@ -388,7 +395,7 @@ path = "lib.rs"
388395
if print_sysroot {
389396
// Print just the sysroot and nothing else; this way we do not need any escaping.
390397
println!("{}", sysroot.display());
391-
} else if !ask_user {
398+
} else if subcommand == MiriCommand::Setup {
392399
println!("A libstd for Miri is now available in `{}`.", sysroot.display());
393400
}
394401
}
@@ -435,8 +442,7 @@ fn in_cargo_miri() {
435442
test_sysroot_consistency();
436443

437444
// We always setup.
438-
let ask = subcommand != MiriCommand::Setup;
439-
setup(ask);
445+
setup(subcommand);
440446
if subcommand == MiriCommand::Setup {
441447
// Stop here.
442448
return;

0 commit comments

Comments
 (0)