@@ -288,7 +288,7 @@ macro_rules! forward {
288
288
}
289
289
290
290
forward ! {
291
- verbose( msg : & str ) ,
291
+ verbose( f : impl Fn ( ) ) ,
292
292
is_verbose( ) -> bool ,
293
293
create( path: & Path , s: & str ) ,
294
294
remove( f: & Path ) ,
@@ -440,19 +440,19 @@ impl Build {
440
440
. unwrap ( )
441
441
. trim ( ) ;
442
442
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}" ) ) ;
444
444
build. local_rebuild = true ;
445
445
}
446
446
447
- build. verbose ( "finding compilers" ) ;
447
+ build. verbose ( || println ! ( "finding compilers" ) ) ;
448
448
utils:: cc_detect:: find ( & build) ;
449
449
// When running `setup`, the profile is about to change, so any requirements we have now may
450
450
// be different on the next invocation. Don't check for them until the next time x.py is
451
451
// run. This is ok because `setup` never runs any build commands, so it won't fail if commands are missing.
452
452
//
453
453
// Similarly, for `setup` we don't actually need submodules or cargo metadata.
454
454
if !matches ! ( build. config. cmd, Subcommand :: Setup { .. } ) {
455
- build. verbose ( "running sanity check" ) ;
455
+ build. verbose ( || println ! ( "running sanity check" ) ) ;
456
456
crate :: core:: sanity:: check ( & mut build) ;
457
457
458
458
// Make sure we update these before gathering metadata so we don't get an error about missing
@@ -464,7 +464,7 @@ impl Build {
464
464
// Now, update all existing submodules.
465
465
build. update_existing_submodules ( ) ;
466
466
467
- build. verbose ( "learning about cargo" ) ;
467
+ build. verbose ( || println ! ( "learning about cargo" ) ) ;
468
468
crate :: core:: metadata:: build ( & mut build) ;
469
469
}
470
470
@@ -693,7 +693,7 @@ impl Build {
693
693
let stamp = dir. join ( ".stamp" ) ;
694
694
let mut cleared = false ;
695
695
if mtime ( & stamp) < mtime ( input) {
696
- self . verbose ( & format ! ( "Dirty - {}" , dir. display( ) ) ) ;
696
+ self . verbose ( || println ! ( "Dirty - {}" , dir. display( ) ) ) ;
697
697
let _ = fs:: remove_dir_all ( dir) ;
698
698
cleared = true ;
699
699
} else if stamp. exists ( ) {
@@ -986,7 +986,7 @@ impl Build {
986
986
}
987
987
988
988
let command = cmd. into ( ) ;
989
- self . verbose ( & format ! ( "running: {command:?}" ) ) ;
989
+ self . verbose ( || println ! ( "running: {command:?}" ) ) ;
990
990
991
991
let ( output, print_error) = match command. output_mode {
992
992
mode @ ( OutputMode :: PrintAll | OutputMode :: PrintOutput ) => (
@@ -1044,14 +1044,15 @@ impl Build {
1044
1044
}
1045
1045
}
1046
1046
1047
+ /// Check if verbosity is greater than the `level`
1047
1048
pub fn is_verbose_than ( & self , level : usize ) -> bool {
1048
1049
self . verbosity > level
1049
1050
}
1050
1051
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 ( ) ) {
1053
1054
if self . is_verbose_than ( level) {
1054
- println ! ( "{msg}" ) ;
1055
+ f ( )
1055
1056
}
1056
1057
}
1057
1058
@@ -1627,7 +1628,7 @@ impl Build {
1627
1628
if self . config . dry_run ( ) {
1628
1629
return ;
1629
1630
}
1630
- self . verbose_than ( 1 , & format ! ( "Copy {src:?} to {dst:?}" ) ) ;
1631
+ self . verbose_than ( 1 , || println ! ( "Copy {src:?} to {dst:?}" ) ) ;
1631
1632
if src == dst {
1632
1633
return ;
1633
1634
}
@@ -1718,7 +1719,7 @@ impl Build {
1718
1719
return ;
1719
1720
}
1720
1721
let dst = dstdir. join ( src. file_name ( ) . unwrap ( ) ) ;
1721
- self . verbose_than ( 1 , & format ! ( "Install {src:?} to {dst:?}" ) ) ;
1722
+ self . verbose_than ( 1 , || println ! ( "Install {src:?} to {dst:?}" ) ) ;
1722
1723
t ! ( fs:: create_dir_all( dstdir) ) ;
1723
1724
if !src. exists ( ) {
1724
1725
panic ! ( "ERROR: File \" {}\" not found!" , src. display( ) ) ;
0 commit comments