@@ -113,10 +113,14 @@ fn show_error(msg: String) -> ! {
113
113
std:: process:: exit ( 1 )
114
114
}
115
115
116
- // Determines whether a `--flag` is present.
116
+ /// Determines whether a `--flag` is present.
117
117
fn has_arg_flag ( name : & str ) -> bool {
118
- let mut args = std:: env:: args ( ) . take_while ( |val| val != "--" ) ;
119
- args. any ( |val| val == name)
118
+ num_arg_flag ( name) > 0
119
+ }
120
+
121
+ /// Determines how many times a `--flag` is present.
122
+ fn num_arg_flag ( name : & str ) -> usize {
123
+ std:: env:: args ( ) . take_while ( |val| val != "--" ) . filter ( |val| val == name) . count ( )
120
124
}
121
125
122
126
/// Yields all values of command line flag `name` as `Ok(arg)`, and all other arguments except
@@ -581,7 +585,7 @@ fn phase_cargo_miri(mut args: env::Args) {
581
585
"`cargo miri` supports the following subcommands: `run`, `test`, and `setup`."
582
586
) ) ,
583
587
} ;
584
- let verbose = has_arg_flag ( "-v" ) ;
588
+ let verbose = num_arg_flag ( "-v" ) ;
585
589
586
590
// We always setup.
587
591
setup ( subcommand) ;
@@ -679,15 +683,15 @@ fn phase_cargo_miri(mut args: env::Args) {
679
683
cmd. env ( "MIRI_LOCAL_CRATES" , local_crates ( & metadata) ) ;
680
684
681
685
// Run cargo.
682
- if verbose {
686
+ if verbose > 0 {
683
687
eprintln ! ( "[cargo-miri miri] RUSTC_WRAPPER={:?}" , cargo_miri_path) ;
684
688
eprintln ! ( "[cargo-miri miri] {}={:?}" , target_runner_env_name, cargo_miri_path) ;
685
689
if * target != host {
686
690
eprintln ! ( "[cargo-miri miri] {}={:?}" , host_runner_env_name, cargo_miri_path) ;
687
691
}
688
692
eprintln ! ( "[cargo-miri miri] RUSTDOC={:?}" , cargo_miri_path) ;
689
693
eprintln ! ( "[cargo-miri miri] {:?}" , cmd) ;
690
- cmd. env ( "MIRI_VERBOSE" , "" ) ; // This makes the other phases verbose.
694
+ cmd. env ( "MIRI_VERBOSE" , verbose . to_string ( ) ) ; // This makes the other phases verbose.
691
695
}
692
696
exec ( cmd)
693
697
}
@@ -746,7 +750,8 @@ fn phase_rustc(mut args: env::Args, phase: RustcPhase) {
746
750
}
747
751
}
748
752
749
- let verbose = std:: env:: var_os ( "MIRI_VERBOSE" ) . is_some ( ) ;
753
+ let verbose = std:: env:: var ( "MIRI_VERBOSE" )
754
+ . map_or ( 0 , |verbose| verbose. parse ( ) . expect ( "verbosity flag must be an integer" ) ) ;
750
755
let target_crate = is_target_crate ( ) ;
751
756
let print = get_arg_flag_value ( "--print" ) . is_some ( ) || has_arg_flag ( "-vV" ) ; // whether this is cargo/xargo invoking rustc to get some infos
752
757
@@ -755,13 +760,13 @@ fn phase_rustc(mut args: env::Args, phase: RustcPhase) {
755
760
// https://github.com/rust-lang/miri/issues/1724#issuecomment-787115693
756
761
// As we store a JSON file instead of building the crate here, an empty file is fine.
757
762
let dep_info_name = out_filename ( "" , ".d" ) ;
758
- if verbose {
763
+ if verbose > 0 {
759
764
eprintln ! ( "[cargo-miri rustc] writing stub dep-info to `{}`" , dep_info_name. display( ) ) ;
760
765
}
761
766
File :: create ( dep_info_name) . expect ( "failed to create fake .d file" ) ;
762
767
763
768
let filename = out_filename ( "" , "" ) ;
764
- if verbose {
769
+ if verbose > 0 {
765
770
eprintln ! ( "[cargo-miri rustc] writing run info to `{}`" , filename. display( ) ) ;
766
771
}
767
772
info. store ( & filename) ;
@@ -804,7 +809,7 @@ fn phase_rustc(mut args: env::Args, phase: RustcPhase) {
804
809
cmd. args ( & env. args ) ;
805
810
cmd. env ( "MIRI_BE_RUSTC" , "target" ) ;
806
811
807
- if verbose {
812
+ if verbose > 0 {
808
813
eprintln ! (
809
814
"[cargo-miri rustc] captured input:\n {}" ,
810
815
std:: str :: from_utf8( & env. stdin) . unwrap( )
@@ -891,21 +896,23 @@ fn phase_rustc(mut args: env::Args, phase: RustcPhase) {
891
896
cmd. env ( "MIRI_BE_RUSTC" , if target_crate { "target" } else { "host" } ) ;
892
897
893
898
// Run it.
894
- if verbose {
899
+ if verbose > 0 {
895
900
eprint ! ( "[cargo-miri rustc] " ) ;
896
- let mut envs = HashMap :: new ( ) ;
897
- for ( key, value) in std:: env:: vars ( ) {
898
- envs. insert ( key, value) ;
899
- }
900
- for ( key, value) in cmd. get_envs ( ) {
901
- if let Some ( value) = value {
902
- envs. insert ( key. to_str ( ) . unwrap ( ) . into ( ) , value. to_str ( ) . unwrap ( ) . to_owned ( ) ) ;
903
- } else {
904
- envs. remove ( key. to_str ( ) . unwrap ( ) ) ;
901
+ if verbose > 1 {
902
+ let mut envs = HashMap :: new ( ) ;
903
+ for ( key, value) in std:: env:: vars ( ) {
904
+ envs. insert ( key, value) ;
905
+ }
906
+ for ( key, value) in cmd. get_envs ( ) {
907
+ if let Some ( value) = value {
908
+ envs. insert ( key. to_str ( ) . unwrap ( ) . into ( ) , value. to_str ( ) . unwrap ( ) . to_owned ( ) ) ;
909
+ } else {
910
+ envs. remove ( key. to_str ( ) . unwrap ( ) ) ;
911
+ }
912
+ }
913
+ for ( key, value) in envs {
914
+ eprint ! ( "{key}={value:?} " ) ;
905
915
}
906
- }
907
- for ( key, value) in envs {
908
- eprint ! ( "{key}={value:?} " ) ;
909
916
}
910
917
eprintln ! ( "{:?}" , cmd) ;
911
918
}
0 commit comments