@@ -38,7 +38,7 @@ impl Config {
38
38
}
39
39
40
40
pub ( crate ) fn remove ( & self , f : & Path ) {
41
- remove ( self . dry_run ( ) , f) ;
41
+ remove ( & self . exec_ctx , f) ;
42
42
}
43
43
44
44
/// Create a temporary directory in `out` and return its path.
@@ -74,13 +74,13 @@ impl Config {
74
74
}
75
75
76
76
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) ;
78
78
}
79
79
80
80
/// Returns whether the SHA256 checksum of `path` matches `expected`.
81
81
#[ cfg( test) ]
82
82
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)
84
84
}
85
85
}
86
86
@@ -414,12 +414,10 @@ pub(crate) struct DownloadContext<'a> {
414
414
out : & ' a Path ,
415
415
patch_binaries_for_nix : Option < bool > ,
416
416
exec_ctx : & ' a ExecutionContext ,
417
- verbose : bool ,
418
417
stage0_metadata : & ' a build_helper:: stage0_parser:: Stage0 ,
419
418
llvm_assertions : bool ,
420
419
bootstrap_cache_path : & ' a Option < PathBuf > ,
421
420
is_running_on_ci : bool ,
422
- dry_run : bool ,
423
421
}
424
422
425
423
impl < ' a > AsRef < DownloadContext < ' a > > for DownloadContext < ' a > {
@@ -435,12 +433,10 @@ impl<'a> From<&'a Config> for DownloadContext<'a> {
435
433
out : & value. out ,
436
434
patch_binaries_for_nix : value. patch_binaries_for_nix ,
437
435
exec_ctx : & value. exec_ctx ,
438
- verbose : value. verbose > 0 ,
439
436
stage0_metadata : & value. stage0_metadata ,
440
437
llvm_assertions : value. llvm_assertions ,
441
438
bootstrap_cache_path : & value. bootstrap_cache_path ,
442
439
is_running_on_ci : value. is_running_on_ci ,
443
- dry_run : value. dry_run ( ) ,
444
440
}
445
441
}
446
442
}
@@ -508,7 +504,7 @@ pub(crate) fn maybe_download_rustfmt<'a>(
508
504
509
505
let dwn_ctx = dwn_ctx. as_ref ( ) ;
510
506
511
- if dwn_ctx. dry_run {
507
+ if dwn_ctx. exec_ctx . dry_run ( ) {
512
508
return Some ( PathBuf :: new ( ) ) ;
513
509
}
514
510
@@ -563,9 +559,9 @@ pub(crate) fn download_beta_toolchain<'a>(dwn_ctx: impl AsRef<DownloadContext<'a
563
559
#[ cfg( not( test) ) ]
564
560
pub ( crate ) fn download_beta_toolchain < ' a > ( dwn_ctx : impl AsRef < DownloadContext < ' a > > ) {
565
561
let dwn_ctx = dwn_ctx. as_ref ( ) ;
566
- if dwn_ctx. verbose {
562
+ dwn_ctx. exec_ctx . verbose ( || {
567
563
println ! ( "downloading stage0 beta artifacts" ) ;
568
- }
564
+ } ) ;
569
565
570
566
let date = dwn_ctx. stage0_metadata . compiler . date . clone ( ) ;
571
567
let version = dwn_ctx. stage0_metadata . compiler . version . clone ( ) ;
@@ -634,8 +630,8 @@ fn download_toolchain<'a>(
634
630
}
635
631
}
636
632
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 ( ) {
639
635
return ;
640
636
}
641
637
fs:: remove_file ( f) . unwrap_or_else ( |_| panic ! ( "failed to remove {f:?}" ) ) ;
@@ -757,7 +753,7 @@ fn download_component<'a>(
757
753
) {
758
754
let dwn_ctx = dwn_ctx. as_ref ( ) ;
759
755
760
- if dwn_ctx. dry_run {
756
+ if dwn_ctx. exec_ctx . dry_run ( ) {
761
757
return ;
762
758
}
763
759
@@ -802,22 +798,22 @@ fn download_component<'a>(
802
798
) ;
803
799
let sha256 = dwn_ctx. stage0_metadata . checksums_sha256 . get ( & url) . expect ( & error) ;
804
800
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) ;
807
803
return ;
808
804
} else {
809
- if dwn_ctx. verbose {
805
+ dwn_ctx. exec_ctx . verbose ( || {
810
806
println ! (
811
807
"ignoring cached file {} due to failed verification" ,
812
808
tarball. display( )
813
809
)
814
- }
815
- remove ( dwn_ctx. dry_run , & tarball) ;
810
+ } ) ;
811
+ remove ( dwn_ctx. exec_ctx , & tarball) ;
816
812
}
817
813
}
818
814
Some ( sha256)
819
815
} else if tarball. exists ( ) {
820
- unpack ( dwn_ctx. verbose , & tarball, & bin_root, prefix) ;
816
+ unpack ( dwn_ctx. exec_ctx , & tarball, & bin_root, prefix) ;
821
817
return ;
822
818
} else {
823
819
None
@@ -836,22 +832,22 @@ download-rustc = false
836
832
}
837
833
download_file ( dwn_ctx, & format ! ( "{base_url}/{url}" ) , & tarball, help_on_error) ;
838
834
if let Some ( sha256) = checksum
839
- && !verify ( dwn_ctx. verbose , dwn_ctx . dry_run , & tarball, sha256)
835
+ && !verify ( dwn_ctx. exec_ctx , & tarball, sha256)
840
836
{
841
837
panic ! ( "failed to verify {}" , tarball. display( ) ) ;
842
838
}
843
839
844
- unpack ( dwn_ctx. verbose , & tarball, & bin_root, prefix) ;
840
+ unpack ( dwn_ctx. exec_ctx , & tarball, & bin_root, prefix) ;
845
841
}
846
842
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 {
848
844
use sha2:: Digest ;
849
845
850
- if verbose {
846
+ exec_ctx . verbose ( || {
851
847
println ! ( "verifying {}" , path. display( ) ) ;
852
- }
848
+ } ) ;
853
849
854
- if dry_run {
850
+ if exec_ctx . dry_run ( ) {
855
851
return false ;
856
852
}
857
853
@@ -885,7 +881,7 @@ pub(crate) fn verify(verbose: bool, dry_run: bool, path: &Path, expected: &str)
885
881
verified
886
882
}
887
883
888
- fn unpack ( verbose : bool , tarball : & Path , dst : & Path , pattern : & str ) {
884
+ fn unpack ( exec_ctx : & ExecutionContext , tarball : & Path , dst : & Path , pattern : & str ) {
889
885
eprintln ! ( "extracting {} to {}" , tarball. display( ) , dst. display( ) ) ;
890
886
if !dst. exists ( ) {
891
887
t ! ( fs:: create_dir_all( dst) ) ;
@@ -927,9 +923,10 @@ fn unpack(verbose: bool, tarball: &Path, dst: &Path, pattern: &str) {
927
923
}
928
924
short_path = short_path. strip_prefix ( pattern) . unwrap_or ( short_path) ;
929
925
let dst_path = dst. join ( short_path) ;
930
- if verbose {
926
+
927
+ exec_ctx. verbose ( || {
931
928
println ! ( "extracting {} to {}" , original_path. display( ) , dst. display( ) ) ;
932
- }
929
+ } ) ;
933
930
934
931
if !t ! ( member. unpack_in( dst) ) {
935
932
panic ! ( "path traversal attack ??" ) ;
@@ -957,9 +954,9 @@ fn download_file<'a>(
957
954
) {
958
955
let dwn_ctx = dwn_ctx. as_ref ( ) ;
959
956
960
- if dwn_ctx. verbose {
957
+ dwn_ctx. exec_ctx . verbose ( || {
961
958
println ! ( "download {url}" ) ;
962
- }
959
+ } ) ;
963
960
// Use a temporary file in case we crash while downloading, to avoid a corrupt download in cache/.
964
961
let tempfile = tempdir ( dwn_ctx. out ) . join ( dest_path. file_name ( ) . unwrap ( ) ) ;
965
962
// While bootstrap itself only supports http and https downloads, downstream forks might
0 commit comments