@@ -5,9 +5,11 @@ use crate::self_update;
5
5
use crate :: term2;
6
6
use crate :: term2:: Terminal ;
7
7
use crate :: topical_doc;
8
+
8
9
use clap:: { App , AppSettings , Arg , ArgGroup , ArgMatches , Shell , SubCommand } ;
9
10
use rustup:: dist:: dist:: { PartialTargetTriple , PartialToolchainDesc , Profile , TargetTriple } ;
10
11
use rustup:: dist:: manifest:: Component ;
12
+ use rustup:: toolchain:: { CustomToolchain , DistributableToolchain } ;
11
13
use rustup:: utils:: utils:: { self , ExitCode } ;
12
14
use rustup:: Notification ;
13
15
use rustup:: { command, Cfg , ComponentStatus , Toolchain } ;
@@ -742,7 +744,8 @@ fn default_(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
742
744
let toolchain = cfg. get_toolchain ( toolchain, false ) ?;
743
745
744
746
let status = if !toolchain. is_custom ( ) {
745
- Some ( toolchain. install_from_dist_if_not_installed ( ) ?)
747
+ let distributable = DistributableToolchain :: new ( & toolchain) ?;
748
+ Some ( distributable. install_from_dist_if_not_installed ( ) ?)
746
749
} else if !toolchain. exists ( ) {
747
750
return Err ( ErrorKind :: ToolchainNotInstalled ( toolchain. name ( ) . to_string ( ) ) . into ( ) ) ;
748
751
} else {
@@ -781,8 +784,9 @@ fn check_updates(cfg: &Cfg) -> Result<()> {
781
784
for channel in channels {
782
785
match channel {
783
786
( ref name, Ok ( ref toolchain) ) => {
784
- let current_version = toolchain. show_version ( ) ?;
785
- let dist_version = toolchain. show_dist_version ( ) ?;
787
+ let distributable = DistributableToolchain :: new ( & toolchain) ?;
788
+ let current_version = distributable. show_version ( ) ?;
789
+ let dist_version = distributable. show_dist_version ( ) ?;
786
790
let _ = t. attr ( term2:: Attr :: Bold ) ;
787
791
write ! ( t, "{} - " , name) ?;
788
792
match ( current_version, dist_version) {
@@ -840,7 +844,8 @@ fn update(cfg: &mut Cfg, m: &ArgMatches<'_>) -> Result<()> {
840
844
. values_of ( "targets" )
841
845
. map ( |v| v. collect ( ) )
842
846
. unwrap_or_else ( Vec :: new) ;
843
- Some ( toolchain. install_from_dist (
847
+ let distributable = DistributableToolchain :: new ( & toolchain) ?;
848
+ Some ( distributable. install_from_dist (
844
849
m. is_present ( "force" ) ,
845
850
m. is_present ( "allow-downgrade" ) ,
846
851
& components,
@@ -933,14 +938,18 @@ fn show(cfg: &Cfg) -> Result<()> {
933
938
934
939
// active_toolchain will carry the reason we don't have one in its detail.
935
940
let active_targets = if let Ok ( ref at) = active_toolchain {
936
- match at. 0 . list_components ( ) {
937
- Ok ( None ) => vec ! [ ] ,
938
- Ok ( Some ( cs_vec) ) => cs_vec
939
- . into_iter ( )
940
- . filter ( |c| c. component . short_name_in_manifest ( ) == "rust-std" )
941
- . filter ( |c| c. installed )
942
- . collect ( ) ,
943
- Err ( _) => vec ! [ ] ,
941
+ if let Ok ( distributable) = DistributableToolchain :: new ( & at. 0 ) {
942
+ match distributable. list_components ( ) {
943
+ Ok ( cs_vec) => cs_vec
944
+ . into_iter ( )
945
+ . filter ( |c| c. component . short_name_in_manifest ( ) == "rust-std" )
946
+ . filter ( |c| c. installed )
947
+ . collect ( ) ,
948
+ Err ( _) => vec ! [ ] ,
949
+ }
950
+ } else {
951
+ // These three vec![] could perhaps be reduced with and_then on active_toolchain.
952
+ vec ! [ ]
944
953
}
945
954
} else {
946
955
vec ! [ ]
@@ -1106,7 +1115,8 @@ fn target_add(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
1106
1115
}
1107
1116
1108
1117
targets. clear ( ) ;
1109
- for component in toolchain. list_components ( ) ?. unwrap ( ) {
1118
+ let distributable = DistributableToolchain :: new ( & toolchain) ?;
1119
+ for component in distributable. list_components ( ) ? {
1110
1120
if component. component . short_name_in_manifest ( ) == "rust-std"
1111
1121
&& component. available
1112
1122
&& !component. installed
@@ -1127,7 +1137,8 @@ fn target_add(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
1127
1137
Some ( TargetTriple :: new ( target) ) ,
1128
1138
false ,
1129
1139
) ;
1130
- toolchain. add_component ( new_component) ?;
1140
+ let distributable = DistributableToolchain :: new ( & toolchain) ?;
1141
+ distributable. add_component ( new_component) ?;
1131
1142
}
1132
1143
1133
1144
Ok ( ( ) )
@@ -1142,8 +1153,9 @@ fn target_remove(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
1142
1153
Some ( TargetTriple :: new ( target) ) ,
1143
1154
false ,
1144
1155
) ;
1145
-
1146
- toolchain. remove_component ( new_component) ?;
1156
+ let distributable = DistributableToolchain :: new ( & toolchain)
1157
+ . chain_err ( || rustup:: ErrorKind :: ComponentsUnsupported ( toolchain. name ( ) . to_string ( ) ) ) ?;
1158
+ distributable. remove_component ( new_component) ?;
1147
1159
}
1148
1160
1149
1161
Ok ( ( ) )
@@ -1161,8 +1173,9 @@ fn component_list(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
1161
1173
1162
1174
fn component_add ( cfg : & Cfg , m : & ArgMatches < ' _ > ) -> Result < ( ) > {
1163
1175
let toolchain = explicit_or_dir_toolchain ( cfg, m) ?;
1176
+ let distributable = DistributableToolchain :: new ( & toolchain) ?;
1164
1177
let target = m. value_of ( "target" ) . map ( TargetTriple :: new) . or_else ( || {
1165
- toolchain
1178
+ distributable
1166
1179
. desc ( )
1167
1180
. as_ref ( )
1168
1181
. ok ( )
@@ -1172,17 +1185,18 @@ fn component_add(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
1172
1185
for component in m. values_of ( "component" ) . unwrap ( ) {
1173
1186
let new_component = Component :: new_with_target ( component, false )
1174
1187
. unwrap_or_else ( || Component :: new ( component. to_string ( ) , target. clone ( ) , true ) ) ;
1175
-
1176
- toolchain. add_component ( new_component) ?;
1188
+ distributable. add_component ( new_component) ?;
1177
1189
}
1178
1190
1179
1191
Ok ( ( ) )
1180
1192
}
1181
1193
1182
1194
fn component_remove ( cfg : & Cfg , m : & ArgMatches < ' _ > ) -> Result < ( ) > {
1183
1195
let toolchain = explicit_or_dir_toolchain ( cfg, m) ?;
1196
+ let distributable = DistributableToolchain :: new ( & toolchain)
1197
+ . chain_err ( || rustup:: ErrorKind :: ComponentsUnsupported ( toolchain. name ( ) . to_string ( ) ) ) ?;
1184
1198
let target = m. value_of ( "target" ) . map ( TargetTriple :: new) . or_else ( || {
1185
- toolchain
1199
+ distributable
1186
1200
. desc ( )
1187
1201
. as_ref ( )
1188
1202
. ok ( )
@@ -1192,8 +1206,7 @@ fn component_remove(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
1192
1206
for component in m. values_of ( "component" ) . unwrap ( ) {
1193
1207
let new_component = Component :: new_with_target ( component, false )
1194
1208
. unwrap_or_else ( || Component :: new ( component. to_string ( ) , target. clone ( ) , true ) ) ;
1195
-
1196
- toolchain. remove_component ( new_component) ?;
1209
+ distributable. remove_component ( new_component) ?;
1197
1210
}
1198
1211
1199
1212
Ok ( ( ) )
@@ -1221,9 +1234,13 @@ fn toolchain_link(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
1221
1234
let path = m. value_of ( "path" ) . unwrap ( ) ;
1222
1235
let toolchain = cfg. get_toolchain ( toolchain, true ) ?;
1223
1236
1224
- toolchain
1225
- . install_from_dir ( Path :: new ( path) , true )
1226
- . map_err ( Into :: into)
1237
+ if let Ok ( custom) = CustomToolchain :: new ( & toolchain) {
1238
+ custom
1239
+ . install_from_dir ( Path :: new ( path) , true )
1240
+ . map_err ( Into :: into)
1241
+ } else {
1242
+ Err ( ErrorKind :: InvalidCustomToolchainName ( toolchain. name ( ) . to_string ( ) ) . into ( ) )
1243
+ }
1227
1244
}
1228
1245
1229
1246
fn toolchain_remove ( cfg : & mut Cfg , m : & ArgMatches < ' _ > ) -> Result < ( ) > {
@@ -1239,7 +1256,8 @@ fn override_add(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
1239
1256
let toolchain = cfg. get_toolchain ( toolchain, false ) ?;
1240
1257
1241
1258
let status = if !toolchain. is_custom ( ) {
1242
- Some ( toolchain. install_from_dist_if_not_installed ( ) ?)
1259
+ let distributable = DistributableToolchain :: new ( & toolchain) ?;
1260
+ Some ( distributable. install_from_dist_if_not_installed ( ) ?)
1243
1261
} else if !toolchain. exists ( ) {
1244
1262
return Err ( ErrorKind :: ToolchainNotInstalled ( toolchain. name ( ) . to_string ( ) ) . into ( ) ) ;
1245
1263
} else {
@@ -1326,28 +1344,26 @@ const DOCS_DATA: &[(&str, &str, &str,)] = &[
1326
1344
1327
1345
fn doc ( cfg : & Cfg , m : & ArgMatches < ' _ > ) -> Result < ( ) > {
1328
1346
let toolchain = explicit_or_dir_toolchain ( cfg, m) ?;
1329
- match toolchain. list_components ( ) ? {
1330
- None => { /* custom - no validation */ }
1331
- Some ( components) => {
1332
- if let [ _] = components
1333
- . into_iter ( )
1334
- . filter ( |cstatus| {
1335
- cstatus. component . short_name_in_manifest ( ) == "rust-docs" && !cstatus. installed
1336
- } )
1337
- . take ( 1 )
1338
- . collect :: < Vec < ComponentStatus > > ( )
1339
- . as_slice ( )
1340
- {
1341
- info ! (
1342
- "`rust-docs` not installed in toolchain `{}`" ,
1343
- toolchain. name( )
1344
- ) ;
1345
- info ! (
1346
- "To install, try `rustup component add --toolchain {} rust-docs`" ,
1347
- toolchain. name( )
1348
- ) ;
1349
- return Err ( "unable to view documentation which is not installed" . into ( ) ) ;
1350
- }
1347
+ if let Ok ( distributable) = DistributableToolchain :: new ( & toolchain) {
1348
+ let components = distributable. list_components ( ) ?;
1349
+ if let [ _] = components
1350
+ . into_iter ( )
1351
+ . filter ( |cstatus| {
1352
+ cstatus. component . short_name_in_manifest ( ) == "rust-docs" && !cstatus. installed
1353
+ } )
1354
+ . take ( 1 )
1355
+ . collect :: < Vec < ComponentStatus > > ( )
1356
+ . as_slice ( )
1357
+ {
1358
+ info ! (
1359
+ "`rust-docs` not installed in toolchain `{}`" ,
1360
+ toolchain. name( )
1361
+ ) ;
1362
+ info ! (
1363
+ "To install, try `rustup component add --toolchain {} rust-docs`" ,
1364
+ toolchain. name( )
1365
+ ) ;
1366
+ return Err ( "unable to view documentation which is not installed" . into ( ) ) ;
1351
1367
}
1352
1368
}
1353
1369
let topical_path: PathBuf ;
0 commit comments