@@ -20,7 +20,6 @@ use crate::channel::GitInfo;
20
20
pub use crate :: flags:: Subcommand ;
21
21
use crate :: flags:: { Color , Flags } ;
22
22
use crate :: util:: { exe, output, program_out_of_date, t} ;
23
- use crate :: RustfmtMetadata ;
24
23
use once_cell:: sync:: OnceCell ;
25
24
use serde:: { Deserialize , Deserializer } ;
26
25
@@ -73,6 +72,7 @@ pub struct Config {
73
72
pub test_compare_mode : bool ,
74
73
pub color : Color ,
75
74
pub patch_binaries_for_nix : bool ,
75
+ pub stage0_metadata : Stage0Metadata ,
76
76
77
77
pub on_fail : Option < String > ,
78
78
pub stage : u32 ,
@@ -212,6 +212,28 @@ pub struct Config {
212
212
pub out : PathBuf ,
213
213
}
214
214
215
+ #[ derive( Default , Deserialize ) ]
216
+ #[ cfg_attr( test, derive( Clone ) ) ]
217
+ pub struct Stage0Metadata {
218
+ pub config : Stage0Config ,
219
+ pub checksums_sha256 : HashMap < String , String > ,
220
+ pub rustfmt : Option < RustfmtMetadata > ,
221
+ }
222
+ #[ derive( Default , Deserialize ) ]
223
+ #[ cfg_attr( test, derive( Clone ) ) ]
224
+ pub struct Stage0Config {
225
+ pub dist_server : String ,
226
+ pub artifacts_server : String ,
227
+ pub artifacts_with_llvm_assertions_server : String ,
228
+ pub git_merge_commit_email : String ,
229
+ }
230
+ #[ derive( Default , Deserialize ) ]
231
+ #[ cfg_attr( test, derive( Clone ) ) ]
232
+ pub struct RustfmtMetadata {
233
+ pub date : String ,
234
+ pub version : String ,
235
+ }
236
+
215
237
#[ derive( Clone , Debug ) ]
216
238
pub enum RustfmtState {
217
239
SystemToolchain ( PathBuf ) ,
@@ -776,6 +798,9 @@ impl Config {
776
798
config. llvm_profile_use = flags. llvm_profile_use ;
777
799
config. llvm_profile_generate = flags. llvm_profile_generate ;
778
800
801
+ let stage0_json = t ! ( std:: fs:: read( & config. src. join( "src" ) . join( "stage0.json" ) ) ) ;
802
+ config. stage0_metadata = t ! ( serde_json:: from_slice:: <Stage0Metadata >( & stage0_json) ) ;
803
+
779
804
#[ cfg( test) ]
780
805
let get_toml = |_| TomlConfig :: default ( ) ;
781
806
#[ cfg( not( test) ) ]
@@ -1103,8 +1128,11 @@ impl Config {
1103
1128
config. rust_codegen_units_std = rust. codegen_units_std . map ( threads_from_config) ;
1104
1129
config. rust_profile_use = flags. rust_profile_use . or ( rust. profile_use ) ;
1105
1130
config. rust_profile_generate = flags. rust_profile_generate . or ( rust. profile_generate ) ;
1106
- config. download_rustc_commit =
1107
- download_ci_rustc_commit ( rust. download_rustc , config. verbose > 0 ) ;
1131
+ config. download_rustc_commit = download_ci_rustc_commit (
1132
+ & config. stage0_metadata ,
1133
+ rust. download_rustc ,
1134
+ config. verbose > 0 ,
1135
+ ) ;
1108
1136
} else {
1109
1137
config. rust_profile_use = flags. rust_profile_use ;
1110
1138
config. rust_profile_generate = flags. rust_profile_generate ;
@@ -1424,7 +1452,11 @@ fn threads_from_config(v: u32) -> u32 {
1424
1452
}
1425
1453
1426
1454
/// Returns the commit to download, or `None` if we shouldn't download CI artifacts.
1427
- fn download_ci_rustc_commit ( download_rustc : Option < StringOrBool > , verbose : bool ) -> Option < String > {
1455
+ fn download_ci_rustc_commit (
1456
+ stage0_metadata : & Stage0Metadata ,
1457
+ download_rustc : Option < StringOrBool > ,
1458
+ verbose : bool ,
1459
+ ) -> Option < String > {
1428
1460
// If `download-rustc` is not set, default to rebuilding.
1429
1461
let if_unchanged = match download_rustc {
1430
1462
None | Some ( StringOrBool :: Bool ( false ) ) => return None ,
@@ -1443,13 +1475,12 @@ fn download_ci_rustc_commit(download_rustc: Option<StringOrBool>, verbose: bool)
1443
1475
1444
1476
// Look for a version to compare to based on the current commit.
1445
1477
// Only commits merged by bors will have CI artifacts.
1446
- let merge_base = output ( Command :: new ( "git" ) . args ( & [
1447
- "rev-list" ,
1448
-
1449
- "-n1" ,
1450
- "--first-parent" ,
1451
- "HEAD" ,
1452
- ] ) ) ;
1478
+ let merge_base = output (
1479
+ Command :: new ( "git" )
1480
+ . arg ( "rev-list" )
1481
+ . arg ( format ! ( "--author={}" , stage0_metadata. config. git_merge_commit_email) )
1482
+ . args ( & [ "-n1" , "--first-parent" , "HEAD" ] ) ,
1483
+ ) ;
1453
1484
let commit = merge_base. trim_end ( ) ;
1454
1485
if commit. is_empty ( ) {
1455
1486
println ! ( "error: could not find commit hash for downloading rustc" ) ;
@@ -1484,7 +1515,7 @@ fn download_ci_rustc_commit(download_rustc: Option<StringOrBool>, verbose: bool)
1484
1515
}
1485
1516
1486
1517
fn maybe_download_rustfmt ( builder : & Builder < ' _ > ) -> Option < PathBuf > {
1487
- let RustfmtMetadata { date, version } = builder. stage0_metadata . rustfmt . as_ref ( ) ?;
1518
+ let RustfmtMetadata { date, version } = builder. config . stage0_metadata . rustfmt . as_ref ( ) ?;
1488
1519
let channel = format ! ( "{version}-{date}" ) ;
1489
1520
1490
1521
let host = builder. config . build ;
@@ -1568,13 +1599,13 @@ fn download_component(
1568
1599
let tarball = cache_dir. join ( & filename) ;
1569
1600
let ( base_url, url, should_verify) = match mode {
1570
1601
DownloadSource :: CI => (
1571
- "https://ci-artifacts.rust-lang.org/rustc-builds" . to_string ( ) ,
1602
+ builder . config . stage0_metadata . config . artifacts_server . clone ( ) ,
1572
1603
format ! ( "{key}/{filename}" ) ,
1573
1604
false ,
1574
1605
) ,
1575
1606
DownloadSource :: Dist => {
1576
1607
let dist_server = env:: var ( "RUSTUP_DIST_SERVER" )
1577
- . unwrap_or ( builder. stage0_metadata . dist_server . to_string ( ) ) ;
1608
+ . unwrap_or ( builder. config . stage0_metadata . config . dist_server . to_string ( ) ) ;
1578
1609
// NOTE: make `dist` part of the URL because that's how it's stored in src/stage0.json
1579
1610
( dist_server, format ! ( "dist/{key}/{filename}" ) , true )
1580
1611
}
@@ -1590,7 +1621,7 @@ fn download_component(
1590
1621
target at this time, see https://doc.rust-lang.org/nightly\
1591
1622
/rustc/platform-support.html for more information."
1592
1623
) ;
1593
- let sha256 = builder. stage0_metadata . checksums_sha256 . get ( & url) . expect ( & error) ;
1624
+ let sha256 = builder. config . stage0_metadata . checksums_sha256 . get ( & url) . expect ( & error) ;
1594
1625
if tarball. exists ( ) {
1595
1626
if builder. verify ( & tarball, sha256) {
1596
1627
builder. unpack ( & tarball, & bin_root, prefix) ;
@@ -1610,7 +1641,7 @@ fn download_component(
1610
1641
None
1611
1642
} ;
1612
1643
1613
- builder. download_component ( & base_url, & url, & tarball, "" ) ;
1644
+ builder. download_component ( & format ! ( "{ base_url}/{ url}" ) , & tarball, "" ) ;
1614
1645
if let Some ( sha256) = checksum {
1615
1646
if !builder. verify ( & tarball, sha256) {
1616
1647
panic ! ( "failed to verify {}" , tarball. display( ) ) ;
0 commit comments