Skip to content

Commit 77097c5

Browse files
committed
change stage0.json to reduce the chance of merge conflicts
1 parent 97f3ecd commit 77097c5

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

src/stage0.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
{
2-
"__comment": "Generated by `./x.py run src/tools/bump-stage0`. Run that command again to update the bootstrap compiler.",
32
"config": {
43
"dist_server": "https://static.rust-lang.org",
54
"artifacts_server": "https://ci-artifacts.rust-lang.org/rustc-builds",
65
"artifacts_with_llvm_assertions_server": "https://ci-artifacts.rust-lang.org/rustc-builds-alt",
76
"git_merge_commit_email": "[email protected]"
87
},
8+
"__comments": [
9+
"The configuration above this comment is editable, and can be changed",
10+
"by forks of the repository if they have alternate values.",
11+
"",
12+
"The section below is generated by `./x.py run src/tools/bump-stage0`,",
13+
"run that command again to update the bootstrap compiler.",
14+
"",
15+
"All changes below this comment will be overridden the next time the",
16+
"tool is executed."
17+
],
918
"compiler": {
1019
"date": "2022-05-20",
1120
"version": "beta"

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

+21-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const RUSTFMT_COMPONENTS: &[&str] = &["rustfmt-preview"];
1010

1111
struct Tool {
1212
config: Config,
13+
comments: Vec<String>,
14+
1315
channel: Channel,
1416
version: [u16; 3],
1517
checksums: IndexMap<String, String>,
@@ -35,7 +37,13 @@ impl Tool {
3537

3638
let existing: Stage0 = serde_json::from_slice(&std::fs::read(PATH)?)?;
3739

38-
Ok(Self { channel, version, config: existing.config, checksums: IndexMap::new() })
40+
Ok(Self {
41+
channel,
42+
version,
43+
config: existing.config,
44+
comments: existing.comments,
45+
checksums: IndexMap::new(),
46+
})
3947
}
4048

4149
fn update_json(mut self) -> Result<(), Error> {
@@ -44,9 +52,6 @@ impl Tool {
4452
format!(
4553
"{}\n",
4654
serde_json::to_string_pretty(&Stage0 {
47-
comment: "Generated by `./x.py run src/tools/bump-stage0`. \
48-
Run that command again to update the bootstrap compiler."
49-
.into(),
5055
compiler: self.detect_compiler()?,
5156
rustfmt: self.detect_rustfmt()?,
5257
checksums_sha256: {
@@ -56,6 +61,7 @@ impl Tool {
5661
self.checksums
5762
},
5863
config: self.config,
64+
comments: self.comments,
5965
})?
6066
),
6167
)?;
@@ -172,9 +178,18 @@ enum Channel {
172178

173179
#[derive(Debug, serde::Serialize, serde::Deserialize)]
174180
struct Stage0 {
175-
#[serde(rename = "__comment")]
176-
comment: String,
177181
config: Config,
182+
// Comments are explicitly below the config, do not move them above.
183+
//
184+
// Downstream forks of the compiler codebase can change the configuration values defined above,
185+
// but doing so would risk merge conflicts whenever they import new changes that include a
186+
// bootstrap compiler bump.
187+
//
188+
// To lessen the pain, a big block of comments is placed between the configuration and the
189+
// auto-generated parts of the file, preventing git diffs of the config to include parts of the
190+
// auto-egenrated content and vice versa. This should prevent merge conflicts.
191+
#[serde(rename = "__comments")]
192+
comments: Vec<String>,
178193
compiler: Stage0Toolchain,
179194
rustfmt: Option<Stage0Toolchain>,
180195
checksums_sha256: IndexMap<String, String>,

0 commit comments

Comments
 (0)