@@ -462,6 +462,7 @@ pub(crate) async fn install(
462
462
}
463
463
}
464
464
465
+ let no_modify_path = opts. no_modify_path ;
465
466
let install_res = move || async move {
466
467
install_bins ( ) ?;
467
468
@@ -483,19 +484,7 @@ pub(crate) async fn install(
483
484
fs:: create_dir_all ( home) . context ( "unable to create ~/.rustup" ) ?;
484
485
}
485
486
486
- maybe_install_rust (
487
- opts. default_toolchain ,
488
- & opts. profile ,
489
- opts. default_host_triple . as_deref ( ) ,
490
- !opts. no_update_toolchain ,
491
- opts. components ,
492
- opts. targets ,
493
- current_dir,
494
- verbose,
495
- quiet,
496
- )
497
- . await ?;
498
-
487
+ maybe_install_rust ( current_dir, verbose, quiet, opts) . await ?;
499
488
Ok ( utils:: ExitCode ( 0 ) )
500
489
} ;
501
490
@@ -518,7 +507,7 @@ pub(crate) async fn install(
518
507
#[ cfg( windows) ]
519
508
let cargo_home = cargo_home. replace ( '\\' , r"\\" ) ;
520
509
#[ cfg( windows) ]
521
- let msg = if opts . no_modify_path {
510
+ let msg = if no_modify_path {
522
511
format ! (
523
512
post_install_msg_win_no_modify_path!( ) ,
524
513
cargo_home = cargo_home
@@ -527,7 +516,7 @@ pub(crate) async fn install(
527
516
format ! ( post_install_msg_win!( ) , cargo_home = cargo_home)
528
517
} ;
529
518
#[ cfg( not( windows) ) ]
530
- let msg = if opts . no_modify_path {
519
+ let msg = if no_modify_path {
531
520
format ! (
532
521
post_install_msg_unix_no_modify_path!( ) ,
533
522
cargo_home = cargo_home
@@ -856,27 +845,15 @@ pub(crate) fn install_proxies() -> Result<()> {
856
845
}
857
846
858
847
async fn maybe_install_rust (
859
- toolchain : Option < MaybeOfficialToolchainName > ,
860
- profile_str : & str ,
861
- default_host_triple : Option < & str > ,
862
- update_existing_toolchain : bool ,
863
- components : & [ & str ] ,
864
- targets : & [ & str ] ,
865
848
current_dir : PathBuf ,
866
849
verbose : bool ,
867
850
quiet : bool ,
851
+ opts : InstallOpts < ' _ > ,
868
852
) -> Result < ( ) > {
869
853
let mut cfg = common:: set_globals ( current_dir, verbose, quiet) ?;
870
854
871
- let toolchain = _install_selection (
872
- & mut cfg,
873
- toolchain,
874
- profile_str,
875
- default_host_triple,
876
- update_existing_toolchain,
877
- components,
878
- targets,
879
- ) ?;
855
+ let ( components, targets) = ( opts. components , opts. targets ) ;
856
+ let toolchain = _install_selection ( opts, & mut cfg) ?;
880
857
if let Some ( ref desc) = toolchain {
881
858
let status = if Toolchain :: exists ( & cfg, & desc. into ( ) ) ? {
882
859
warn ! ( "Updating existing toolchain, profile choice will be ignored" ) ;
@@ -909,37 +886,39 @@ async fn maybe_install_rust(
909
886
Ok ( ( ) )
910
887
}
911
888
912
- fn _install_selection (
913
- cfg : & mut Cfg ,
914
- toolchain_opt : Option < MaybeOfficialToolchainName > ,
915
- profile_str : & str ,
916
- default_host_triple : Option < & str > ,
917
- update_existing_toolchain : bool ,
918
- components : & [ & str ] ,
919
- targets : & [ & str ] ,
920
- ) -> Result < Option < ToolchainDesc > > {
921
- cfg. set_profile ( profile_str) ?;
922
-
923
- if let Some ( default_host_triple) = default_host_triple {
889
+ fn _install_selection ( opts : InstallOpts < ' _ > , cfg : & mut Cfg ) -> Result < Option < ToolchainDesc > > {
890
+ let InstallOpts {
891
+ default_host_triple,
892
+ default_toolchain,
893
+ profile,
894
+ no_modify_path : _no_modify_path,
895
+ no_update_toolchain,
896
+ components,
897
+ targets,
898
+ } = opts;
899
+
900
+ cfg. set_profile ( & profile) ?;
901
+
902
+ if let Some ( default_host_triple) = & default_host_triple {
924
903
// Set host triple now as it will affect resolution of toolchain_str
925
904
info ! ( "setting default host triple to {}" , default_host_triple) ;
926
905
cfg. set_default_host_triple ( default_host_triple. to_owned ( ) ) ?;
927
906
} else {
928
907
info ! ( "default host triple is {}" , cfg. get_default_host_triple( ) ?) ;
929
908
}
930
909
931
- let user_specified_something = toolchain_opt . is_some ( )
910
+ let user_specified_something = default_toolchain . is_some ( )
932
911
|| !targets. is_empty ( )
933
912
|| !components. is_empty ( )
934
- || update_existing_toolchain ;
913
+ || !no_update_toolchain ;
935
914
936
915
// If the user specified they want no toolchain, we skip this, otherwise
937
916
// if they specify something directly, or we have no default, then we install
938
917
// a toolchain (updating if it's already present) and then if neither of
939
918
// those are true, we have a user who doesn't mind, and already has an
940
919
// install, so we leave their setup alone.
941
920
Ok (
942
- if matches ! ( toolchain_opt , Some ( MaybeOfficialToolchainName :: None ) ) {
921
+ if matches ! ( default_toolchain , Some ( MaybeOfficialToolchainName :: None ) ) {
943
922
info ! ( "skipping toolchain installation" ) ;
944
923
if !components. is_empty ( ) {
945
924
warn ! (
@@ -958,9 +937,9 @@ fn _install_selection(
958
937
writeln ! ( process( ) . stdout( ) . lock( ) ) ?;
959
938
None
960
939
} else if user_specified_something
961
- || ( update_existing_toolchain && cfg. find_default ( ) ?. is_none ( ) )
940
+ || ( !no_update_toolchain && cfg. find_default ( ) ?. is_none ( ) )
962
941
{
963
- match toolchain_opt {
942
+ match default_toolchain {
964
943
Some ( s) => {
965
944
let toolchain_name = match s {
966
945
MaybeOfficialToolchainName :: None => unreachable ! ( ) ,
@@ -1350,6 +1329,7 @@ mod tests {
1350
1329
use rustup_macros:: unit_test as test;
1351
1330
1352
1331
use crate :: cli:: common;
1332
+ use crate :: cli:: self_update:: InstallOpts ;
1353
1333
use crate :: dist:: dist:: PartialToolchainDesc ;
1354
1334
use crate :: test:: { test_dir, with_rustup_home, Env } ;
1355
1335
use crate :: { currentprocess, for_host} ;
@@ -1363,6 +1343,17 @@ mod tests {
1363
1343
vars,
1364
1344
..Default :: default ( )
1365
1345
} ;
1346
+
1347
+ let opts = InstallOpts {
1348
+ default_host_triple : None ,
1349
+ default_toolchain : None , // No toolchain specified
1350
+ profile : "default" . to_owned ( ) , // default profile
1351
+ no_modify_path : false ,
1352
+ components : & [ ] ,
1353
+ targets : & [ ] ,
1354
+ no_update_toolchain : false ,
1355
+ } ;
1356
+
1366
1357
currentprocess:: with ( tp. clone ( ) . into ( ) , || -> Result < ( ) > {
1367
1358
// TODO: we could pass in a custom cfg to get notification
1368
1359
// callbacks rather than output to the tp sink.
@@ -1373,17 +1364,9 @@ mod tests {
1373
1364
. unwrap( )
1374
1365
. resolve( & cfg. get_default_host_triple( ) . unwrap( ) )
1375
1366
. unwrap( ) ,
1376
- super :: _install_selection(
1377
- & mut cfg,
1378
- None , // No toolchain specified
1379
- "default" , // default profile
1380
- None ,
1381
- true ,
1382
- & [ ] ,
1383
- & [ ] ,
1384
- )
1385
- . unwrap( ) // result
1386
- . unwrap( ) // option
1367
+ super :: _install_selection( opts, & mut cfg)
1368
+ . unwrap( ) // result
1369
+ . unwrap( ) // option
1387
1370
) ;
1388
1371
Ok ( ( ) )
1389
1372
} ) ?;
0 commit comments