@@ -38,7 +38,7 @@ impl Config {
3838 }
3939
4040 pub ( crate ) fn remove ( & self , f : & Path ) {
41- remove ( self . dry_run ( ) , f) ;
41+ remove ( & self . exec_ctx , f) ;
4242 }
4343
4444 /// Create a temporary directory in `out` and return its path.
@@ -74,13 +74,13 @@ impl Config {
7474 }
7575
7676 fn unpack ( & self , tarball : & Path , dst : & Path , pattern : & str ) {
77- unpack ( self . verbose > 0 , tarball, dst, pattern) ;
77+ unpack ( & self . exec_ctx , tarball, dst, pattern) ;
7878 }
7979
8080 /// Returns whether the SHA256 checksum of `path` matches `expected`.
8181 #[ cfg( test) ]
8282 pub ( crate ) fn verify ( & self , path : & Path , expected : & str ) -> bool {
83- verify ( self . verbose > 0 , self . dry_run ( ) , path, expected)
83+ verify ( & self . exec_ctx , path, expected)
8484 }
8585}
8686
@@ -414,12 +414,10 @@ pub(crate) struct DownloadContext<'a> {
414414 out : & ' a Path ,
415415 patch_binaries_for_nix : Option < bool > ,
416416 exec_ctx : & ' a ExecutionContext ,
417- verbose : bool ,
418417 stage0_metadata : & ' a build_helper:: stage0_parser:: Stage0 ,
419418 llvm_assertions : bool ,
420419 bootstrap_cache_path : & ' a Option < PathBuf > ,
421420 is_running_on_ci : bool ,
422- dry_run : bool ,
423421}
424422
425423impl < ' a > AsRef < DownloadContext < ' a > > for DownloadContext < ' a > {
@@ -435,12 +433,10 @@ impl<'a> From<&'a Config> for DownloadContext<'a> {
435433 out : & value. out ,
436434 patch_binaries_for_nix : value. patch_binaries_for_nix ,
437435 exec_ctx : & value. exec_ctx ,
438- verbose : value. verbose > 0 ,
439436 stage0_metadata : & value. stage0_metadata ,
440437 llvm_assertions : value. llvm_assertions ,
441438 bootstrap_cache_path : & value. bootstrap_cache_path ,
442439 is_running_on_ci : value. is_running_on_ci ,
443- dry_run : value. dry_run ( ) ,
444440 }
445441 }
446442}
@@ -508,7 +504,7 @@ pub(crate) fn maybe_download_rustfmt<'a>(
508504
509505 let dwn_ctx = dwn_ctx. as_ref ( ) ;
510506
511- if dwn_ctx. dry_run {
507+ if dwn_ctx. exec_ctx . dry_run ( ) {
512508 return Some ( PathBuf :: new ( ) ) ;
513509 }
514510
@@ -563,9 +559,9 @@ pub(crate) fn download_beta_toolchain<'a>(dwn_ctx: impl AsRef<DownloadContext<'a
563559#[ cfg( not( test) ) ]
564560pub ( crate ) fn download_beta_toolchain < ' a > ( dwn_ctx : impl AsRef < DownloadContext < ' a > > ) {
565561 let dwn_ctx = dwn_ctx. as_ref ( ) ;
566- if dwn_ctx. verbose {
562+ dwn_ctx. exec_ctx . verbose ( || {
567563 println ! ( "downloading stage0 beta artifacts" ) ;
568- }
564+ } ) ;
569565
570566 let date = dwn_ctx. stage0_metadata . compiler . date . clone ( ) ;
571567 let version = dwn_ctx. stage0_metadata . compiler . version . clone ( ) ;
@@ -634,8 +630,8 @@ fn download_toolchain<'a>(
634630 }
635631}
636632
637- pub ( crate ) fn remove ( dry_run : bool , f : & Path ) {
638- if dry_run {
633+ pub ( crate ) fn remove ( exec_ctx : & ExecutionContext , f : & Path ) {
634+ if exec_ctx . dry_run ( ) {
639635 return ;
640636 }
641637 fs:: remove_file ( f) . unwrap_or_else ( |_| panic ! ( "failed to remove {f:?}" ) ) ;
@@ -757,7 +753,7 @@ fn download_component<'a>(
757753) {
758754 let dwn_ctx = dwn_ctx. as_ref ( ) ;
759755
760- if dwn_ctx. dry_run {
756+ if dwn_ctx. exec_ctx . dry_run ( ) {
761757 return ;
762758 }
763759
@@ -802,22 +798,22 @@ fn download_component<'a>(
802798 ) ;
803799 let sha256 = dwn_ctx. stage0_metadata . checksums_sha256 . get ( & url) . expect ( & error) ;
804800 if tarball. exists ( ) {
805- if verify ( dwn_ctx. verbose , dwn_ctx . dry_run , & tarball, sha256) {
806- unpack ( dwn_ctx. verbose , & tarball, & bin_root, prefix) ;
801+ if verify ( dwn_ctx. exec_ctx , & tarball, sha256) {
802+ unpack ( dwn_ctx. exec_ctx , & tarball, & bin_root, prefix) ;
807803 return ;
808804 } else {
809- if dwn_ctx. verbose {
805+ dwn_ctx. exec_ctx . verbose ( || {
810806 println ! (
811807 "ignoring cached file {} due to failed verification" ,
812808 tarball. display( )
813809 )
814- }
815- remove ( dwn_ctx. dry_run , & tarball) ;
810+ } ) ;
811+ remove ( dwn_ctx. exec_ctx , & tarball) ;
816812 }
817813 }
818814 Some ( sha256)
819815 } else if tarball. exists ( ) {
820- unpack ( dwn_ctx. verbose , & tarball, & bin_root, prefix) ;
816+ unpack ( dwn_ctx. exec_ctx , & tarball, & bin_root, prefix) ;
821817 return ;
822818 } else {
823819 None
@@ -836,22 +832,22 @@ download-rustc = false
836832 }
837833 download_file ( dwn_ctx, & format ! ( "{base_url}/{url}" ) , & tarball, help_on_error) ;
838834 if let Some ( sha256) = checksum
839- && !verify ( dwn_ctx. verbose , dwn_ctx . dry_run , & tarball, sha256)
835+ && !verify ( dwn_ctx. exec_ctx , & tarball, sha256)
840836 {
841837 panic ! ( "failed to verify {}" , tarball. display( ) ) ;
842838 }
843839
844- unpack ( dwn_ctx. verbose , & tarball, & bin_root, prefix) ;
840+ unpack ( dwn_ctx. exec_ctx , & tarball, & bin_root, prefix) ;
845841}
846842
847- pub ( crate ) fn verify ( verbose : bool , dry_run : bool , path : & Path , expected : & str ) -> bool {
843+ pub ( crate ) fn verify ( exec_ctx : & ExecutionContext , path : & Path , expected : & str ) -> bool {
848844 use sha2:: Digest ;
849845
850- if verbose {
846+ exec_ctx . verbose ( || {
851847 println ! ( "verifying {}" , path. display( ) ) ;
852- }
848+ } ) ;
853849
854- if dry_run {
850+ if exec_ctx . dry_run ( ) {
855851 return false ;
856852 }
857853
@@ -885,7 +881,7 @@ pub(crate) fn verify(verbose: bool, dry_run: bool, path: &Path, expected: &str)
885881 verified
886882}
887883
888- fn unpack ( verbose : bool , tarball : & Path , dst : & Path , pattern : & str ) {
884+ fn unpack ( exec_ctx : & ExecutionContext , tarball : & Path , dst : & Path , pattern : & str ) {
889885 eprintln ! ( "extracting {} to {}" , tarball. display( ) , dst. display( ) ) ;
890886 if !dst. exists ( ) {
891887 t ! ( fs:: create_dir_all( dst) ) ;
@@ -927,9 +923,10 @@ fn unpack(verbose: bool, tarball: &Path, dst: &Path, pattern: &str) {
927923 }
928924 short_path = short_path. strip_prefix ( pattern) . unwrap_or ( short_path) ;
929925 let dst_path = dst. join ( short_path) ;
930- if verbose {
926+
927+ exec_ctx. verbose ( || {
931928 println ! ( "extracting {} to {}" , original_path. display( ) , dst. display( ) ) ;
932- }
929+ } ) ;
933930
934931 if !t ! ( member. unpack_in( dst) ) {
935932 panic ! ( "path traversal attack ??" ) ;
@@ -957,9 +954,9 @@ fn download_file<'a>(
957954) {
958955 let dwn_ctx = dwn_ctx. as_ref ( ) ;
959956
960- if dwn_ctx. verbose {
957+ dwn_ctx. exec_ctx . verbose ( || {
961958 println ! ( "download {url}" ) ;
962- }
959+ } ) ;
963960 // Use a temporary file in case we crash while downloading, to avoid a corrupt download in cache/.
964961 let tempfile = tempdir ( dwn_ctx. out ) . join ( dest_path. file_name ( ) . unwrap ( ) ) ;
965962 // While bootstrap itself only supports http and https downloads, downstream forks might
0 commit comments