@@ -96,6 +96,87 @@ pub(crate) struct InstallOpts<'a> {
96
96
}
97
97
98
98
impl < ' a > InstallOpts < ' a > {
99
+ fn install ( self , cfg : & mut Cfg ) -> Result < Option < ToolchainDesc > > {
100
+ let Self {
101
+ default_host_triple,
102
+ default_toolchain,
103
+ profile,
104
+ no_modify_path : _no_modify_path,
105
+ no_update_toolchain,
106
+ components,
107
+ targets,
108
+ } = self ;
109
+
110
+ cfg. set_profile ( & profile) ?;
111
+
112
+ if let Some ( default_host_triple) = & default_host_triple {
113
+ // Set host triple now as it will affect resolution of toolchain_str
114
+ info ! ( "setting default host triple to {}" , default_host_triple) ;
115
+ cfg. set_default_host_triple ( default_host_triple. to_owned ( ) ) ?;
116
+ } else {
117
+ info ! ( "default host triple is {}" , cfg. get_default_host_triple( ) ?) ;
118
+ }
119
+
120
+ let user_specified_something = default_toolchain. is_some ( )
121
+ || !targets. is_empty ( )
122
+ || !components. is_empty ( )
123
+ || !no_update_toolchain;
124
+
125
+ // If the user specified they want no toolchain, we skip this, otherwise
126
+ // if they specify something directly, or we have no default, then we install
127
+ // a toolchain (updating if it's already present) and then if neither of
128
+ // those are true, we have a user who doesn't mind, and already has an
129
+ // install, so we leave their setup alone.
130
+ Ok (
131
+ if matches ! ( default_toolchain, Some ( MaybeOfficialToolchainName :: None ) ) {
132
+ info ! ( "skipping toolchain installation" ) ;
133
+ if !components. is_empty ( ) {
134
+ warn ! (
135
+ "ignoring requested component{}: {}" ,
136
+ if components. len( ) == 1 { "" } else { "s" } ,
137
+ components. join( ", " )
138
+ ) ;
139
+ }
140
+ if !targets. is_empty ( ) {
141
+ warn ! (
142
+ "ignoring requested target{}: {}" ,
143
+ if targets. len( ) == 1 { "" } else { "s" } ,
144
+ targets. join( ", " )
145
+ ) ;
146
+ }
147
+ writeln ! ( process( ) . stdout( ) . lock( ) ) ?;
148
+ None
149
+ } else if user_specified_something
150
+ || ( !no_update_toolchain && cfg. find_default ( ) ?. is_none ( ) )
151
+ {
152
+ match default_toolchain {
153
+ Some ( s) => {
154
+ let toolchain_name = match s {
155
+ MaybeOfficialToolchainName :: None => unreachable ! ( ) ,
156
+ MaybeOfficialToolchainName :: Some ( n) => n,
157
+ } ;
158
+ Some ( toolchain_name. resolve ( & cfg. get_default_host_triple ( ) ?) ?)
159
+ }
160
+ None => match cfg. get_default ( ) ? {
161
+ // Default is installable
162
+ Some ( ToolchainName :: Official ( t) ) => Some ( t) ,
163
+ // Default is custom, presumably from a prior install. Do nothing.
164
+ Some ( ToolchainName :: Custom ( _) ) => None ,
165
+ None => Some (
166
+ "stable"
167
+ . parse :: < PartialToolchainDesc > ( ) ?
168
+ . resolve ( & cfg. get_default_host_triple ( ) ?) ?,
169
+ ) ,
170
+ } ,
171
+ }
172
+ } else {
173
+ info ! ( "updating existing rustup installation - leaving toolchains alone" ) ;
174
+ writeln ! ( process( ) . stdout( ) . lock( ) ) ?;
175
+ None
176
+ } ,
177
+ )
178
+ }
179
+
99
180
// Interactive editing of the install options
100
181
fn customize ( & mut self ) -> Result < ( ) > {
101
182
writeln ! (
@@ -846,7 +927,7 @@ async fn maybe_install_rust(
846
927
let mut cfg = common:: set_globals ( current_dir, verbose, quiet) ?;
847
928
848
929
let ( components, targets) = ( opts. components , opts. targets ) ;
849
- let toolchain = _install_selection ( opts, & mut cfg) ?;
930
+ let toolchain = opts. install ( & mut cfg) ?;
850
931
if let Some ( ref desc) = toolchain {
851
932
let status = if Toolchain :: exists ( & cfg, & desc. into ( ) ) ? {
852
933
warn ! ( "Updating existing toolchain, profile choice will be ignored" ) ;
@@ -879,87 +960,6 @@ async fn maybe_install_rust(
879
960
Ok ( ( ) )
880
961
}
881
962
882
- fn _install_selection ( opts : InstallOpts < ' _ > , cfg : & mut Cfg ) -> Result < Option < ToolchainDesc > > {
883
- let InstallOpts {
884
- default_host_triple,
885
- default_toolchain,
886
- profile,
887
- no_modify_path : _no_modify_path,
888
- no_update_toolchain,
889
- components,
890
- targets,
891
- } = opts;
892
-
893
- cfg. set_profile ( & profile) ?;
894
-
895
- if let Some ( default_host_triple) = & default_host_triple {
896
- // Set host triple now as it will affect resolution of toolchain_str
897
- info ! ( "setting default host triple to {}" , default_host_triple) ;
898
- cfg. set_default_host_triple ( default_host_triple. to_owned ( ) ) ?;
899
- } else {
900
- info ! ( "default host triple is {}" , cfg. get_default_host_triple( ) ?) ;
901
- }
902
-
903
- let user_specified_something = default_toolchain. is_some ( )
904
- || !targets. is_empty ( )
905
- || !components. is_empty ( )
906
- || !no_update_toolchain;
907
-
908
- // If the user specified they want no toolchain, we skip this, otherwise
909
- // if they specify something directly, or we have no default, then we install
910
- // a toolchain (updating if it's already present) and then if neither of
911
- // those are true, we have a user who doesn't mind, and already has an
912
- // install, so we leave their setup alone.
913
- Ok (
914
- if matches ! ( default_toolchain, Some ( MaybeOfficialToolchainName :: None ) ) {
915
- info ! ( "skipping toolchain installation" ) ;
916
- if !components. is_empty ( ) {
917
- warn ! (
918
- "ignoring requested component{}: {}" ,
919
- if components. len( ) == 1 { "" } else { "s" } ,
920
- components. join( ", " )
921
- ) ;
922
- }
923
- if !targets. is_empty ( ) {
924
- warn ! (
925
- "ignoring requested target{}: {}" ,
926
- if targets. len( ) == 1 { "" } else { "s" } ,
927
- targets. join( ", " )
928
- ) ;
929
- }
930
- writeln ! ( process( ) . stdout( ) . lock( ) ) ?;
931
- None
932
- } else if user_specified_something
933
- || ( !no_update_toolchain && cfg. find_default ( ) ?. is_none ( ) )
934
- {
935
- match default_toolchain {
936
- Some ( s) => {
937
- let toolchain_name = match s {
938
- MaybeOfficialToolchainName :: None => unreachable ! ( ) ,
939
- MaybeOfficialToolchainName :: Some ( n) => n,
940
- } ;
941
- Some ( toolchain_name. resolve ( & cfg. get_default_host_triple ( ) ?) ?)
942
- }
943
- None => match cfg. get_default ( ) ? {
944
- // Default is installable
945
- Some ( ToolchainName :: Official ( t) ) => Some ( t) ,
946
- // Default is custom, presumably from a prior install. Do nothing.
947
- Some ( ToolchainName :: Custom ( _) ) => None ,
948
- None => Some (
949
- "stable"
950
- . parse :: < PartialToolchainDesc > ( ) ?
951
- . resolve ( & cfg. get_default_host_triple ( ) ?) ?,
952
- ) ,
953
- } ,
954
- }
955
- } else {
956
- info ! ( "updating existing rustup installation - leaving toolchains alone" ) ;
957
- writeln ! ( process( ) . stdout( ) . lock( ) ) ?;
958
- None
959
- } ,
960
- )
961
- }
962
-
963
963
pub ( crate ) fn uninstall ( no_prompt : bool ) -> Result < utils:: ExitCode > {
964
964
if NEVER_SELF_UPDATE {
965
965
err ! ( "self-uninstall is disabled for this build of rustup" ) ;
@@ -1357,7 +1357,7 @@ mod tests {
1357
1357
. unwrap( )
1358
1358
. resolve( & cfg. get_default_host_triple( ) . unwrap( ) )
1359
1359
. unwrap( ) ,
1360
- super :: _install_selection ( opts, & mut cfg)
1360
+ opts. install ( & mut cfg)
1361
1361
. unwrap( ) // result
1362
1362
. unwrap( ) // option
1363
1363
) ;
0 commit comments