@@ -297,7 +297,7 @@ impl<'gctx> InstallablePackage<'gctx> {
297
297
Ok ( duplicates)
298
298
}
299
299
300
- fn install_one ( mut self ) -> CargoResult < bool > {
300
+ fn install_one ( mut self , dry_run : bool ) -> CargoResult < bool > {
301
301
self . gctx . shell ( ) . status ( "Installing" , & self . pkg ) ?;
302
302
303
303
let dst = self . root . join ( "bin" ) . into_path_unlocked ( ) ;
@@ -321,6 +321,7 @@ impl<'gctx> InstallablePackage<'gctx> {
321
321
self . check_yanked_install ( ) ?;
322
322
323
323
let exec: Arc < dyn Executor > = Arc :: new ( DefaultExecutor ) ;
324
+ self . opts . build_config . dry_run = dry_run;
324
325
let compile = ops:: compile_ws ( & self . ws , & self . opts , & exec) . with_context ( || {
325
326
if let Some ( td) = td_opt. take ( ) {
326
327
// preserve the temporary directory, so the user can inspect it
@@ -422,7 +423,7 @@ impl<'gctx> InstallablePackage<'gctx> {
422
423
for & ( bin, src) in binaries. iter ( ) {
423
424
let dst = staging_dir. path ( ) . join ( bin) ;
424
425
// Try to move if `target_dir` is transient.
425
- if !self . source_id . is_path ( ) && fs:: rename ( src, & dst) . is_ok ( ) {
426
+ if ( !self . source_id . is_path ( ) && fs:: rename ( src, & dst) . is_ok ( ) ) || dry_run {
426
427
continue ;
427
428
}
428
429
paths:: copy ( src, & dst) ?;
@@ -441,11 +442,13 @@ impl<'gctx> InstallablePackage<'gctx> {
441
442
let src = staging_dir. path ( ) . join ( bin) ;
442
443
let dst = dst. join ( bin) ;
443
444
self . gctx . shell ( ) . status ( "Installing" , dst. display ( ) ) ?;
444
- fs:: rename ( & src, & dst) . with_context ( || {
445
- format ! ( "failed to move `{}` to `{}`" , src. display( ) , dst. display( ) )
446
- } ) ?;
447
- installed. bins . push ( dst) ;
448
- successful_bins. insert ( bin. to_string ( ) ) ;
445
+ if !dry_run {
446
+ fs:: rename ( & src, & dst) . with_context ( || {
447
+ format ! ( "failed to move `{}` to `{}`" , src. display( ) , dst. display( ) )
448
+ } ) ?;
449
+ installed. bins . push ( dst) ;
450
+ successful_bins. insert ( bin. to_string ( ) ) ;
451
+ }
449
452
}
450
453
451
454
// Repeat for binaries which replace existing ones but don't pop the error
@@ -456,10 +459,12 @@ impl<'gctx> InstallablePackage<'gctx> {
456
459
let src = staging_dir. path ( ) . join ( bin) ;
457
460
let dst = dst. join ( bin) ;
458
461
self . gctx . shell ( ) . status ( "Replacing" , dst. display ( ) ) ?;
459
- fs:: rename ( & src, & dst) . with_context ( || {
460
- format ! ( "failed to move `{}` to `{}`" , src. display( ) , dst. display( ) )
461
- } ) ?;
462
- successful_bins. insert ( bin. to_string ( ) ) ;
462
+ if !dry_run {
463
+ fs:: rename ( & src, & dst) . with_context ( || {
464
+ format ! ( "failed to move `{}` to `{}`" , src. display( ) , dst. display( ) )
465
+ } ) ?;
466
+ successful_bins. insert ( bin. to_string ( ) ) ;
467
+ }
463
468
}
464
469
Ok ( ( ) )
465
470
} ;
@@ -476,9 +481,14 @@ impl<'gctx> InstallablePackage<'gctx> {
476
481
& self . rustc . verbose_version ,
477
482
) ;
478
483
479
- if let Err ( e) =
480
- remove_orphaned_bins ( & self . ws , & mut tracker, & duplicates, & self . pkg , & dst)
481
- {
484
+ if let Err ( e) = remove_orphaned_bins (
485
+ & self . ws ,
486
+ & mut tracker,
487
+ & duplicates,
488
+ & self . pkg ,
489
+ & dst,
490
+ dry_run,
491
+ ) {
482
492
// Don't hard error on remove.
483
493
self . gctx
484
494
. shell ( )
@@ -515,7 +525,10 @@ impl<'gctx> InstallablePackage<'gctx> {
515
525
}
516
526
}
517
527
518
- if duplicates. is_empty ( ) {
528
+ if dry_run {
529
+ self . gctx . shell ( ) . warn ( "aborting install due to dry run" ) ?;
530
+ Ok ( true )
531
+ } else if duplicates. is_empty ( ) {
519
532
self . gctx . shell ( ) . status (
520
533
"Installed" ,
521
534
format ! (
@@ -620,6 +633,7 @@ pub fn install(
620
633
opts : & ops:: CompileOptions ,
621
634
force : bool ,
622
635
no_track : bool ,
636
+ dry_run : bool ,
623
637
) -> CargoResult < ( ) > {
624
638
let root = resolve_root ( root, gctx) ?;
625
639
let dst = root. join ( "bin" ) . into_path_unlocked ( ) ;
@@ -654,7 +668,7 @@ pub fn install(
654
668
) ?;
655
669
let mut installed_anything = true ;
656
670
if let Some ( installable_pkg) = installable_pkg {
657
- installed_anything = installable_pkg. install_one ( ) ?;
671
+ installed_anything = installable_pkg. install_one ( dry_run ) ?;
658
672
}
659
673
( installed_anything, false )
660
674
} else {
@@ -705,7 +719,7 @@ pub fn install(
705
719
706
720
let install_results: Vec < _ > = pkgs_to_install
707
721
. into_iter ( )
708
- . map ( |( krate, installable_pkg) | ( krate, installable_pkg. install_one ( ) ) )
722
+ . map ( |( krate, installable_pkg) | ( krate, installable_pkg. install_one ( dry_run ) ) )
709
723
. collect ( ) ;
710
724
711
725
for ( krate, result) in install_results {
@@ -857,6 +871,7 @@ fn remove_orphaned_bins(
857
871
duplicates : & BTreeMap < String , Option < PackageId > > ,
858
872
pkg : & Package ,
859
873
dst : & Path ,
874
+ dry_run : bool ,
860
875
) -> CargoResult < ( ) > {
861
876
let filter = ops:: CompileFilter :: new_all_targets ( ) ;
862
877
let all_self_names = exe_names ( pkg, & filter) ;
@@ -894,8 +909,10 @@ fn remove_orphaned_bins(
894
909
old_pkg
895
910
) ,
896
911
) ?;
897
- paths:: remove_file ( & full_path)
898
- . with_context ( || format ! ( "failed to remove {:?}" , full_path) ) ?;
912
+ if !dry_run {
913
+ paths:: remove_file ( & full_path)
914
+ . with_context ( || format ! ( "failed to remove {:?}" , full_path) ) ?;
915
+ }
899
916
}
900
917
}
901
918
}
0 commit comments