@@ -113,10 +113,14 @@ fn show_error(msg: String) -> ! {
113113 std:: process:: exit ( 1 )
114114}
115115
116- // Determines whether a `--flag` is present.
116+ /// Determines whether a `--flag` is present.
117117fn 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 ( )
120124}
121125
122126/// 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) {
581585 "`cargo miri` supports the following subcommands: `run`, `test`, and `setup`."
582586 ) ) ,
583587 } ;
584- let verbose = has_arg_flag ( "-v" ) ;
588+ let verbose = num_arg_flag ( "-v" ) ;
585589
586590 // We always setup.
587591 setup ( subcommand) ;
@@ -679,15 +683,15 @@ fn phase_cargo_miri(mut args: env::Args) {
679683 cmd. env ( "MIRI_LOCAL_CRATES" , local_crates ( & metadata) ) ;
680684
681685 // Run cargo.
682- if verbose {
686+ if verbose > 0 {
683687 eprintln ! ( "[cargo-miri miri] RUSTC_WRAPPER={:?}" , cargo_miri_path) ;
684688 eprintln ! ( "[cargo-miri miri] {}={:?}" , target_runner_env_name, cargo_miri_path) ;
685689 if * target != host {
686690 eprintln ! ( "[cargo-miri miri] {}={:?}" , host_runner_env_name, cargo_miri_path) ;
687691 }
688692 eprintln ! ( "[cargo-miri miri] RUSTDOC={:?}" , cargo_miri_path) ;
689693 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.
691695 }
692696 exec ( cmd)
693697}
@@ -746,7 +750,8 @@ fn phase_rustc(mut args: env::Args, phase: RustcPhase) {
746750 }
747751 }
748752
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" ) ) ;
750755 let target_crate = is_target_crate ( ) ;
751756 let print = get_arg_flag_value ( "--print" ) . is_some ( ) || has_arg_flag ( "-vV" ) ; // whether this is cargo/xargo invoking rustc to get some infos
752757
@@ -755,13 +760,13 @@ fn phase_rustc(mut args: env::Args, phase: RustcPhase) {
755760 // https://github.com/rust-lang/miri/issues/1724#issuecomment-787115693
756761 // As we store a JSON file instead of building the crate here, an empty file is fine.
757762 let dep_info_name = out_filename ( "" , ".d" ) ;
758- if verbose {
763+ if verbose > 0 {
759764 eprintln ! ( "[cargo-miri rustc] writing stub dep-info to `{}`" , dep_info_name. display( ) ) ;
760765 }
761766 File :: create ( dep_info_name) . expect ( "failed to create fake .d file" ) ;
762767
763768 let filename = out_filename ( "" , "" ) ;
764- if verbose {
769+ if verbose > 0 {
765770 eprintln ! ( "[cargo-miri rustc] writing run info to `{}`" , filename. display( ) ) ;
766771 }
767772 info. store ( & filename) ;
@@ -804,7 +809,7 @@ fn phase_rustc(mut args: env::Args, phase: RustcPhase) {
804809 cmd. args ( & env. args ) ;
805810 cmd. env ( "MIRI_BE_RUSTC" , "target" ) ;
806811
807- if verbose {
812+ if verbose > 0 {
808813 eprintln ! (
809814 "[cargo-miri rustc] captured input:\n {}" ,
810815 std:: str :: from_utf8( & env. stdin) . unwrap( )
@@ -891,21 +896,23 @@ fn phase_rustc(mut args: env::Args, phase: RustcPhase) {
891896 cmd. env ( "MIRI_BE_RUSTC" , if target_crate { "target" } else { "host" } ) ;
892897
893898 // Run it.
894- if verbose {
899+ if verbose > 0 {
895900 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:?} " ) ;
905915 }
906- }
907- for ( key, value) in envs {
908- eprint ! ( "{key}={value:?} " ) ;
909916 }
910917 eprintln ! ( "{:?}" , cmd) ;
911918 }
0 commit comments