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.
上级 a0411e2b
......@@ -1043,7 +1043,7 @@ def bootstrap(help_triggered):
build.checksums_sha256 = data["checksums_sha256"]
build.stage0_compiler = Stage0Toolchain(data["compiler"])
build.set_dist_environment(data["dist_server"])
build.set_dist_environment(data["config"]["dist_server"])
build.build = args.build or build.build_triple()
......
{
"__comment": "Generated by `./x.py run src/tools/bump-stage0`. Run that command again to update the bootstrap compiler.",
"dist_server": "https://static.rust-lang.org",
"config": {
"dist_server": "https://static.rust-lang.org"
},
"compiler": {
"date": "2022-05-20",
"version": "beta"
......
......@@ -4,11 +4,12 @@
use std::collections::HashMap;
use std::convert::TryInto;
const DIST_SERVER: &str = "https://static.rust-lang.org";
const PATH: &str = "src/stage0.json";
const COMPILER_COMPONENTS: &[&str] = &["rustc", "rust-std", "cargo"];
const RUSTFMT_COMPONENTS: &[&str] = &["rustfmt-preview"];
struct Tool {
config: Config,
channel: Channel,
version: [u16; 3],
checksums: IndexMap<String, String>,
......@@ -32,18 +33,20 @@ fn new() -> Result<Self, Error> {
.try_into()
.map_err(|_| anyhow::anyhow!("failed to parse version"))?;
Ok(Self { channel, version, checksums: IndexMap::new() })
let existing: Stage0 = serde_json::from_slice(&std::fs::read(PATH)?)?;
Ok(Self { channel, version, config: existing.config, checksums: IndexMap::new() })
}
fn update_json(mut self) -> Result<(), Error> {
std::fs::write(
"src/stage0.json",
PATH,
format!(
"{}\n",
serde_json::to_string_pretty(&Stage0 {
comment: "Generated by `./x.py run src/tools/bump-stage0`. \
Run that command again to update the bootstrap compiler.",
dist_server: DIST_SERVER.into(),
Run that command again to update the bootstrap compiler."
.into(),
compiler: self.detect_compiler()?,
rustfmt: self.detect_rustfmt()?,
checksums_sha256: {
......@@ -51,7 +54,8 @@ fn update_json(mut self) -> Result<(), Error> {
// are added while filling the other struct fields just above this block.
self.checksums.sort_keys();
self.checksums
}
},
config: self.config,
})?
),
)?;
......@@ -74,7 +78,7 @@ fn detect_compiler(&mut self) -> Result<Stage0Toolchain, Error> {
Channel::Nightly => "beta".to_string(),
};
let manifest = fetch_manifest(&channel)?;
let manifest = fetch_manifest(&self.config, &channel)?;
self.collect_checksums(&manifest, COMPILER_COMPONENTS)?;
Ok(Stage0Toolchain {
date: manifest.date,
......@@ -100,13 +104,13 @@ fn detect_rustfmt(&mut self) -> Result<Option<Stage0Toolchain>, Error> {
return Ok(None);
}
let manifest = fetch_manifest("nightly")?;
let manifest = fetch_manifest(&self.config, "nightly")?;
self.collect_checksums(&manifest, RUSTFMT_COMPONENTS)?;
Ok(Some(Stage0Toolchain { date: manifest.date, version: "nightly".into() }))
}
fn collect_checksums(&mut self, manifest: &Manifest, components: &[&str]) -> Result<(), Error> {
let prefix = format!("{}/", DIST_SERVER);
let prefix = format!("{}/", self.config.dist_server);
for component in components {
let pkg = manifest
.pkg
......@@ -136,10 +140,10 @@ fn main() -> Result<(), Error> {
Ok(())
}
fn fetch_manifest(channel: &str) -> Result<Manifest, Error> {
fn fetch_manifest(config: &Config, channel: &str) -> Result<Manifest, Error> {
Ok(toml::from_slice(&http_get(&format!(
"{}/dist/channel-rust-{}.toml",
DIST_SERVER, channel
config.dist_server, channel
))?)?)
}
......@@ -166,35 +170,40 @@ enum Channel {
Nightly,
}
#[derive(Debug, serde::Serialize)]
#[derive(Debug, serde::Serialize, serde::Deserialize)]
struct Stage0 {
#[serde(rename = "__comment")]
comment: &'static str,
dist_server: String,
comment: String,
config: Config,
compiler: Stage0Toolchain,
rustfmt: Option<Stage0Toolchain>,
checksums_sha256: IndexMap<String, String>,
}
#[derive(Debug, serde::Serialize)]
#[derive(Debug, serde::Serialize, serde::Deserialize)]
struct Config {
dist_server: String,
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
struct Stage0Toolchain {
date: String,
version: String,
}
#[derive(Debug, serde::Deserialize)]
#[derive(Debug, serde::Serialize, serde::Deserialize)]
struct Manifest {
date: String,
pkg: HashMap<String, ManifestPackage>,
}
#[derive(Debug, serde::Deserialize)]
#[derive(Debug, serde::Serialize, serde::Deserialize)]
struct ManifestPackage {
version: String,
target: HashMap<String, ManifestTargetPackage>,
}
#[derive(Debug, serde::Deserialize)]
#[derive(Debug, serde::Serialize, serde::Deserialize)]
struct ManifestTargetPackage {
url: Option<String>,
hash: Option<String>,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册