@@ -288,7 +288,7 @@ macro_rules! forward {
288288}
289289
290290forward ! {
291- verbose( msg : & str ) ,
291+ verbose( f : impl Fn ( ) ) ,
292292 is_verbose( ) -> bool ,
293293 create( path: & Path , s: & str ) ,
294294 remove( f: & Path ) ,
@@ -440,19 +440,19 @@ impl Build {
440440 . unwrap ( )
441441 . trim ( ) ;
442442 if local_release. split ( '.' ) . take ( 2 ) . eq ( version. split ( '.' ) . take ( 2 ) ) {
443- build. verbose ( & format ! ( "auto-detected local-rebuild {local_release}" ) ) ;
443+ build. verbose ( || println ! ( "auto-detected local-rebuild {local_release}" ) ) ;
444444 build. local_rebuild = true ;
445445 }
446446
447- build. verbose ( "finding compilers" ) ;
447+ build. verbose ( || println ! ( "finding compilers" ) ) ;
448448 utils:: cc_detect:: find ( & build) ;
449449 // When running `setup`, the profile is about to change, so any requirements we have now may
450450 // be different on the next invocation. Don't check for them until the next time x.py is
451451 // run. This is ok because `setup` never runs any build commands, so it won't fail if commands are missing.
452452 //
453453 // Similarly, for `setup` we don't actually need submodules or cargo metadata.
454454 if !matches ! ( build. config. cmd, Subcommand :: Setup { .. } ) {
455- build. verbose ( "running sanity check" ) ;
455+ build. verbose ( || println ! ( "running sanity check" ) ) ;
456456 crate :: core:: sanity:: check ( & mut build) ;
457457
458458 // Make sure we update these before gathering metadata so we don't get an error about missing
@@ -464,7 +464,7 @@ impl Build {
464464 // Now, update all existing submodules.
465465 build. update_existing_submodules ( ) ;
466466
467- build. verbose ( "learning about cargo" ) ;
467+ build. verbose ( || println ! ( "learning about cargo" ) ) ;
468468 crate :: core:: metadata:: build ( & mut build) ;
469469 }
470470
@@ -693,7 +693,7 @@ impl Build {
693693 let stamp = dir. join ( ".stamp" ) ;
694694 let mut cleared = false ;
695695 if mtime ( & stamp) < mtime ( input) {
696- self . verbose ( & format ! ( "Dirty - {}" , dir. display( ) ) ) ;
696+ self . verbose ( || println ! ( "Dirty - {}" , dir. display( ) ) ) ;
697697 let _ = fs:: remove_dir_all ( dir) ;
698698 cleared = true ;
699699 } else if stamp. exists ( ) {
@@ -986,7 +986,7 @@ impl Build {
986986 }
987987
988988 let command = cmd. into ( ) ;
989- self . verbose ( & format ! ( "running: {command:?}" ) ) ;
989+ self . verbose ( || println ! ( "running: {command:?}" ) ) ;
990990
991991 let ( output, print_error) = match command. output_mode {
992992 mode @ ( OutputMode :: PrintAll | OutputMode :: PrintOutput ) => (
@@ -1044,14 +1044,15 @@ impl Build {
10441044 }
10451045 }
10461046
1047+ /// Check if verbosity is greater than the `level`
10471048 pub fn is_verbose_than ( & self , level : usize ) -> bool {
10481049 self . verbosity > level
10491050 }
10501051
1051- /// Prints a message if this build is configured in more verbose mode than `level`.
1052- fn verbose_than ( & self , level : usize , msg : & str ) {
1052+ /// Runs a function if verbosity is greater than `level`.
1053+ fn verbose_than ( & self , level : usize , f : impl Fn ( ) ) {
10531054 if self . is_verbose_than ( level) {
1054- println ! ( "{msg}" ) ;
1055+ f ( )
10551056 }
10561057 }
10571058
@@ -1654,7 +1655,7 @@ impl Build {
16541655 if self . config . dry_run ( ) {
16551656 return ;
16561657 }
1657- self . verbose_than ( 1 , & format ! ( "Copy {src:?} to {dst:?}" ) ) ;
1658+ self . verbose_than ( 1 , || println ! ( "Copy {src:?} to {dst:?}" ) ) ;
16581659 if src == dst {
16591660 return ;
16601661 }
@@ -1745,7 +1746,7 @@ impl Build {
17451746 return ;
17461747 }
17471748 let dst = dstdir. join ( src. file_name ( ) . unwrap ( ) ) ;
1748- self . verbose_than ( 1 , & format ! ( "Install {src:?} to {dst:?}" ) ) ;
1749+ self . verbose_than ( 1 , || println ! ( "Install {src:?} to {dst:?}" ) ) ;
17491750 t ! ( fs:: create_dir_all( dstdir) ) ;
17501751 if !src. exists ( ) {
17511752 panic ! ( "ERROR: File \" {}\" not found!" , src. display( ) ) ;
0 commit comments