about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPietro Albini <pietro.albini@ferrous-systems.com>2022-06-07 13:29:39 +0200
committerPietro Albini <pietro.albini@ferrous-systems.com>2022-06-09 19:43:11 +0200
commit77097c5da87338e4964b8a717466beb2346f480c (patch)
tree1add442d939cb29e2394b7377e23f13abbaefb59
parent97f3ecda016ca7ab3edf64e11901466f879d4483 (diff)
downloadrust-77097c5da87338e4964b8a717466beb2346f480c.tar.gz
rust-77097c5da87338e4964b8a717466beb2346f480c.zip
change stage0.json to reduce the chance of merge conflicts
-rw-r--r--src/stage0.json11
-rw-r--r--src/tools/bump-stage0/src/main.rs27
2 files changed, 31 insertions, 7 deletions
diff --git a/src/stage0.json b/src/stage0.json
index b1782955283..b6b502f4cf0 100644
--- a/src/stage0.json
+++ b/src/stage0.json
@@ -1,11 +1,20 @@
 {
-  "__comment": "Generated by `./x.py run src/tools/bump-stage0`. Run that command again to update the bootstrap compiler.",
   "config": {
     "dist_server": "https://static.rust-lang.org",
     "artifacts_server": "https://ci-artifacts.rust-lang.org/rustc-builds",
     "artifacts_with_llvm_assertions_server": "https://ci-artifacts.rust-lang.org/rustc-builds-alt",
     "git_merge_commit_email": "bors@rust-lang.org"
   },
+  "__comments": [
+    "The configuration above this comment is editable, and can be changed",
+    "by forks of the repository if they have alternate values.",
+    "",
+    "The section below is generated by `./x.py run src/tools/bump-stage0`,",
+    "run that command again to update the bootstrap compiler.",
+    "",
+    "All changes below this comment will be overridden the next time the",
+    "tool is executed."
+  ],
   "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 b40fd66e08e..7c6e4bb4fb5 100644
--- a/src/tools/bump-stage0/src/main.rs
+++ b/src/tools/bump-stage0/src/main.rs
@@ -10,6 +10,8 @@ const RUSTFMT_COMPONENTS: &[&str] = &["rustfmt-preview"];
 
 struct Tool {
     config: Config,
+    comments: Vec<String>,
+
     channel: Channel,
     version: [u16; 3],
     checksums: IndexMap<String, String>,
@@ -35,7 +37,13 @@ impl Tool {
 
         let existing: Stage0 = serde_json::from_slice(&std::fs::read(PATH)?)?;
 
-        Ok(Self { channel, version, config: existing.config, checksums: IndexMap::new() })
+        Ok(Self {
+            channel,
+            version,
+            config: existing.config,
+            comments: existing.comments,
+            checksums: IndexMap::new(),
+        })
     }
 
     fn update_json(mut self) -> Result<(), Error> {
@@ -44,9 +52,6 @@ impl Tool {
             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."
-                        .into(),
                     compiler: self.detect_compiler()?,
                     rustfmt: self.detect_rustfmt()?,
                     checksums_sha256: {
@@ -56,6 +61,7 @@ impl Tool {
                         self.checksums
                     },
                     config: self.config,
+                    comments: self.comments,
                 })?
             ),
         )?;
@@ -172,9 +178,18 @@ enum Channel {
 
 #[derive(Debug, serde::Serialize, serde::Deserialize)]
 struct Stage0 {
-    #[serde(rename = "__comment")]
-    comment: 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<String>,
     compiler: Stage0Toolchain,
     rustfmt: Option<Stage0Toolchain>,
     checksums_sha256: IndexMap<String, String>,