Skip to content

Commit dda6d65

Browse files
committed
implement cyclic inclusion handling
Signed-off-by: onur-ozkan <[email protected]>
1 parent 48a1103 commit dda6d65

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

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

+23-13
Original file line numberDiff line numberDiff line change
@@ -745,19 +745,20 @@ enum ReplaceOpt {
745745
}
746746

747747
trait Merge {
748-
fn merge(&mut self, other: Self, replace: ReplaceOpt);
748+
fn merge(&mut self, extension_path: Option<PathBuf>, other: Self, replace: ReplaceOpt);
749749
}
750750

751751
impl Merge for TomlConfig {
752752
fn merge(
753753
&mut self,
754+
extension_path: Option<PathBuf>,
754755
TomlConfig { build, install, llvm, gcc, rust, dist, target, profile, change_id, include }: Self,
755756
replace: ReplaceOpt,
756757
) {
757758
fn do_merge<T: Merge>(x: &mut Option<T>, y: Option<T>, replace: ReplaceOpt) {
758759
if let Some(new) = y {
759760
if let Some(original) = x {
760-
original.merge(new, replace);
761+
original.merge(None, new, replace);
761762
} else {
762763
*x = Some(new);
763764
}
@@ -772,11 +773,20 @@ impl Merge for TomlConfig {
772773
);
773774
exit!(2);
774775
});
775-
self.merge(included_toml, ReplaceOpt::Override);
776+
777+
if let Some(extension_path) = &extension_path {
778+
assert!(
779+
!included_toml.include.clone().unwrap_or_default().contains(extension_path),
780+
"Cyclic inclusion detected in extension: {}",
781+
extension_path.display()
782+
);
783+
}
784+
785+
self.merge(Some(include_path), included_toml, ReplaceOpt::Override);
776786
}
777787

778-
self.change_id.inner.merge(change_id.inner, replace);
779-
self.profile.merge(profile, replace);
788+
self.change_id.inner.merge(None, change_id.inner, replace);
789+
self.profile.merge(None, profile, replace);
780790

781791
do_merge(&mut self.build, build, replace);
782792
do_merge(&mut self.install, install, replace);
@@ -791,7 +801,7 @@ impl Merge for TomlConfig {
791801
(Some(original_target), Some(new_target)) => {
792802
for (triple, new) in new_target {
793803
if let Some(original) = original_target.get_mut(&triple) {
794-
original.merge(new, replace);
804+
original.merge(None, new, replace);
795805
} else {
796806
original_target.insert(triple, new);
797807
}
@@ -812,7 +822,7 @@ macro_rules! define_config {
812822
}
813823

814824
impl Merge for $name {
815-
fn merge(&mut self, other: Self, replace: ReplaceOpt) {
825+
fn merge(&mut self, _extension_path: Option<PathBuf>, other: Self, replace: ReplaceOpt) {
816826
$(
817827
match replace {
818828
ReplaceOpt::IgnoreDuplicate => {
@@ -912,7 +922,7 @@ macro_rules! define_config {
912922
}
913923

914924
impl<T> Merge for Option<T> {
915-
fn merge(&mut self, other: Self, replace: ReplaceOpt) {
925+
fn merge(&mut self, _extension_path: Option<PathBuf>, other: Self, replace: ReplaceOpt) {
916926
match replace {
917927
ReplaceOpt::IgnoreDuplicate => {
918928
if self.is_none() {
@@ -1608,7 +1618,7 @@ impl Config {
16081618
);
16091619
exit!(2);
16101620
});
1611-
toml.merge(included_toml, ReplaceOpt::IgnoreDuplicate);
1621+
toml.merge(None, included_toml, ReplaceOpt::IgnoreDuplicate);
16121622
}
16131623

16141624
for include_path in toml.include.clone().unwrap_or_default() {
@@ -1619,7 +1629,7 @@ impl Config {
16191629
);
16201630
exit!(2);
16211631
});
1622-
toml.merge(included_toml, ReplaceOpt::Override);
1632+
toml.merge(Some(include_path), included_toml, ReplaceOpt::Override);
16231633
}
16241634

16251635
let mut override_toml = TomlConfig::default();
@@ -1630,7 +1640,7 @@ impl Config {
16301640

16311641
let mut err = match get_table(option) {
16321642
Ok(v) => {
1633-
override_toml.merge(v, ReplaceOpt::ErrorOnDuplicate);
1643+
override_toml.merge(None, v, ReplaceOpt::ErrorOnDuplicate);
16341644
continue;
16351645
}
16361646
Err(e) => e,
@@ -1641,7 +1651,7 @@ impl Config {
16411651
if !value.contains('"') {
16421652
match get_table(&format!(r#"{key}="{value}""#)) {
16431653
Ok(v) => {
1644-
override_toml.merge(v, ReplaceOpt::ErrorOnDuplicate);
1654+
override_toml.merge(None, v, ReplaceOpt::ErrorOnDuplicate);
16451655
continue;
16461656
}
16471657
Err(e) => err = e,
@@ -1651,7 +1661,7 @@ impl Config {
16511661
eprintln!("failed to parse override `{option}`: `{err}");
16521662
exit!(2)
16531663
}
1654-
toml.merge(override_toml, ReplaceOpt::Override);
1664+
toml.merge(None, override_toml, ReplaceOpt::Override);
16551665

16561666
config.change_id = toml.change_id.inner;
16571667

0 commit comments

Comments
 (0)