Skip to content

Commit 5b51f20

Browse files
authored
Unrolled build for rust-lang#121787
Rollup merge of rust-lang#121787 - onur-ozkan:improve-change-tracker, r=albertlarsan68 run change tracker even when config parse fails Please note that we are currently validating the build configuration on two entry points (e.g., profile validation is handled on the python side), and change tracker system is handled on the rust side. Once rust-lang#94829 is completed (scheduled for 2024), we will be able to handle this more effectively. Fixes rust-lang#121756
2 parents a0c20d5 + c36f493 commit 5b51f20

File tree

5 files changed

+66
-14
lines changed

5 files changed

+66
-14
lines changed

src/bootstrap/src/bin/main.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ use std::{
1515
};
1616

1717
use bootstrap::{
18-
find_recent_config_change_ids, t, Build, Config, Subcommand, CONFIG_CHANGE_HISTORY,
18+
find_recent_config_change_ids, human_readable_changes, t, Build, Config, Subcommand,
19+
CONFIG_CHANGE_HISTORY,
1920
};
2021

2122
fn main() {
@@ -164,14 +165,7 @@ fn check_version(config: &Config) -> Option<String> {
164165
}
165166

166167
msg.push_str("There have been changes to x.py since you last updated:\n");
167-
168-
for change in changes {
169-
msg.push_str(&format!(" [{}] {}\n", change.severity, change.summary));
170-
msg.push_str(&format!(
171-
" - PR Link https://github.com/rust-lang/rust/pull/{}\n",
172-
change.change_id
173-
));
174-
}
168+
msg.push_str(&human_readable_changes(&changes));
175169

176170
msg.push_str("NOTE: to silence this warning, ");
177171
msg.push_str(&format!(

src/bootstrap/src/core/config/config.rs

+28-3
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,8 @@ impl Target {
606606
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
607607
pub(crate) struct TomlConfig {
608608
changelog_seen: Option<usize>, // FIXME: Deprecated field. Remove it at 2024.
609-
change_id: Option<usize>,
609+
#[serde(flatten)]
610+
change_id: ChangeIdWrapper,
610611
build: Option<Build>,
611612
install: Option<Install>,
612613
llvm: Option<Llvm>,
@@ -616,6 +617,16 @@ pub(crate) struct TomlConfig {
616617
profile: Option<String>,
617618
}
618619

620+
/// Since we use `#[serde(deny_unknown_fields)]` on `TomlConfig`, we need a wrapper type
621+
/// for the "change-id" field to parse it even if other fields are invalid. This ensures
622+
/// that if deserialization fails due to other fields, we can still provide the changelogs
623+
/// to allow developers to potentially find the reason for the failure in the logs..
624+
#[derive(Deserialize, Default)]
625+
pub(crate) struct ChangeIdWrapper {
626+
#[serde(alias = "change-id")]
627+
pub(crate) inner: Option<usize>,
628+
}
629+
619630
/// Describes how to handle conflicts in merging two [`TomlConfig`]
620631
#[derive(Copy, Clone, Debug)]
621632
enum ReplaceOpt {
@@ -657,7 +668,7 @@ impl Merge for TomlConfig {
657668
}
658669
}
659670
self.changelog_seen.merge(changelog_seen, replace);
660-
self.change_id.merge(change_id, replace);
671+
self.change_id.inner.merge(change_id.inner, replace);
661672
do_merge(&mut self.build, build, replace);
662673
do_merge(&mut self.install, install, replace);
663674
do_merge(&mut self.llvm, llvm, replace);
@@ -1210,6 +1221,20 @@ impl Config {
12101221
toml::from_str(&contents)
12111222
.and_then(|table: toml::Value| TomlConfig::deserialize(table))
12121223
.unwrap_or_else(|err| {
1224+
if let Ok(Some(changes)) = toml::from_str(&contents)
1225+
.and_then(|table: toml::Value| ChangeIdWrapper::deserialize(table))
1226+
.and_then(|change_id| {
1227+
Ok(change_id.inner.map(|id| crate::find_recent_config_change_ids(id)))
1228+
})
1229+
{
1230+
if !changes.is_empty() {
1231+
println!(
1232+
"WARNING: There have been changes to x.py since you last updated:\n{}",
1233+
crate::human_readable_changes(&changes)
1234+
);
1235+
}
1236+
}
1237+
12131238
eprintln!("failed to parse TOML configuration '{}': {err}", file.display());
12141239
exit!(2);
12151240
})
@@ -1376,7 +1401,7 @@ impl Config {
13761401
toml.merge(override_toml, ReplaceOpt::Override);
13771402

13781403
config.changelog_seen = toml.changelog_seen;
1379-
config.change_id = toml.change_id;
1404+
config.change_id = toml.change_id.inner;
13801405

13811406
let Build {
13821407
build,

src/bootstrap/src/core/config/tests.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{flags::Flags, Config};
1+
use super::{flags::Flags, ChangeIdWrapper, Config};
22
use crate::core::config::{LldMode, TomlConfig};
33

44
use clap::CommandFactory;
@@ -237,3 +237,20 @@ fn rust_lld() {
237237
assert!(matches!(parse("rust.use-lld = true").lld_mode, LldMode::External));
238238
assert!(matches!(parse("rust.use-lld = false").lld_mode, LldMode::Unused));
239239
}
240+
241+
#[test]
242+
#[should_panic]
243+
fn parse_config_with_unknown_field() {
244+
parse("unknown-key = 1");
245+
}
246+
247+
#[test]
248+
fn parse_change_id_with_unknown_field() {
249+
let config = r#"
250+
change-id = 3461
251+
unknown-key = 1
252+
"#;
253+
254+
let change_id_wrapper: ChangeIdWrapper = toml::from_str(config).unwrap();
255+
assert_eq!(change_id_wrapper.inner, Some(3461));
256+
}

src/bootstrap/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ mod utils;
5050
pub use core::builder::PathSet;
5151
pub use core::config::flags::Subcommand;
5252
pub use core::config::Config;
53-
pub use utils::change_tracker::{find_recent_config_change_ids, CONFIG_CHANGE_HISTORY};
53+
pub use utils::change_tracker::{
54+
find_recent_config_change_ids, human_readable_changes, CONFIG_CHANGE_HISTORY,
55+
};
5456

5557
const LLVM_TOOLS: &[&str] = &[
5658
"llvm-cov", // used to generate coverage report

src/bootstrap/src/utils/change_tracker.rs

+14
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@ pub fn find_recent_config_change_ids(current_id: usize) -> Vec<ChangeInfo> {
6060
.collect()
6161
}
6262

63+
pub fn human_readable_changes(changes: &[ChangeInfo]) -> String {
64+
let mut message = String::new();
65+
66+
for change in changes {
67+
message.push_str(&format!(" [{}] {}\n", change.severity, change.summary));
68+
message.push_str(&format!(
69+
" - PR Link https://github.com/rust-lang/rust/pull/{}\n",
70+
change.change_id
71+
));
72+
}
73+
74+
message
75+
}
76+
6377
/// Keeps track of major changes made to the bootstrap configuration.
6478
///
6579
/// If you make any major changes (such as adding new values or changing default values),

0 commit comments

Comments
 (0)