From 7cf89ec0bd44910dc3b981a2c9fab3ca8a6fdc69 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Sat, 27 Jul 2024 04:00:49 +0800 Subject: [PATCH] fix: make remappings resolution more deterministic (#176) --- crates/artifacts/solc/src/remappings.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/artifacts/solc/src/remappings.rs b/crates/artifacts/solc/src/remappings.rs index 8a5bcc4a..6767cb56 100644 --- a/crates/artifacts/solc/src/remappings.rs +++ b/crates/artifacts/solc/src/remappings.rs @@ -1,7 +1,7 @@ use foundry_compilers_core::utils; use serde::{Deserialize, Serialize}; use std::{ - collections::{hash_map::Entry, HashMap, HashSet}, + collections::{btree_map::Entry, BTreeMap, HashSet}, fmt, path::{Path, PathBuf}, str::FromStr, @@ -209,7 +209,11 @@ impl Remapping { /// prioritize /// - ("a", "1/2") over ("a", "1/2/3") /// - if a path ends with `src` - fn insert_prioritized(mappings: &mut HashMap, key: String, path: PathBuf) { + fn insert_prioritized( + mappings: &mut BTreeMap, + key: String, + path: PathBuf, + ) { match mappings.entry(key) { Entry::Occupied(mut e) => { if e.get().components().count() > path.components().count() @@ -226,13 +230,14 @@ impl Remapping { } // all combined remappings from all subdirs - let mut all_remappings = HashMap::new(); + let mut all_remappings = BTreeMap::new(); let is_inside_node_modules = dir.ends_with("node_modules"); let mut visited_symlink_dirs = HashSet::new(); // iterate over all dirs that are children of the root for dir in walkdir::WalkDir::new(dir) + .sort_by_file_name() .follow_links(true) .min_depth(1) .max_depth(1) @@ -641,6 +646,7 @@ fn find_remapping_candidates( // scan all entries in the current dir for entry in walkdir::WalkDir::new(current_dir) + .sort_by_file_name() .follow_links(true) .min_depth(1) .max_depth(1)