Skip to content

Commit

Permalink
disable download-rustc if CI rustc has unsupported options
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <[email protected]>
  • Loading branch information
onur-ozkan committed Aug 14, 2024
1 parent 0935c86 commit 469d593
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
46 changes: 34 additions & 12 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1200,19 +1200,19 @@ impl Config {
}

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

#[cfg(not(test))]
fn get_toml(file: &Path) -> TomlConfig {
fn get_toml(file: &Path) -> Result<TomlConfig, toml::de::Error> {
let contents =
t!(fs::read_to_string(file), format!("config file {} not found", file.display()));
// Deserialize to Value and then TomlConfig to prevent the Deserialize impl of
// TomlConfig and sub types to be monomorphized 5x by toml.
toml::from_str(&contents)
.and_then(|table: toml::Value| TomlConfig::deserialize(table))
.unwrap_or_else(|err| {
.inspect_err(|_| {
if let Ok(Some(changes)) = toml::from_str(&contents)
.and_then(|table: toml::Value| ChangeIdWrapper::deserialize(table))
.map(|change_id| change_id.inner.map(crate::find_recent_config_change_ids))
Expand All @@ -1224,17 +1224,17 @@ impl Config {
);
}
}

eprintln!("failed to parse TOML configuration '{}': {err}", file.display());
exit!(2);
})
}

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

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

// Set flags.
Expand Down Expand Up @@ -1342,7 +1342,10 @@ impl Config {
} else {
toml_path.clone()
});
get_toml(&toml_path)
get_toml(&toml_path).unwrap_or_else(|e| {
eprintln!("ERROR: Failed to parse '{}': {e}", toml_path.display());
exit!(2);
})
} else {
config.config = None;
TomlConfig::default()
Expand Down Expand Up @@ -1373,7 +1376,13 @@ impl Config {
include_path.push("bootstrap");
include_path.push("defaults");
include_path.push(format!("config.{include}.toml"));
let included_toml = get_toml(&include_path);
let included_toml = get_toml(&include_path).unwrap_or_else(|e| {
eprintln!(
"ERROR: Failed to parse default config profile at '{}': {e}",
include_path.display()
);
exit!(2);
});
toml.merge(included_toml, ReplaceOpt::IgnoreDuplicate);
}

Expand Down Expand Up @@ -2331,8 +2340,21 @@ impl Config {
if let Some(config_path) = &self.config {
let builder_config_path =
self.out.join(self.build.triple).join("ci-rustc").join(BUILDER_CONFIG_FILENAME);
let ci_config_toml = Self::get_toml(&builder_config_path);
let current_config_toml = Self::get_toml(config_path);

let ci_config_toml = match Self::get_toml(&builder_config_path) {
Ok(ci_config_toml) => ci_config_toml,
Err(e) if e.to_string().contains("unknown field") => {
println!("WARNING: CI rustc has some fields that are no longer supported in bootstrap; download-rustc will be disabled.");
println!("HELP: Consider rebasing to a newer commit if available.");
return None;
},
Err(e) => {
eprintln!("ERROR: Failed to parse CI rustc config at '{}': {e}", builder_config_path.display());
exit!(2);
},
};

let current_config_toml = Self::get_toml(config_path).unwrap();

// Check the config compatibility
// FIXME: this doesn't cover `--set` flags yet.
Expand Down
11 changes: 4 additions & 7 deletions src/bootstrap/src/core/config/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::core::config::{LldMode, Target, TargetSelection, TomlConfig};
fn parse(config: &str) -> Config {
Config::parse_inner(
Flags::parse(&["check".to_string(), "--config=/does/not/exist".to_string()]),
|&_| toml::from_str(&config).unwrap(),
|&_| toml::from_str(&config),
)
}

Expand Down Expand Up @@ -151,7 +151,6 @@ runner = "x86_64-runner"
"#,
)
.unwrap()
},
);
assert_eq!(config.change_id, Some(1), "setting top-level value");
Expand Down Expand Up @@ -208,13 +207,13 @@ fn override_toml_duplicate() {
"--set=change-id=1".to_owned(),
"--set=change-id=2".to_owned(),
]),
|&_| toml::from_str("change-id = 0").unwrap(),
|&_| toml::from_str("change-id = 0"),
);
}

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

toml::from_str(&contents)
.and_then(|table: toml::Value| TomlConfig::deserialize(table))
.unwrap()
toml::from_str(&contents).and_then(|table: toml::Value| TomlConfig::deserialize(table))
}
Config::parse_inner(Flags::parse(&["check".to_owned()]), get_toml);
}
Expand Down

0 comments on commit 469d593

Please sign in to comment.