X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Ftools%2Fbump-stage0%2Fsrc%2Fmain.rs;h=7c6e4bb4fb5be92e1a4bdac241d2c4c74f5eec77;hb=77097c5da87338e4964b8a717466beb2346f480c;hp=d6364e28fef97f2394694d80e550419ea16f25b2;hpb=60cad9789c8ab22bc008f88817001d538acb40b3;p=rust.git diff --git a/src/tools/bump-stage0/src/main.rs b/src/tools/bump-stage0/src/main.rs index d6364e28fef..7c6e4bb4fb5 100644 --- a/src/tools/bump-stage0/src/main.rs +++ b/src/tools/bump-stage0/src/main.rs @@ -4,11 +4,14 @@ 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, + comments: Vec, + channel: Channel, version: [u16; 3], checksums: IndexMap, @@ -32,18 +35,23 @@ fn new() -> Result { .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, + comments: existing.comments, + 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(), compiler: self.detect_compiler()?, rustfmt: self.detect_rustfmt()?, checksums_sha256: { @@ -51,7 +59,9 @@ 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, + comments: self.comments, })? ), )?; @@ -74,7 +84,7 @@ fn detect_compiler(&mut self) -> Result { 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 +110,13 @@ fn detect_rustfmt(&mut self) -> Result, 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 +146,10 @@ fn main() -> Result<(), Error> { Ok(()) } -fn fetch_manifest(channel: &str) -> Result { +fn fetch_manifest(config: &Config, channel: &str) -> Result { Ok(toml::from_slice(&http_get(&format!( "{}/dist/channel-rust-{}.toml", - DIST_SERVER, channel + config.dist_server, channel ))?)?) } @@ -166,35 +176,52 @@ enum Channel { Nightly, } -#[derive(Debug, serde::Serialize)] +#[derive(Debug, serde::Serialize, serde::Deserialize)] struct Stage0 { - #[serde(rename = "__comment")] - comment: &'static str, - dist_server: String, + config: Config, + // Comments are explicitly below the config, do not move them above. + // + // Downstream forks of the compiler codebase can change the configuration values defined above, + // but doing so would risk merge conflicts whenever they import new changes that include a + // bootstrap compiler bump. + // + // To lessen the pain, a big block of comments is placed between the configuration and the + // auto-generated parts of the file, preventing git diffs of the config to include parts of the + // auto-egenrated content and vice versa. This should prevent merge conflicts. + #[serde(rename = "__comments")] + comments: Vec, compiler: Stage0Toolchain, rustfmt: Option, checksums_sha256: IndexMap, } -#[derive(Debug, serde::Serialize)] +#[derive(Debug, serde::Serialize, serde::Deserialize)] +struct Config { + dist_server: String, + artifacts_server: String, + artifacts_with_llvm_assertions_server: String, + git_merge_commit_email: 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, } -#[derive(Debug, serde::Deserialize)] +#[derive(Debug, serde::Serialize, serde::Deserialize)] struct ManifestPackage { version: String, target: HashMap, } -#[derive(Debug, serde::Deserialize)] +#[derive(Debug, serde::Serialize, serde::Deserialize)] struct ManifestTargetPackage { url: Option, hash: Option,