1
1
//! Tools to manage and use Rust toolchains.
2
2
3
3
use crate :: cmd:: { Binary , Command , Runnable } ;
4
- use crate :: tools:: { RUSTUP , RUSTUP_TOOLCHAIN_INSTALL_MASTER } ;
4
+ use crate :: tools:: RUSTUP ;
5
+ #[ cfg( feature = "unstable-toolchain-ci" ) ]
6
+ use crate :: tools:: RUSTUP_TOOLCHAIN_INSTALL_MASTER ;
5
7
use crate :: Workspace ;
6
- use failure:: { bail , Error , ResultExt } ;
8
+ use failure:: { Error , ResultExt } ;
7
9
use log:: info;
8
10
use std:: borrow:: Cow ;
9
11
use std:: path:: Path ;
@@ -95,6 +97,8 @@ impl std::fmt::Display for RustupThing {
95
97
96
98
/// Metadata of a CI toolchain. See [`Toolchain`](struct.Toolchain.html) to create and get it.
97
99
#[ derive( serde:: Serialize , serde:: Deserialize , PartialEq , Eq , Hash , Debug , Clone ) ]
100
+ #[ cfg( any( feature = "unstable-toolchain-ci" , doc) ) ]
101
+ #[ cfg_attr( docs_rs, doc( cfg( feature = "unstable-toolchain-ci" ) ) ) ]
98
102
pub struct CiToolchain {
99
103
/// Hash of the merge commit of the PR you want to download.
100
104
sha : String ,
@@ -103,6 +107,7 @@ pub struct CiToolchain {
103
107
alt : bool ,
104
108
}
105
109
110
+ #[ cfg( any( feature = "unstable-toolchain-ci" , doc) ) ]
106
111
impl CiToolchain {
107
112
/// Get the SHA of the git commit that produced this toolchain.
108
113
pub fn sha ( & self ) -> & str {
@@ -149,6 +154,7 @@ impl CiToolchain {
149
154
enum ToolchainInner {
150
155
Dist ( DistToolchain ) ,
151
156
#[ serde( rename = "ci" ) ]
157
+ #[ cfg( feature = "unstable-toolchain-ci" ) ]
152
158
CI ( CiToolchain ) ,
153
159
}
154
160
@@ -197,6 +203,8 @@ impl Toolchain {
197
203
/// **There is no availability or stability guarantee for these builds!**
198
204
///
199
205
/// [repo]: https://github.com/rust-lang/rust
206
+ #[ cfg( any( feature = "unstable-toolchain-ci" , doc) ) ]
207
+ #[ cfg_attr( docs_rs, doc( cfg( feature = "unstable-toolchain-ci" ) ) ) ]
200
208
pub fn ci ( sha : & str , alt : bool ) -> Self {
201
209
Toolchain {
202
210
inner : ToolchainInner :: CI ( CiToolchain {
@@ -207,6 +215,7 @@ impl Toolchain {
207
215
}
208
216
209
217
/// If this toolchain is a dist toolchain, return its metadata.
218
+ #[ allow( irrefutable_let_patterns) ]
210
219
pub fn as_dist ( & self ) -> Option < & DistToolchain > {
211
220
if let ToolchainInner :: Dist ( dist) = & self . inner {
212
221
Some ( dist)
@@ -216,6 +225,8 @@ impl Toolchain {
216
225
}
217
226
218
227
/// If this toolchain is a CI toolchain, return its metadata.
228
+ #[ cfg( any( feature = "unstable-toolchain-ci" , doc) ) ]
229
+ #[ cfg_attr( docs_rs, doc( cfg( feature = "unstable-toolchain-ci" ) ) ) ]
219
230
pub fn as_ci ( & self ) -> Option < & CiToolchain > {
220
231
if let ToolchainInner :: CI ( ci) = & self . inner {
221
232
Some ( ci)
@@ -228,6 +239,7 @@ impl Toolchain {
228
239
pub fn install ( & self , workspace : & Workspace ) -> Result < ( ) , Error > {
229
240
match & self . inner {
230
241
ToolchainInner :: Dist ( dist) => dist. init ( workspace) ?,
242
+ #[ cfg( feature = "unstable-toolchain-ci" ) ]
231
243
ToolchainInner :: CI ( ci) => ci. init ( workspace) ?,
232
244
}
233
245
@@ -287,13 +299,15 @@ impl Toolchain {
287
299
let thing = thing. to_string ( ) ;
288
300
let action = action. to_string ( ) ;
289
301
302
+ #[ cfg( feature = "unstable-toolchain-ci" ) ]
290
303
if let ToolchainInner :: CI { .. } = self . inner {
291
- bail ! (
304
+ failure :: bail!(
292
305
"{} {} on CI toolchains is not supported yet" ,
293
306
log_action_ing,
294
307
thing
295
308
) ;
296
309
}
310
+
297
311
let toolchain_name = self . rustup_name ( ) ;
298
312
info ! (
299
313
"{} {} {} for toolchain {}" ,
@@ -419,7 +433,9 @@ impl Toolchain {
419
433
fn rustup_name ( & self ) -> String {
420
434
match & self . inner {
421
435
ToolchainInner :: Dist ( dist) => dist. name . to_string ( ) ,
436
+ #[ cfg( feature = "unstable-toolchain-ci" ) ]
422
437
ToolchainInner :: CI ( ci) if ci. alt => format ! ( "{}-alt" , ci. sha) ,
438
+ #[ cfg( feature = "unstable-toolchain-ci" ) ]
423
439
ToolchainInner :: CI ( ci) => ci. sha . to_string ( ) ,
424
440
}
425
441
}
@@ -462,12 +478,15 @@ pub(crate) fn list_installed_toolchains(rustup_home: &Path) -> Result<Vec<Toolch
462
478
if entry. file_type ( ) ?. is_symlink ( ) || update_hashes. join ( & name) . exists ( ) {
463
479
result. push ( Toolchain :: dist ( & name) ) ;
464
480
} else {
465
- let ( sha, alt) = if name. ends_with ( "-alt" ) {
466
- ( ( & name[ ..name. len ( ) - 4 ] ) . to_string ( ) , true )
467
- } else {
468
- ( name, false )
469
- } ;
470
- result. push ( Toolchain :: ci ( & sha, alt) ) ;
481
+ #[ cfg( feature = "unstable-toolchain-ci" ) ]
482
+ {
483
+ let ( sha, alt) = if name. ends_with ( "-alt" ) {
484
+ ( ( & name[ ..name. len ( ) - 4 ] ) . to_string ( ) , true )
485
+ } else {
486
+ ( name, false )
487
+ } ;
488
+ result. push ( Toolchain :: ci ( & sha, alt) ) ;
489
+ }
471
490
}
472
491
}
473
492
Ok ( result)
@@ -479,12 +498,20 @@ mod tests {
479
498
use failure:: Error ;
480
499
481
500
#[ test]
482
- fn test_serde_repr ( ) -> Result < ( ) , Error > {
501
+ fn test_dist_serde_repr ( ) -> Result < ( ) , Error > {
483
502
const DIST : & str = r#"{"type": "dist", "name": "stable"}"# ;
503
+
504
+ assert_eq ! ( Toolchain :: dist( "stable" ) , serde_json:: from_str( DIST ) ?) ;
505
+
506
+ Ok ( ( ) )
507
+ }
508
+
509
+ #[ test]
510
+ #[ cfg( feature = "unstable-toolchain-ci" ) ]
511
+ fn test_ci_serde_repr ( ) -> Result < ( ) , Error > {
484
512
const CI_NORMAL : & str = r#"{"type": "ci", "sha": "0000000", "alt": false}"# ;
485
513
const CI_ALT : & str = r#"{"type": "ci", "sha": "0000000", "alt": true}"# ;
486
514
487
- assert_eq ! ( Toolchain :: dist( "stable" ) , serde_json:: from_str( DIST ) ?) ;
488
515
assert_eq ! (
489
516
Toolchain :: ci( "0000000" , false ) ,
490
517
serde_json:: from_str( CI_NORMAL ) ?
@@ -537,11 +564,21 @@ mod tests {
537
564
) ?;
538
565
539
566
let res = super :: list_installed_toolchains ( rustup_home. path ( ) ) ?;
540
- assert_eq ! ( 4 , res. len( ) ) ;
567
+
568
+ let mut expected_count = 0 ;
569
+
541
570
assert ! ( res. contains( & Toolchain :: dist( DIST_NAME ) ) ) ;
542
571
assert ! ( res. contains( & Toolchain :: dist( LINK_NAME ) ) ) ;
543
- assert ! ( res. contains( & Toolchain :: ci( CI_SHA , false ) ) ) ;
544
- assert ! ( res. contains( & Toolchain :: ci( CI_SHA , true ) ) ) ;
572
+ expected_count += 2 ;
573
+
574
+ #[ cfg( feature = "unstable-toolchain-ci" ) ]
575
+ {
576
+ assert ! ( res. contains( & Toolchain :: ci( CI_SHA , false ) ) ) ;
577
+ assert ! ( res. contains( & Toolchain :: ci( CI_SHA , true ) ) ) ;
578
+ expected_count += 2 ;
579
+ }
580
+
581
+ assert_eq ! ( res. len( ) , expected_count) ;
545
582
546
583
Ok ( ( ) )
547
584
}
0 commit comments