Skip to content

Commit af6eedc

Browse files
committed
disable download-rustc if CI rustc has unsupported options
Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent a1aaf18 commit af6eedc

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

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

+34-12
Original file line numberDiff line numberDiff line change
@@ -1200,19 +1200,19 @@ impl Config {
12001200
}
12011201

12021202
#[cfg(test)]
1203-
fn get_toml(_: &Path) -> TomlConfig {
1204-
TomlConfig::default()
1203+
fn get_toml(_: &Path) -> Result<TomlConfig, toml::de::Error> {
1204+
Ok(TomlConfig::default())
12051205
}
12061206

12071207
#[cfg(not(test))]
1208-
fn get_toml(file: &Path) -> TomlConfig {
1208+
fn get_toml(file: &Path) -> Result<TomlConfig, toml::de::Error> {
12091209
let contents =
12101210
t!(fs::read_to_string(file), format!("config file {} not found", file.display()));
12111211
// Deserialize to Value and then TomlConfig to prevent the Deserialize impl of
12121212
// TomlConfig and sub types to be monomorphized 5x by toml.
12131213
toml::from_str(&contents)
12141214
.and_then(|table: toml::Value| TomlConfig::deserialize(table))
1215-
.unwrap_or_else(|err| {
1215+
.inspect_err(|_| {
12161216
if let Ok(Some(changes)) = toml::from_str(&contents)
12171217
.and_then(|table: toml::Value| ChangeIdWrapper::deserialize(table))
12181218
.map(|change_id| change_id.inner.map(crate::find_recent_config_change_ids))
@@ -1224,17 +1224,17 @@ impl Config {
12241224
);
12251225
}
12261226
}
1227-
1228-
eprintln!("failed to parse TOML configuration '{}': {err}", file.display());
1229-
exit!(2);
12301227
})
12311228
}
12321229

12331230
pub fn parse(flags: Flags) -> Config {
12341231
Self::parse_inner(flags, Self::get_toml)
12351232
}
12361233

1237-
pub(crate) fn parse_inner(mut flags: Flags, get_toml: impl Fn(&Path) -> TomlConfig) -> Config {
1234+
pub(crate) fn parse_inner(
1235+
mut flags: Flags,
1236+
get_toml: impl Fn(&Path) -> Result<TomlConfig, toml::de::Error>,
1237+
) -> Config {
12381238
let mut config = Config::default_opts();
12391239

12401240
// Set flags.
@@ -1342,7 +1342,10 @@ impl Config {
13421342
} else {
13431343
toml_path.clone()
13441344
});
1345-
get_toml(&toml_path)
1345+
get_toml(&toml_path).unwrap_or_else(|e| {
1346+
eprintln!("ERROR: Failed to parse '{}': {e}", toml_path.display());
1347+
exit!(2);
1348+
})
13461349
} else {
13471350
config.config = None;
13481351
TomlConfig::default()
@@ -1373,7 +1376,13 @@ impl Config {
13731376
include_path.push("bootstrap");
13741377
include_path.push("defaults");
13751378
include_path.push(format!("config.{include}.toml"));
1376-
let included_toml = get_toml(&include_path);
1379+
let included_toml = get_toml(&include_path).unwrap_or_else(|e| {
1380+
eprintln!(
1381+
"ERROR: Failed to parse default config profile at '{}': {e}",
1382+
include_path.display()
1383+
);
1384+
exit!(2);
1385+
});
13771386
toml.merge(included_toml, ReplaceOpt::IgnoreDuplicate);
13781387
}
13791388

@@ -2331,8 +2340,21 @@ impl Config {
23312340
if let Some(config_path) = &self.config {
23322341
let builder_config_path =
23332342
self.out.join(self.build.triple).join("ci-rustc").join(BUILDER_CONFIG_FILENAME);
2334-
let ci_config_toml = Self::get_toml(&builder_config_path);
2335-
let current_config_toml = Self::get_toml(config_path);
2343+
2344+
let ci_config_toml = match Self::get_toml(&builder_config_path) {
2345+
Ok(ci_config_toml) => ci_config_toml,
2346+
Err(e) if e.to_string().contains("unknown field") => {
2347+
println!("WARNING: CI rustc has some fields that are no longer supported in bootstrap; download-rustc will be disabled.");
2348+
println!("HELP: Consider rebasing to a newer commit if available.");
2349+
return None;
2350+
},
2351+
Err(e) => {
2352+
eprintln!("ERROR: Failed to parse CI rustc config at '{}': {e}", builder_config_path.display());
2353+
exit!(2);
2354+
},
2355+
};
2356+
2357+
let current_config_toml = Self::get_toml(config_path).unwrap();
23362358

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

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

+4-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::core::config::{LldMode, Target, TargetSelection, TomlConfig};
1414
fn parse(config: &str) -> Config {
1515
Config::parse_inner(
1616
Flags::parse(&["check".to_string(), "--config=/does/not/exist".to_string()]),
17-
|&_| toml::from_str(&config).unwrap(),
17+
|&_| toml::from_str(&config),
1818
)
1919
}
2020

@@ -151,7 +151,6 @@ runner = "x86_64-runner"
151151
152152
"#,
153153
)
154-
.unwrap()
155154
},
156155
);
157156
assert_eq!(config.change_id, Some(1), "setting top-level value");
@@ -208,13 +207,13 @@ fn override_toml_duplicate() {
208207
"--set=change-id=1".to_owned(),
209208
"--set=change-id=2".to_owned(),
210209
]),
211-
|&_| toml::from_str("change-id = 0").unwrap(),
210+
|&_| toml::from_str("change-id = 0"),
212211
);
213212
}
214213

215214
#[test]
216215
fn profile_user_dist() {
217-
fn get_toml(file: &Path) -> TomlConfig {
216+
fn get_toml(file: &Path) -> Result<TomlConfig, toml::de::Error> {
218217
let contents =
219218
if file.ends_with("config.toml") || env::var_os("RUST_BOOTSTRAP_CONFIG").is_some() {
220219
"profile = \"user\"".to_owned()
@@ -223,9 +222,7 @@ fn profile_user_dist() {
223222
std::fs::read_to_string(file).unwrap()
224223
};
225224

226-
toml::from_str(&contents)
227-
.and_then(|table: toml::Value| TomlConfig::deserialize(table))
228-
.unwrap()
225+
toml::from_str(&contents).and_then(|table: toml::Value| TomlConfig::deserialize(table))
229226
}
230227
Config::parse_inner(Flags::parse(&["check".to_owned()]), get_toml);
231228
}

0 commit comments

Comments
 (0)