diff --git a/ethers-solc/src/lib.rs b/ethers-solc/src/lib.rs index c2fcd7058..69ab0e6de 100644 --- a/ethers-solc/src/lib.rs +++ b/ethers-solc/src/lib.rs @@ -3,7 +3,7 @@ pub mod artifacts; pub mod sourcemap; pub use artifacts::{CompilerInput, CompilerOutput, EvmVersion}; -use std::collections::BTreeMap; +use std::collections::{BTreeMap, HashSet}; mod artifact_output; pub mod cache; @@ -440,11 +440,17 @@ impl Project { let target_index = graph.files().get(target).ok_or_else(|| { SolcError::msg(format!("cannot resolve file at {:?}", target.display())) })?; + let mut sources = Vec::new(); + let mut unique_paths = HashSet::new(); let (path, source) = graph.node(*target_index).unpack(); + unique_paths.insert(path.clone()); sources.push((path, source)); sources.extend( - graph.all_imported_nodes(*target_index).map(|index| graph.node(index).unpack()), + graph + .all_imported_nodes(*target_index) + .map(|index| graph.node(index).unpack()) + .filter(|(p, _)| unique_paths.insert(p.to_path_buf())), ); let root = self.root();