1
1
#![ feature( inner_deref) ]
2
2
3
+ use std:: env;
3
4
use std:: fs:: { self , File } ;
4
5
use std:: io:: { self , BufRead , Write } ;
5
6
use std:: ops:: Not ;
@@ -247,7 +248,8 @@ fn xargo_version() -> Option<(u32, u32, u32)> {
247
248
}
248
249
249
250
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 ( ) {
251
253
let mut buf = String :: new ( ) ;
252
254
print ! ( "I will run `{:?}` to {}. Proceed? [Y/n] " , cmd, text) ;
253
255
io:: stdout ( ) . flush ( ) . unwrap ( ) ;
@@ -270,14 +272,18 @@ fn ask_to_run(mut cmd: Command, ask: bool, text: &str) {
270
272
/// Performs the setup required to make `cargo miri` work: Getting a custom-built libstd. Then sets
271
273
/// `MIRI_SYSROOT`. Skipped if `MIRI_SYSROOT` is already set, in which case we expect the user has
272
274
/// done all this already.
273
- fn setup ( ask_user : bool ) {
275
+ fn setup ( subcommand : MiriCommand ) {
274
276
if std:: env:: var ( "MIRI_SYSROOT" ) . is_ok ( ) {
275
- if !ask_user {
277
+ if subcommand == MiriCommand :: Setup {
276
278
println ! ( "WARNING: MIRI_SYSROOT already set, not doing anything." )
277
279
}
278
280
return ;
279
281
}
280
282
283
+ // Subcommands other than `setup` will do a setup if necessary, but
284
+ // interactively confirm first.
285
+ let ask_user = subcommand != MiriCommand :: Setup ;
286
+
281
287
// First, we need xargo.
282
288
if xargo_version ( ) . map_or ( true , |v| v < XARGO_MIN_VERSION ) {
283
289
if std:: env:: var ( "XARGO_CHECK" ) . is_ok ( ) {
@@ -360,7 +366,8 @@ path = "lib.rs"
360
366
File :: create ( dir. join ( "lib.rs" ) ) . unwrap ( ) ;
361
367
// Prepare xargo invocation.
362
368
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
364
371
let mut command = xargo_check ( ) ;
365
372
command. arg ( "build" ) . arg ( "-q" ) ;
366
373
command. current_dir ( & dir) ;
@@ -388,7 +395,7 @@ path = "lib.rs"
388
395
if print_sysroot {
389
396
// Print just the sysroot and nothing else; this way we do not need any escaping.
390
397
println ! ( "{}" , sysroot. display( ) ) ;
391
- } else if !ask_user {
398
+ } else if subcommand == MiriCommand :: Setup {
392
399
println ! ( "A libstd for Miri is now available in `{}`." , sysroot. display( ) ) ;
393
400
}
394
401
}
@@ -435,8 +442,7 @@ fn in_cargo_miri() {
435
442
test_sysroot_consistency ( ) ;
436
443
437
444
// We always setup.
438
- let ask = subcommand != MiriCommand :: Setup ;
439
- setup ( ask) ;
445
+ setup ( subcommand) ;
440
446
if subcommand == MiriCommand :: Setup {
441
447
// Stop here.
442
448
return ;
0 commit comments