Skip to content

Commit 81436bd

Browse files
committed
handle config profiles recursively
Signed-off-by: onur-ozkan <[email protected]>
1 parent ffc4705 commit 81436bd

File tree

1 file changed

+39
-29
lines changed

1 file changed

+39
-29
lines changed

Diff for: src/bootstrap/src/core/config/config.rs

+39-29
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,44 @@ impl Config {
13731373
Self::parse_inner(flags, Self::get_toml)
13741374
}
13751375

1376+
fn handle_profiles_recursively(
1377+
&self,
1378+
get_toml: impl Fn(&Path) -> Result<TomlConfig, toml::de::Error>,
1379+
toml: &mut TomlConfig,
1380+
) {
1381+
if let Some(profile) = &toml.profile {
1382+
let mut include_path = PathBuf::from(format!("{profile}.toml"));
1383+
1384+
if !include_path.exists() {
1385+
// Allows creating alias for profile names, allowing
1386+
// profiles to be renamed while maintaining back compatibility
1387+
// Keep in sync with `profile_aliases` in bootstrap.py
1388+
let profile_aliases = HashMap::from([("user", "dist")]);
1389+
let profile = match profile_aliases.get(profile.as_str()) {
1390+
Some(alias) => alias,
1391+
None => profile.as_str(),
1392+
};
1393+
1394+
include_path = self
1395+
.src
1396+
.join("src/bootstrap/defaults")
1397+
.join(format!("bootstrap.{profile}.toml"));
1398+
}
1399+
1400+
let mut included_toml = get_toml(&include_path).unwrap_or_else(|e| {
1401+
eprintln!(
1402+
"ERROR: Failed to parse default config profile at '{}': {e}",
1403+
include_path.display()
1404+
);
1405+
exit!(2);
1406+
});
1407+
1408+
self.handle_profiles_recursively(get_toml, &mut included_toml);
1409+
1410+
toml.merge(included_toml, ReplaceOpt::IgnoreDuplicate);
1411+
}
1412+
}
1413+
13761414
#[cfg_attr(
13771415
feature = "tracing",
13781416
instrument(
@@ -1552,35 +1590,7 @@ impl Config {
15521590
toml.profile = Some("dist".into());
15531591
}
15541592

1555-
if let Some(profile) = &toml.profile {
1556-
let mut include_path = PathBuf::from(format!("{profile}.toml"));
1557-
1558-
if !include_path.exists() {
1559-
// Allows creating alias for profile names, allowing
1560-
// profiles to be renamed while maintaining back compatibility
1561-
// Keep in sync with `profile_aliases` in bootstrap.py
1562-
let profile_aliases = HashMap::from([("user", "dist")]);
1563-
let profile = match profile_aliases.get(profile.as_str()) {
1564-
Some(alias) => alias,
1565-
None => profile.as_str(),
1566-
};
1567-
1568-
include_path = config
1569-
.src
1570-
.join("src/bootstrap/defaults")
1571-
.join(format!("bootstrap.{profile}.toml"));
1572-
}
1573-
1574-
let included_toml = get_toml(&include_path).unwrap_or_else(|e| {
1575-
eprintln!(
1576-
"ERROR: Failed to parse default config profile at '{}': {e}",
1577-
include_path.display()
1578-
);
1579-
exit!(2);
1580-
});
1581-
1582-
toml.merge(included_toml, ReplaceOpt::IgnoreDuplicate);
1583-
}
1593+
config.handle_profiles_recursively(get_toml, &mut toml);
15841594

15851595
let mut override_toml = TomlConfig::default();
15861596
for option in flags.set.iter() {

0 commit comments

Comments
 (0)