@@ -47,7 +47,7 @@ use std::process::{self, Command};
47
47
48
48
pub struct InstallOpts < ' a > {
49
49
pub default_host_triple : Option < String > ,
50
- pub default_toolchain : String ,
50
+ pub default_toolchain : Option < String > ,
51
51
pub profile : String ,
52
52
pub no_modify_path : bool ,
53
53
pub components : & ' a [ & ' a str ] ,
@@ -283,9 +283,9 @@ pub fn install(no_prompt: bool, verbose: bool, quiet: bool, mut opts: InstallOpt
283
283
}
284
284
utils:: create_rustup_home ( ) ?;
285
285
maybe_install_rust (
286
- & opts. default_toolchain ,
286
+ opts. default_toolchain . as_deref ( ) ,
287
287
& opts. profile ,
288
- opts. default_host_triple . as_ref ( ) ,
288
+ opts. default_host_triple . as_deref ( ) ,
289
289
opts. components ,
290
290
opts. targets ,
291
291
verbose,
@@ -440,10 +440,10 @@ fn do_pre_install_options_sanity_checks(opts: &InstallOpts) -> Result<()> {
440
440
. as_ref ( )
441
441
. map ( |s| dist:: TargetTriple :: new ( s) )
442
442
. unwrap_or_else ( TargetTriple :: from_host_or_build) ;
443
- let toolchain_to_use = if opts. default_toolchain == "none" {
444
- "stable"
445
- } else {
446
- & opts . default_toolchain
443
+ let toolchain_to_use = match & opts. default_toolchain {
444
+ None => "stable" ,
445
+ Some ( s ) if s == "none" => "stable" ,
446
+ Some ( s ) => & s ,
447
447
} ;
448
448
let partial_channel = dist:: PartialToolchainDesc :: from_str ( toolchain_to_use) ?;
449
449
let resolved = partial_channel. resolve ( & host_triple) ?. to_string ( ) ;
@@ -590,7 +590,9 @@ fn current_install_opts(opts: &InstallOpts) -> String {
590
590
. as_ref( )
591
591
. map( |s| TargetTriple :: new( s) )
592
592
. unwrap_or_else( TargetTriple :: from_host_or_build) ,
593
- opts. default_toolchain,
593
+ opts. default_toolchain
594
+ . as_deref( )
595
+ . unwrap_or( "stable (default)" ) ,
594
596
opts. profile,
595
597
if !opts. no_modify_path { "yes" } else { "no" }
596
598
)
@@ -612,10 +614,10 @@ fn customize_install(mut opts: InstallOpts) -> Result<InstallOpts> {
612
614
. unwrap_or_else ( || TargetTriple :: from_host_or_build ( ) . to_string ( ) ) ,
613
615
) ?) ;
614
616
615
- opts. default_toolchain = common:: question_str (
617
+ opts. default_toolchain = Some ( common:: question_str (
616
618
"Default toolchain? (stable/beta/nightly/none)" ,
617
- & opts. default_toolchain ,
618
- ) ?;
619
+ opts. default_toolchain . as_deref ( ) . unwrap_or ( "stable" ) ,
620
+ ) ?) ;
619
621
620
622
opts. profile = common:: question_str (
621
623
& format ! (
@@ -727,9 +729,9 @@ pub fn install_proxies() -> Result<()> {
727
729
}
728
730
729
731
fn maybe_install_rust (
730
- toolchain_str : & str ,
732
+ toolchain : Option < & str > ,
731
733
profile_str : & str ,
732
- default_host_triple : Option < & String > ,
734
+ default_host_triple : Option < & str > ,
733
735
components : & [ & str ] ,
734
736
targets : & [ & str ] ,
735
737
verbose : bool ,
@@ -746,21 +748,29 @@ fn maybe_install_rust(
746
748
info ! ( "default host triple is {}" , cfg. get_default_host_triple( ) ?) ;
747
749
}
748
750
749
- // If there is already an install, then `toolchain_str` may not be
750
- // a toolchain the user actually wants. Don't do anything. FIXME:
751
- // This logic should be part of InstallOpts so that it isn't
752
- // possible to select a toolchain then have it not be installed.
753
- if toolchain_str == "none" {
751
+ let user_specified_something =
752
+ toolchain. is_some ( ) || !targets. is_empty ( ) || !components. is_empty ( ) ;
753
+
754
+ // If the user specified they want no toolchain, we skip this, otherwise
755
+ // if they specify something directly, or we have no default, then we install
756
+ // a toolchain (updating if it's already present) and then if neither of
757
+ // those are true, we have a user who doesn't mind, and already has an
758
+ // install, so we leave their setup alone.
759
+ if toolchain == Some ( "none" ) {
754
760
info ! ( "skipping toolchain installation" ) ;
755
761
println ! ( ) ;
756
- } else if cfg. find_default ( ) ?. is_none ( ) {
762
+ } else if user_specified_something || cfg. find_default ( ) ?. is_none ( ) {
763
+ let toolchain_str = toolchain. unwrap_or ( "stable" ) ;
757
764
let toolchain = cfg. get_toolchain ( toolchain_str, false ) ?;
765
+ if toolchain. exists ( ) {
766
+ warn ! ( "Updating existing toolchain, profile choice will be ignored" ) ;
767
+ }
758
768
let status = toolchain. install_from_dist ( true , false , components, targets) ?;
759
769
cfg. set_default ( toolchain_str) ?;
760
770
println ! ( ) ;
761
771
common:: show_channel_update ( & cfg, toolchain_str, Ok ( status) ) ?;
762
772
} else {
763
- info ! ( "updating existing rustup installation" ) ;
773
+ info ! ( "updating existing rustup installation - leaving toolchains alone " ) ;
764
774
println ! ( ) ;
765
775
}
766
776
0 commit comments