Skip to content

Commit

Permalink
fix: ordering for flattener (#247)
Browse files Browse the repository at this point in the history
Closes foundry-rs/foundry#9788

ref
foundry-rs/foundry#9788 (comment)

Instead of sorting by path, firstly attempts sorting by filenames
  • Loading branch information
klkvr authored Feb 6, 2025
1 parent 9942ac2 commit 912fa49
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion crates/compilers/src/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,24 @@ pub fn collect_ordered_deps<D: ParsedSource + MaybeSolData>(
paths_with_deps_count.push((path_deps.len(), path));
}

paths_with_deps_count.sort();
paths_with_deps_count.sort_by(|(count_0, path_0), (count_1, path_1)| {
// Compare dependency counts
match count_0.cmp(count_1) {
o if !o.is_eq() => return o,
_ => {}
};

// Try comparing file names
if let Some((name_0, name_1)) = path_0.file_name().zip(path_1.file_name()) {
match name_0.cmp(name_1) {
o if !o.is_eq() => return o,
_ => {}
}
}

// If both filenames and dependecy counts are equal, fallback to comparing file paths
path_0.cmp(path_1)
});

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

0 comments on commit 912fa49

Please sign in to comment.