1
+ #![ feature( let_else) ]
1
2
#![ allow( clippy:: useless_format, clippy:: derive_partial_eq_without_eq) ]
2
3
3
4
mod version;
@@ -34,11 +35,12 @@ Examples:
34
35
cargo miri test -- test-suite-filter
35
36
"# ;
36
37
37
- #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
38
+ #[ derive( Clone , Debug ) ]
38
39
enum MiriCommand {
39
- Run ,
40
- Test ,
40
+ /// Our own special 'setup' command.
41
41
Setup ,
42
+ /// A command to be forwarded to cargo.
43
+ Forward ( String ) ,
42
44
}
43
45
44
46
/// The information to run a crate with the given environment.
@@ -339,17 +341,18 @@ fn write_to_file(filename: &Path, content: &str) {
339
341
/// Performs the setup required to make `cargo miri` work: Getting a custom-built libstd. Then sets
340
342
/// `MIRI_SYSROOT`. Skipped if `MIRI_SYSROOT` is already set, in which case we expect the user has
341
343
/// done all this already.
342
- fn setup ( subcommand : MiriCommand ) {
344
+ fn setup ( subcommand : & MiriCommand ) {
345
+ let only_setup = matches ! ( subcommand, MiriCommand :: Setup ) ;
343
346
if std:: env:: var_os ( "MIRI_SYSROOT" ) . is_some ( ) {
344
- if subcommand == MiriCommand :: Setup {
347
+ if only_setup {
345
348
println ! ( "WARNING: MIRI_SYSROOT already set, not doing anything." )
346
349
}
347
350
return ;
348
351
}
349
352
350
353
// Subcommands other than `setup` will do a setup if necessary, but
351
354
// interactively confirm first.
352
- let ask_user = subcommand != MiriCommand :: Setup ;
355
+ let ask_user = !only_setup ;
353
356
354
357
// First, we need xargo.
355
358
if xargo_version ( ) . map_or ( true , |v| v < XARGO_MIN_VERSION ) {
@@ -495,11 +498,11 @@ path = "lib.rs"
495
498
let sysroot = if target == & host { dir. join ( "HOST" ) } else { PathBuf :: from ( dir) } ;
496
499
std:: env:: set_var ( "MIRI_SYSROOT" , & sysroot) ; // pass the env var to the processes we spawn, which will turn it into "--sysroot" flags
497
500
// Figure out what to print.
498
- let print_sysroot = subcommand == MiriCommand :: Setup && has_arg_flag ( "--print-sysroot" ) ; // whether we just print the sysroot path
501
+ let print_sysroot = only_setup && has_arg_flag ( "--print-sysroot" ) ; // whether we just print the sysroot path
499
502
if print_sysroot {
500
503
// Print just the sysroot and nothing else; this way we do not need any escaping.
501
504
println ! ( "{}" , sysroot. display( ) ) ;
502
- } else if subcommand == MiriCommand :: Setup {
505
+ } else if only_setup {
503
506
println ! ( "A libstd for Miri is now available in `{}`." , sysroot. display( ) ) ;
504
507
}
505
508
}
@@ -573,10 +576,12 @@ fn phase_cargo_miri(mut args: env::Args) {
573
576
// Require a subcommand before any flags.
574
577
// We cannot know which of those flags take arguments and which do not,
575
578
// so we cannot detect subcommands later.
576
- let subcommand = match args. next ( ) . as_deref ( ) {
577
- Some ( "test" | "t" ) => MiriCommand :: Test ,
578
- Some ( "run" | "r" ) => MiriCommand :: Run ,
579
- Some ( "setup" ) => MiriCommand :: Setup ,
579
+ let Some ( subcommand) = args. next ( ) else {
580
+ show_error ( format ! ( "`cargo miri` needs to be called with a subcommand (`run`, `test`)" ) ) ;
581
+ } ;
582
+ let subcommand = match & * subcommand {
583
+ "setup" => MiriCommand :: Setup ,
584
+ "test" | "t" | "run" | "r" => MiriCommand :: Forward ( subcommand) ,
580
585
// Invalid command.
581
586
_ =>
582
587
show_error ( format ! (
@@ -586,7 +591,7 @@ fn phase_cargo_miri(mut args: env::Args) {
586
591
let verbose = has_arg_flag ( "-v" ) ;
587
592
588
593
// We always setup.
589
- setup ( subcommand) ;
594
+ setup ( & subcommand) ;
590
595
591
596
// Invoke actual cargo for the job, but with different flags.
592
597
// We re-use `cargo test` and `cargo run`, which makes target and binary handling very easy but
@@ -596,8 +601,7 @@ fn phase_cargo_miri(mut args: env::Args) {
596
601
// harder.
597
602
let cargo_miri_path = std:: env:: current_exe ( ) . expect ( "current executable path invalid" ) ;
598
603
let cargo_cmd = match subcommand {
599
- MiriCommand :: Test => "test" ,
600
- MiriCommand :: Run => "run" ,
604
+ MiriCommand :: Forward ( s) => s,
601
605
MiriCommand :: Setup => return , // `cargo miri setup` stops here.
602
606
} ;
603
607
let mut cmd = cargo ( ) ;
0 commit comments