about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPietro Albini <pietro.albini@ferrous-systems.com>2022-06-07 12:17:11 +0200
committerPietro Albini <pietro.albini@ferrous-systems.com>2022-06-09 17:54:11 +0200
commitc1a0f49e9f92ce7ebb8c9f2a3baefce779bb5950 (patch)
treeb6d0de13d7edf608670699eed6d85e66d5653fca
parenta0411e2bfe1fb939757aa96603f0a10d1d9eb029 (diff)
downloadrust-c1a0f49e9f92ce7ebb8c9f2a3baefce779bb5950.tar.gz
rust-c1a0f49e9f92ce7ebb8c9f2a3baefce779bb5950.zip
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.
-rw-r--r--src/bootstrap/bootstrap.py2
-rw-r--r--src/stage0.json4
-rw-r--r--src/tools/bump-stage0/src/main.rs45
3 files changed, 31 insertions, 20 deletions
diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py
index 635e4f3703b..3b2b507b062 100644
--- a/src/bootstrap/bootstrap.py
+++ b/src/bootstrap/bootstrap.py
@@ -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()
 
diff --git a/src/stage0.json b/src/stage0.json
index 6371b9eae59..5af6d7d824f 100644
--- a/src/stage0.json
+++ b/src/stage0.json
@@ -1,6 +1,8 @@
 {
   "__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"
diff --git a/src/tools/bump-stage0/src/main.rs b/src/tools/bump-stage0/src/main.rs
index d6364e28fef..e9ae1fe272f 100644
--- a/src/tools/bump-stage0/src/main.rs
+++ b/src/tools/bump-stage0/src/main.rs
@@ -4,11 +4,12 @@ use indexmap::IndexMap;
 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 @@ impl Tool {
             .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 @@ impl Tool {
                         // 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 @@ impl Tool {
             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 @@ impl Tool {
             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>,