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