@@ -22,6 +22,7 @@ use crate::utils::cache::{Interned, INTERNER};
22
22
use crate :: utils:: channel:: { self , GitInfo } ;
23
23
use crate :: utils:: helpers:: { exe, output, t} ;
24
24
use build_helper:: exit;
25
+ use build_helper:: util:: fail;
25
26
use semver:: Version ;
26
27
use serde:: { Deserialize , Deserializer } ;
27
28
use serde_derive:: Deserialize ;
@@ -1416,17 +1417,23 @@ impl Config {
1416
1417
1417
1418
config. initial_rustc = if let Some ( rustc) = rustc {
1418
1419
if !flags. skip_stage0_validation {
1419
- config. check_build_rustc_version ( & rustc) ;
1420
+ config. check_stage0_version ( & rustc, "rustc" ) ;
1420
1421
}
1421
1422
PathBuf :: from ( rustc)
1422
1423
} else {
1423
1424
config. download_beta_toolchain ( ) ;
1424
1425
config. out . join ( config. build . triple ) . join ( "stage0/bin/rustc" )
1425
1426
} ;
1426
1427
1427
- config. initial_cargo = cargo
1428
- . map ( PathBuf :: from)
1429
- . unwrap_or_else ( || config. out . join ( config. build . triple ) . join ( "stage0/bin/cargo" ) ) ;
1428
+ config. initial_cargo = if let Some ( cargo) = cargo {
1429
+ if !flags. skip_stage0_validation {
1430
+ config. check_stage0_version ( & cargo, "cargo" ) ;
1431
+ }
1432
+ PathBuf :: from ( cargo)
1433
+ } else {
1434
+ config. download_beta_toolchain ( ) ;
1435
+ config. out . join ( config. build . triple ) . join ( "stage0/bin/cargo" )
1436
+ } ;
1430
1437
1431
1438
// NOTE: it's important this comes *after* we set `initial_rustc` just above.
1432
1439
if config. dry_run ( ) {
@@ -2282,39 +2289,37 @@ impl Config {
2282
2289
}
2283
2290
}
2284
2291
2285
- pub fn check_build_rustc_version ( & self , rustc_path : & str ) {
2292
+ // check rustc/cargo version is same or lower with 1 apart from the building one
2293
+ pub fn check_stage0_version ( & self , program_path : & str , component_name : & ' static str ) {
2286
2294
if self . dry_run ( ) {
2287
2295
return ;
2288
2296
}
2289
2297
2290
- // check rustc version is same or lower with 1 apart from the building one
2291
- let mut cmd = Command :: new ( rustc_path) ;
2292
- cmd. arg ( "--version" ) ;
2293
- let rustc_output = output ( & mut cmd)
2294
- . lines ( )
2295
- . next ( )
2296
- . unwrap ( )
2297
- . split ( ' ' )
2298
- . nth ( 1 )
2299
- . unwrap ( )
2300
- . split ( '-' )
2301
- . next ( )
2302
- . unwrap ( )
2303
- . to_owned ( ) ;
2304
- let rustc_version = Version :: parse ( & rustc_output. trim ( ) ) . unwrap ( ) ;
2298
+ let stage0_output = output ( Command :: new ( program_path) . arg ( "--version" ) ) ;
2299
+ let mut stage0_output = stage0_output. lines ( ) . next ( ) . unwrap ( ) . split ( ' ' ) ;
2300
+
2301
+ let stage0_name = stage0_output. next ( ) . unwrap ( ) ;
2302
+ if stage0_name != component_name {
2303
+ fail ( & format ! (
2304
+ "Expected to find {component_name} at {program_path} but it claims to be {stage0_name}"
2305
+ ) ) ;
2306
+ }
2307
+
2308
+ let stage0_version =
2309
+ Version :: parse ( stage0_output. next ( ) . unwrap ( ) . split ( '-' ) . next ( ) . unwrap ( ) . trim ( ) )
2310
+ . unwrap ( ) ;
2305
2311
let source_version =
2306
2312
Version :: parse ( & fs:: read_to_string ( self . src . join ( "src/version" ) ) . unwrap ( ) . trim ( ) )
2307
2313
. unwrap ( ) ;
2308
- if !( source_version == rustc_version
2309
- || ( source_version. major == rustc_version . major
2310
- && ( source_version. minor == rustc_version . minor
2311
- || source_version. minor == rustc_version . minor + 1 ) ) )
2314
+ if !( source_version == stage0_version
2315
+ || ( source_version. major == stage0_version . major
2316
+ && ( source_version. minor == stage0_version . minor
2317
+ || source_version. minor == stage0_version . minor + 1 ) ) )
2312
2318
{
2313
2319
let prev_version = format ! ( "{}.{}.x" , source_version. major, source_version. minor - 1 ) ;
2314
- eprintln ! (
2315
- "Unexpected rustc version: {rustc_version}, we should use {prev_version}/{source_version} to build source with {source_version}"
2316
- ) ;
2317
- exit ! ( 1 ) ;
2320
+ fail ( & format ! (
2321
+ "Unexpected {component_name} version: {stage0_version}, we should use {prev_version}/{source_version} to build source with {source_version}"
2322
+ ) ) ;
2318
2323
}
2319
2324
}
2320
2325
0 commit comments