Skip to content

Commit c1a0f49

Browse files
committed
keep the same config values in stage0 between invocations
This commit allows users to change the contents of the "config" key in src/stage0.json without having it overridden the next time the bump-stage0 tool is executed.
1 parent a0411e2 commit c1a0f49

File tree

3 files changed

+31
-20
lines changed

3 files changed

+31
-20
lines changed

src/bootstrap/bootstrap.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ def bootstrap(help_triggered):
10431043
build.checksums_sha256 = data["checksums_sha256"]
10441044
build.stage0_compiler = Stage0Toolchain(data["compiler"])
10451045

1046-
build.set_dist_environment(data["dist_server"])
1046+
build.set_dist_environment(data["config"]["dist_server"])
10471047

10481048
build.build = args.build or build.build_triple()
10491049

src/stage0.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"__comment": "Generated by `./x.py run src/tools/bump-stage0`. Run that command again to update the bootstrap compiler.",
3-
"dist_server": "https://static.rust-lang.org",
3+
"config": {
4+
"dist_server": "https://static.rust-lang.org"
5+
},
46
"compiler": {
57
"date": "2022-05-20",
68
"version": "beta"

src/tools/bump-stage0/src/main.rs

+27-18
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ use indexmap::IndexMap;
44
use std::collections::HashMap;
55
use std::convert::TryInto;
66

7-
const DIST_SERVER: &str = "https://static.rust-lang.org";
7+
const PATH: &str = "src/stage0.json";
88
const COMPILER_COMPONENTS: &[&str] = &["rustc", "rust-std", "cargo"];
99
const RUSTFMT_COMPONENTS: &[&str] = &["rustfmt-preview"];
1010

1111
struct Tool {
12+
config: Config,
1213
channel: Channel,
1314
version: [u16; 3],
1415
checksums: IndexMap<String, String>,
@@ -32,26 +33,29 @@ impl Tool {
3233
.try_into()
3334
.map_err(|_| anyhow::anyhow!("failed to parse version"))?;
3435

35-
Ok(Self { channel, version, checksums: IndexMap::new() })
36+
let existing: Stage0 = serde_json::from_slice(&std::fs::read(PATH)?)?;
37+
38+
Ok(Self { channel, version, config: existing.config, checksums: IndexMap::new() })
3639
}
3740

3841
fn update_json(mut self) -> Result<(), Error> {
3942
std::fs::write(
40-
"src/stage0.json",
43+
PATH,
4144
format!(
4245
"{}\n",
4346
serde_json::to_string_pretty(&Stage0 {
4447
comment: "Generated by `./x.py run src/tools/bump-stage0`. \
45-
Run that command again to update the bootstrap compiler.",
46-
dist_server: DIST_SERVER.into(),
48+
Run that command again to update the bootstrap compiler."
49+
.into(),
4750
compiler: self.detect_compiler()?,
4851
rustfmt: self.detect_rustfmt()?,
4952
checksums_sha256: {
5053
// Keys are sorted here instead of beforehand because values in this map
5154
// are added while filling the other struct fields just above this block.
5255
self.checksums.sort_keys();
5356
self.checksums
54-
}
57+
},
58+
config: self.config,
5559
})?
5660
),
5761
)?;
@@ -74,7 +78,7 @@ impl Tool {
7478
Channel::Nightly => "beta".to_string(),
7579
};
7680

77-
let manifest = fetch_manifest(&channel)?;
81+
let manifest = fetch_manifest(&self.config, &channel)?;
7882
self.collect_checksums(&manifest, COMPILER_COMPONENTS)?;
7983
Ok(Stage0Toolchain {
8084
date: manifest.date,
@@ -100,13 +104,13 @@ impl Tool {
100104
return Ok(None);
101105
}
102106

103-
let manifest = fetch_manifest("nightly")?;
107+
let manifest = fetch_manifest(&self.config, "nightly")?;
104108
self.collect_checksums(&manifest, RUSTFMT_COMPONENTS)?;
105109
Ok(Some(Stage0Toolchain { date: manifest.date, version: "nightly".into() }))
106110
}
107111

108112
fn collect_checksums(&mut self, manifest: &Manifest, components: &[&str]) -> Result<(), Error> {
109-
let prefix = format!("{}/", DIST_SERVER);
113+
let prefix = format!("{}/", self.config.dist_server);
110114
for component in components {
111115
let pkg = manifest
112116
.pkg
@@ -136,10 +140,10 @@ fn main() -> Result<(), Error> {
136140
Ok(())
137141
}
138142

139-
fn fetch_manifest(channel: &str) -> Result<Manifest, Error> {
143+
fn fetch_manifest(config: &Config, channel: &str) -> Result<Manifest, Error> {
140144
Ok(toml::from_slice(&http_get(&format!(
141145
"{}/dist/channel-rust-{}.toml",
142-
DIST_SERVER, channel
146+
config.dist_server, channel
143147
))?)?)
144148
}
145149

@@ -166,35 +170,40 @@ enum Channel {
166170
Nightly,
167171
}
168172

169-
#[derive(Debug, serde::Serialize)]
173+
#[derive(Debug, serde::Serialize, serde::Deserialize)]
170174
struct Stage0 {
171175
#[serde(rename = "__comment")]
172-
comment: &'static str,
173-
dist_server: String,
176+
comment: String,
177+
config: Config,
174178
compiler: Stage0Toolchain,
175179
rustfmt: Option<Stage0Toolchain>,
176180
checksums_sha256: IndexMap<String, String>,
177181
}
178182

179-
#[derive(Debug, serde::Serialize)]
183+
#[derive(Debug, serde::Serialize, serde::Deserialize)]
184+
struct Config {
185+
dist_server: String,
186+
}
187+
188+
#[derive(Debug, serde::Serialize, serde::Deserialize)]
180189
struct Stage0Toolchain {
181190
date: String,
182191
version: String,
183192
}
184193

185-
#[derive(Debug, serde::Deserialize)]
194+
#[derive(Debug, serde::Serialize, serde::Deserialize)]
186195
struct Manifest {
187196
date: String,
188197
pkg: HashMap<String, ManifestPackage>,
189198
}
190199

191-
#[derive(Debug, serde::Deserialize)]
200+
#[derive(Debug, serde::Serialize, serde::Deserialize)]
192201
struct ManifestPackage {
193202
version: String,
194203
target: HashMap<String, ManifestTargetPackage>,
195204
}
196205

197-
#[derive(Debug, serde::Deserialize)]
206+
#[derive(Debug, serde::Serialize, serde::Deserialize)]
198207
struct ManifestTargetPackage {
199208
url: Option<String>,
200209
hash: Option<String>,

0 commit comments

Comments
 (0)