Skip to content

Commit 06ef7b7

Browse files
committed
refactor(config): Move TOML file reading methods to 'toml' submodule
This commit moves the `Config` struct's methods responsible for reading and deserializing `bootstrap.toml` files into `TomlConfig` instances to `src/bootstrap/config/toml/mod.rs`. Specifically, `Config::get_builder_toml`, `Config::get_toml`, and `Config::get_toml_inner` are now located within the `toml` submodule.
1 parent 0d7864a commit 06ef7b7

File tree

3 files changed

+56
-54
lines changed

3 files changed

+56
-54
lines changed

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

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use std::{env, fs};
1717
use build_helper::ci::CiEnv;
1818
use build_helper::exit;
1919
use build_helper::git::{GitConfig, PathFreshness, check_path_modifications, output_result};
20-
use serde::Deserialize;
2120
#[cfg(feature = "tracing")]
2221
use tracing::{instrument, span};
2322

@@ -26,13 +25,12 @@ use crate::core::build_steps::llvm::LLVM_INVALIDATION_PATHS;
2625
use crate::core::config::flags::Color;
2726
pub use crate::core::config::flags::Subcommand;
2827
use crate::core::config::parsing::check_incompatible_options_for_ci_rustc;
29-
use crate::core::config::toml::change_id::{ChangeId, ChangeIdWrapper};
28+
use crate::core::config::toml::change_id::ChangeId;
3029
use crate::core::config::toml::common::{
3130
DebuginfoLevel, LlvmLibunwind, SplitDebuginfo, StringOrBool,
3231
};
3332
use crate::core::config::toml::rust::{LldMode, RustOptimize};
3433
use crate::core::config::toml::target::Target;
35-
use crate::core::config::toml::*;
3634
use crate::core::config::types::{DryRun, GccCiMode, RustcLto};
3735
use crate::core::download::is_download_ci_available;
3836
use crate::utils::channel;
@@ -58,14 +56,6 @@ pub const RUSTC_IF_UNCHANGED_ALLOWED_PATHS: &[&str] = &[
5856
":!triagebot.toml",
5957
];
6058

61-
/// This file is embedded in the overlay directory of the tarball sources. It is
62-
/// useful in scenarios where developers want to see how the tarball sources were
63-
/// generated.
64-
///
65-
/// We also use this file to compare the host's bootstrap.toml against the CI rustc builder
66-
/// configuration to detect any incompatible options.
67-
pub const BUILDER_CONFIG_FILENAME: &str = "builder-config";
68-
6959
/// Global configuration for the entire build and/or bootstrap.
7060
///
7161
/// This structure is parsed from `bootstrap.toml`, and some of the fields are inferred from `git` or build-time parameters.
@@ -358,47 +348,6 @@ impl Config {
358348
Self::parse_inner(flags, Self::get_toml)
359349
}
360350

361-
pub(crate) fn get_builder_toml(&self, build_name: &str) -> Result<TomlConfig, toml::de::Error> {
362-
if self.dry_run() {
363-
return Ok(TomlConfig::default());
364-
}
365-
366-
let builder_config_path =
367-
self.out.join(self.build.triple).join(build_name).join(BUILDER_CONFIG_FILENAME);
368-
Self::get_toml(&builder_config_path)
369-
}
370-
371-
pub(crate) fn get_toml(file: &Path) -> Result<TomlConfig, toml::de::Error> {
372-
#[cfg(test)]
373-
return Ok(TomlConfig::default());
374-
375-
#[cfg(not(test))]
376-
Self::get_toml_inner(file)
377-
}
378-
379-
pub(crate) fn get_toml_inner(file: &Path) -> Result<TomlConfig, toml::de::Error> {
380-
let contents =
381-
t!(fs::read_to_string(file), format!("config file {} not found", file.display()));
382-
// Deserialize to Value and then TomlConfig to prevent the Deserialize impl of
383-
// TomlConfig and sub types to be monomorphized 5x by toml.
384-
toml::from_str(&contents)
385-
.and_then(|table: toml::Value| TomlConfig::deserialize(table))
386-
.inspect_err(|_| {
387-
if let Ok(ChangeIdWrapper { inner: Some(ChangeId::Id(id)) }) =
388-
toml::from_str::<toml::Value>(&contents)
389-
.and_then(|table: toml::Value| ChangeIdWrapper::deserialize(table))
390-
{
391-
let changes = crate::find_recent_config_change_ids(id);
392-
if !changes.is_empty() {
393-
println!(
394-
"WARNING: There have been changes to x.py since you last updated:\n{}",
395-
crate::human_readable_changes(changes)
396-
);
397-
}
398-
}
399-
})
400-
}
401-
402351
pub fn dry_run(&self) -> bool {
403352
match self.dry_run {
404353
DryRun::Disabled => false,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub mod types;
1010

1111
pub use config::*;
1212
pub use target_selection::TargetSelection;
13+
pub use toml::BUILDER_CONFIG_FILENAME;
1314
pub use toml::change_id::ChangeId;
1415
pub use toml::common::*;
1516
pub use toml::rust::LldMode;

src/bootstrap/src/core/config/toml/mod.rs

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//! It also houses the `Merge` trait and `define_config!` macro, which are essential
77
//! for handling these raw TOML structures.
88
9+
use serde::Deserialize;
910
use serde_derive::Deserialize;
1011
pub mod build;
1112
pub mod change_id;
@@ -20,7 +21,7 @@ pub mod rust;
2021
pub mod target;
2122

2223
use build::Build;
23-
use change_id::ChangeIdWrapper;
24+
use change_id::{ChangeId, ChangeIdWrapper};
2425
use dist::Dist;
2526
use gcc::Gcc;
2627
use install::Install;
@@ -30,7 +31,7 @@ use rust::Rust;
3031
use target::TomlTarget;
3132

3233
use crate::core::config::toml::common::ReplaceOpt;
33-
use crate::{Config, HashMap, HashSet, PathBuf, exit};
34+
use crate::{Config, HashMap, HashSet, Path, PathBuf, exit, fs, t};
3435

3536
/// Structure of the `bootstrap.toml` file that configuration is read from.
3637
///
@@ -133,3 +134,54 @@ impl Merge for TomlConfig {
133134
}
134135
}
135136
}
137+
138+
/// This file is embedded in the overlay directory of the tarball sources. It is
139+
/// useful in scenarios where developers want to see how the tarball sources were
140+
/// generated.
141+
///
142+
/// We also use this file to compare the host's bootstrap.toml against the CI rustc builder
143+
/// configuration to detect any incompatible options.
144+
pub const BUILDER_CONFIG_FILENAME: &str = "builder-config";
145+
146+
impl Config {
147+
pub(crate) fn get_builder_toml(&self, build_name: &str) -> Result<TomlConfig, toml::de::Error> {
148+
if self.dry_run() {
149+
return Ok(TomlConfig::default());
150+
}
151+
152+
let builder_config_path =
153+
self.out.join(self.build.triple).join(build_name).join(BUILDER_CONFIG_FILENAME);
154+
Self::get_toml(&builder_config_path)
155+
}
156+
157+
pub(crate) fn get_toml(file: &Path) -> Result<TomlConfig, toml::de::Error> {
158+
#[cfg(test)]
159+
return Ok(TomlConfig::default());
160+
161+
#[cfg(not(test))]
162+
Self::get_toml_inner(file)
163+
}
164+
165+
pub(crate) fn get_toml_inner(file: &Path) -> Result<TomlConfig, toml::de::Error> {
166+
let contents =
167+
t!(fs::read_to_string(file), format!("config file {} not found", file.display()));
168+
// Deserialize to Value and then TomlConfig to prevent the Deserialize impl of
169+
// TomlConfig and sub types to be monomorphized 5x by toml.
170+
toml::from_str(&contents)
171+
.and_then(|table: toml::Value| TomlConfig::deserialize(table))
172+
.inspect_err(|_| {
173+
if let Ok(ChangeIdWrapper { inner: Some(ChangeId::Id(id)) }) =
174+
toml::from_str::<toml::Value>(&contents)
175+
.and_then(|table: toml::Value| ChangeIdWrapper::deserialize(table))
176+
{
177+
let changes = crate::find_recent_config_change_ids(id);
178+
if !changes.is_empty() {
179+
println!(
180+
"WARNING: There have been changes to x.py since you last updated:\n{}",
181+
crate::human_readable_changes(changes)
182+
);
183+
}
184+
}
185+
})
186+
}
187+
}

0 commit comments

Comments
 (0)