Skip to content

Commit 912fa49

Browse files
authored
fix: ordering for flattener (#247)
Closes foundry-rs/foundry#9788 ref foundry-rs/foundry#9788 (comment) Instead of sorting by path, firstly attempts sorting by filenames
1 parent 9942ac2 commit 912fa49

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

crates/compilers/src/flatten.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,24 @@ pub fn collect_ordered_deps<D: ParsedSource + MaybeSolData>(
854854
paths_with_deps_count.push((path_deps.len(), path));
855855
}
856856

857-
paths_with_deps_count.sort();
857+
paths_with_deps_count.sort_by(|(count_0, path_0), (count_1, path_1)| {
858+
// Compare dependency counts
859+
match count_0.cmp(count_1) {
860+
o if !o.is_eq() => return o,
861+
_ => {}
862+
};
863+
864+
// Try comparing file names
865+
if let Some((name_0, name_1)) = path_0.file_name().zip(path_1.file_name()) {
866+
match name_0.cmp(name_1) {
867+
o if !o.is_eq() => return o,
868+
_ => {}
869+
}
870+
}
871+
872+
// If both filenames and dependecy counts are equal, fallback to comparing file paths
873+
path_0.cmp(path_1)
874+
});
858875

859876
let mut ordered_deps =
860877
paths_with_deps_count.into_iter().map(|(_, path)| path).collect::<Vec<_>>();

0 commit comments

Comments
 (0)