Skip to content

Commit ae4d18b

Browse files
committed
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. Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent 750c2ec commit ae4d18b

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/bootstrap/src/bin/main.rs

+12-8
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 {
112+
if let Some(id) = config.change_id {
113113
if &id != latest_config_id {
114-
msg.push_str("WARNING: there have been changes to x.py since you last updated.\n");
115114
let change_links: Vec<String> = find_recent_config_change_ids(id)
116115
.iter()
117116
.map(|id| format!("https://github.com/rust-lang/rust/pull/{id}"))
118117
.collect();
119118
if !change_links.is_empty() {
119+
msg.push_str("WARNING: there have been changes to x.py since you last updated.\n");
120120
msg.push_str("To see more detail about these changes, visit the following PRs:\n");
121+
121122
for link in change_links {
122123
msg.push_str(&format!(" - {link}\n"));
123124
}
125+
126+
msg.push_str("WARNING: there have been changes to x.py since you last updated.\n");
127+
128+
msg.push_str("note: to silence this warning, ");
129+
msg.push_str(&format!(
130+
"update `config.toml` to use `change-id = {latest_config_id}` instead"
131+
));
124132
}
125-
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")
127133
} else {
128134
return None;
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

+13-4
Original file line numberDiff line numberDiff line change
@@ -1849,10 +1849,19 @@ fn envify(s: &str) -> String {
18491849
}
18501850

18511851
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));
1852+
if !CONFIG_CHANGE_HISTORY.contains(&current_id) {
1853+
// If the current change-id is greater than the most recent one,
1854+
// return an empty list; otherwise, return the full list.
1855+
if let Some(max_id) = CONFIG_CHANGE_HISTORY.iter().max() {
1856+
if &current_id > max_id {
1857+
return Vec::new();
1858+
}
1859+
}
1860+
1861+
return CONFIG_CHANGE_HISTORY.to_vec();
1862+
}
1863+
1864+
let index = CONFIG_CHANGE_HISTORY.iter().position(|&id| id == current_id).unwrap();
18561865

18571866
CONFIG_CHANGE_HISTORY
18581867
.iter()

0 commit comments

Comments
 (0)