Skip to content

Commit d4cf5b3

Browse files
onur-ozkanrezwanahmedsami
authored andcommitted
disable download-rustc if CI rustc has unsupported options
Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent 0275bc5 commit d4cf5b3

File tree

1 file changed

+34
-12
lines changed

1 file changed

+34
-12
lines changed

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

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,19 +1212,19 @@ impl Config {
12121212
}
12131213

12141214
#[cfg(test)]
1215-
fn get_toml(_: &Path) -> TomlConfig {
1216-
TomlConfig::default()
1215+
fn get_toml(_: &Path) -> Result<TomlConfig, toml::de::Error> {
1216+
Ok(TomlConfig::default())
12171217
}
12181218

12191219
#[cfg(not(test))]
1220-
fn get_toml(file: &Path) -> TomlConfig {
1220+
fn get_toml(file: &Path) -> Result<TomlConfig, toml::de::Error> {
12211221
let contents =
12221222
t!(fs::read_to_string(file), format!("config file {} not found", file.display()));
12231223
// Deserialize to Value and then TomlConfig to prevent the Deserialize impl of
12241224
// TomlConfig and sub types to be monomorphized 5x by toml.
12251225
toml::from_str(&contents)
12261226
.and_then(|table: toml::Value| TomlConfig::deserialize(table))
1227-
.unwrap_or_else(|err| {
1227+
.inspect_err(|_| {
12281228
if let Ok(Some(changes)) = toml::from_str(&contents)
12291229
.and_then(|table: toml::Value| ChangeIdWrapper::deserialize(table))
12301230
.map(|change_id| change_id.inner.map(crate::find_recent_config_change_ids))
@@ -1236,17 +1236,17 @@ impl Config {
12361236
);
12371237
}
12381238
}
1239-
1240-
eprintln!("failed to parse TOML configuration '{}': {err}", file.display());
1241-
exit!(2);
12421239
})
12431240
}
12441241

12451242
pub fn parse(flags: Flags) -> Config {
12461243
Self::parse_inner(flags, Self::get_toml)
12471244
}
12481245

1249-
pub(crate) fn parse_inner(mut flags: Flags, get_toml: impl Fn(&Path) -> TomlConfig) -> Config {
1246+
pub(crate) fn parse_inner(
1247+
mut flags: Flags,
1248+
get_toml: impl Fn(&Path) -> Result<TomlConfig, toml::de::Error>,
1249+
) -> Config {
12501250
let mut config = Config::default_opts();
12511251

12521252
// Set flags.
@@ -1354,7 +1354,10 @@ impl Config {
13541354
} else {
13551355
toml_path.clone()
13561356
});
1357-
get_toml(&toml_path)
1357+
get_toml(&toml_path).unwrap_or_else(|e| {
1358+
eprintln!("ERROR: Failed to parse '{}': {e}", toml_path.display());
1359+
exit!(2);
1360+
})
13581361
} else {
13591362
config.config = None;
13601363
TomlConfig::default()
@@ -1385,7 +1388,13 @@ impl Config {
13851388
include_path.push("bootstrap");
13861389
include_path.push("defaults");
13871390
include_path.push(format!("config.{include}.toml"));
1388-
let included_toml = get_toml(&include_path);
1391+
let included_toml = get_toml(&include_path).unwrap_or_else(|e| {
1392+
eprintln!(
1393+
"ERROR: Failed to parse default config profile at '{}': {e}",
1394+
include_path.display()
1395+
);
1396+
exit!(2);
1397+
});
13891398
toml.merge(included_toml, ReplaceOpt::IgnoreDuplicate);
13901399
}
13911400

@@ -2343,8 +2352,21 @@ impl Config {
23432352
if let Some(config_path) = &self.config {
23442353
let builder_config_path =
23452354
self.out.join(self.build.triple).join("ci-rustc").join(BUILDER_CONFIG_FILENAME);
2346-
let ci_config_toml = Self::get_toml(&builder_config_path);
2347-
let current_config_toml = Self::get_toml(config_path);
2355+
2356+
let ci_config_toml = match Self::get_toml(&builder_config_path) {
2357+
Ok(ci_config_toml) => ci_config_toml,
2358+
Err(e) if e.to_string().contains("unknown field") => {
2359+
println!("WARNING: CI rustc has some fields that are no longer supported in bootstrap; download-rustc will be disabled.");
2360+
println!("HELP: Consider rebasing to a newer commit if available.");
2361+
return None;
2362+
},
2363+
Err(e) => {
2364+
eprintln!("ERROR: Failed to parse CI rustc config at '{}': {e}", builder_config_path.display());
2365+
exit!(2);
2366+
},
2367+
};
2368+
2369+
let current_config_toml = Self::get_toml(config_path).unwrap();
23482370

23492371
// Check the config compatibility
23502372
// FIXME: this doesn't cover `--set` flags yet.

0 commit comments

Comments
 (0)