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