Skip to content

Commit 21a2130

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 <[email protected]>
1 parent e918db8 commit 21a2130

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
@@ -1799,10 +1799,19 @@ fn envify(s: &str) -> String {
17991799
}
18001800

18011801
pub fn find_recent_config_change_ids(current_id: usize) -> Vec<usize> {
1802-
let index = CONFIG_CHANGE_HISTORY
1803-
.iter()
1804-
.position(|&id| id == current_id)
1805-
.expect(&format!("Value `{}` was not found in `CONFIG_CHANGE_HISTORY`.", current_id));
1802+
if !CONFIG_CHANGE_HISTORY.contains(&current_id) {
1803+
// If the current change-id is greater than the most recent one,
1804+
// return an empty list; otherwise, return the full list.
1805+
if let Some(max_id) = CONFIG_CHANGE_HISTORY.iter().max() {
1806+
if &current_id > max_id {
1807+
return Vec::new();
1808+
}
1809+
}
1810+
1811+
return CONFIG_CHANGE_HISTORY.to_vec();
1812+
}
1813+
1814+
let index = CONFIG_CHANGE_HISTORY.iter().position(|&id| id == current_id).unwrap();
18061815

18071816
CONFIG_CHANGE_HISTORY
18081817
.iter()

0 commit comments

Comments
 (0)