Skip to content

Commit e05e4f3

Browse files
Rollup merge of #117263 - onur-ozkan:change-id-fix, r=saethlin
handle the case when the change-id isn't found When we switch back and forth between the old and recent branches, if there was a breaking change in the bootstrap configuration in between, we have to update the change-id in the build configuration with each checkout, which can be exhausting. This change fixes that. r? saethlin
2 parents 28acba3 + e0cb1cc commit e05e4f3

File tree

2 files changed

+40
-24
lines changed

2 files changed

+40
-24
lines changed

src/bootstrap/src/bin/main.rs

+22-18
Original file line numberDiff line numberDiff line change
@@ -109,31 +109,35 @@ fn check_version(config: &Config) -> Option<String> {
109109
}
110110

111111
let latest_config_id = CONFIG_CHANGE_HISTORY.last().unwrap();
112-
let suggestion = if let Some(id) = config.change_id {
113-
if &id != latest_config_id {
112+
if let Some(id) = config.change_id {
113+
if &id == latest_config_id {
114+
return None;
115+
}
116+
117+
let change_links: Vec<String> = find_recent_config_change_ids(id)
118+
.iter()
119+
.map(|id| format!("https://github.com/rust-lang/rust/pull/{id}"))
120+
.collect();
121+
if !change_links.is_empty() {
114122
msg.push_str("WARNING: there have been changes to x.py since you last updated.\n");
115-
let change_links: Vec<String> = find_recent_config_change_ids(id)
116-
.iter()
117-
.map(|id| format!("https://github.com/rust-lang/rust/pull/{id}"))
118-
.collect();
119-
if !change_links.is_empty() {
120-
msg.push_str("To see more detail about these changes, visit the following PRs:\n");
121-
for link in change_links {
122-
msg.push_str(&format!(" - {link}\n"));
123-
}
123+
msg.push_str("To see more detail about these changes, visit the following PRs:\n");
124+
125+
for link in change_links {
126+
msg.push_str(&format!(" - {link}\n"));
124127
}
128+
125129
msg.push_str("WARNING: there have been changes to x.py since you last updated.\n");
126-
format!("update `config.toml` to use `change-id = {latest_config_id}` instead")
127-
} else {
128-
return None;
130+
131+
msg.push_str("note: to silence this warning, ");
132+
msg.push_str(&format!(
133+
"update `config.toml` to use `change-id = {latest_config_id}` instead"
134+
));
129135
}
130136
} else {
131137
msg.push_str("WARNING: The `change-id` is missing in the `config.toml`. This means that you will not be able to track the major changes made to the bootstrap configurations.\n");
132-
format!("add `change-id = {latest_config_id}` at the top of `config.toml`")
138+
msg.push_str("note: to silence this warning, ");
139+
msg.push_str(&format!("add `change-id = {latest_config_id}` at the top of `config.toml`"));
133140
};
134141

135-
msg.push_str("note: to silence this warning, ");
136-
msg.push_str(&suggestion);
137-
138142
Some(msg)
139143
}

src/bootstrap/src/lib.rs

+18-6
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ const LLD_FILE_NAMES: &[&str] = &["ld.lld", "ld64.lld", "lld-link", "wasm-ld"];
7575
/// You can visit `https://github.com/rust-lang/rust/pull/{any-id-from-the-list}` to
7676
/// check for more details regarding each change.
7777
///
78-
/// If you make any major changes (such as adding new values or changing default values), please
79-
/// ensure that the associated PR ID is added to the end of this list.
78+
/// If you make any major changes (such as adding new values or changing default values),
79+
/// please ensure that the associated PR ID is added to the end of this list.
80+
/// This is necessary because the list must be sorted by the merge date.
8081
pub const CONFIG_CHANGE_HISTORY: &[usize] = &[115898, 116998, 117435, 116881];
8182

8283
/// Extra --check-cfg to add when building
@@ -1849,10 +1850,21 @@ fn envify(s: &str) -> String {
18491850
}
18501851

18511852
pub fn find_recent_config_change_ids(current_id: usize) -> Vec<usize> {
1852-
let index = CONFIG_CHANGE_HISTORY
1853-
.iter()
1854-
.position(|&id| id == current_id)
1855-
.expect(&format!("Value `{}` was not found in `CONFIG_CHANGE_HISTORY`.", current_id));
1853+
if !CONFIG_CHANGE_HISTORY.contains(&current_id) {
1854+
// If the current change-id is greater than the most recent one, return
1855+
// an empty list (it may be due to switching from a recent branch to an
1856+
// older one); otherwise, return the full list (assuming the user provided
1857+
// the incorrect change-id by accident).
1858+
if let Some(max_id) = CONFIG_CHANGE_HISTORY.iter().max() {
1859+
if &current_id > max_id {
1860+
return Vec::new();
1861+
}
1862+
}
1863+
1864+
return CONFIG_CHANGE_HISTORY.to_vec();
1865+
}
1866+
1867+
let index = CONFIG_CHANGE_HISTORY.iter().position(|&id| id == current_id).unwrap();
18561868

18571869
CONFIG_CHANGE_HISTORY
18581870
.iter()

0 commit comments

Comments
 (0)