diff --git a/crates/artifacts/solc/src/sources.rs b/crates/artifacts/solc/src/sources.rs index b8ac1c821..2b929ad7a 100644 --- a/crates/artifacts/solc/src/sources.rs +++ b/crates/artifacts/solc/src/sources.rs @@ -22,6 +22,14 @@ impl Sources { Self::default() } + /// Joins all paths relative to `root`. + pub fn make_absolute(&mut self, root: &Path) { + self.0 = std::mem::take(&mut self.0) + .into_iter() + .map(|(path, source)| (root.join(path), source)) + .collect(); + } + /// Returns `true` if no sources should have optimized output selection. pub fn all_dirty(&self) -> bool { self.0.values().all(|s| s.is_dirty()) @@ -169,7 +177,7 @@ impl Source { /// Recursively finds all source files under the given dir path and reads them all #[cfg(feature = "walkdir")] pub fn read_all_from(dir: &Path, extensions: &[&str]) -> Result { - Self::read_all_files(utils::source_files(dir, extensions)) + Self::read_all(utils::source_files_iter(dir, extensions)) } /// Recursively finds all solidity and yul files under the given dir path and reads them all @@ -178,14 +186,12 @@ impl Source { Self::read_all_from(dir, utils::SOLC_EXTENSIONS) } - /// Reads all source files of the given vec - /// - /// Depending on the len of the vec it will try to read the files in parallel + /// Reads all source files of the given list. pub fn read_all_files(files: Vec) -> Result { Self::read_all(files) } - /// Reads all files + /// Reads all of the given files. #[instrument(name = "Source::read_all", skip_all)] pub fn read_all(files: I) -> Result where diff --git a/crates/compilers/src/config.rs b/crates/compilers/src/config.rs index 3f3b5f451..326bd325b 100644 --- a/crates/compilers/src/config.rs +++ b/crates/compilers/src/config.rs @@ -616,7 +616,7 @@ impl ProjectPathsConfig { /// Returns the combined set of `Self::read_sources` + `Self::read_tests` + `Self::read_scripts` pub fn read_input_files(&self) -> Result { - Ok(Source::read_all_files(self.input_files())?) + Ok(Source::read_all(self.input_files_iter())?) } } diff --git a/crates/compilers/src/flatten.rs b/crates/compilers/src/flatten.rs index ce34243c1..5ec755d0c 100644 --- a/crates/compilers/src/flatten.rs +++ b/crates/compilers/src/flatten.rs @@ -209,7 +209,7 @@ impl Flattener { let output = output.compiler_output; - let sources = Source::read_all_files(vec![target.to_path_buf()])?; + let sources = Source::read_all([target.to_path_buf()])?; let graph = Graph::::resolve_sources(&project.paths, sources)?; let ordered_sources = collect_ordered_deps(target, &project.paths, &graph)?; diff --git a/crates/compilers/src/resolver/mod.rs b/crates/compilers/src/resolver/mod.rs index feb4abc14..4a9cc85fc 100644 --- a/crates/compilers/src/resolver/mod.rs +++ b/crates/compilers/src/resolver/mod.rs @@ -400,6 +400,9 @@ impl Graph

{ Ok(()) } + // The cache relies on the absolute paths relative to the project root as cache keys. + sources.make_absolute(&paths.root); + let mut parser = P::new(paths.with_language_ref()); // we start off by reading all input files, which includes all solidity files from the @@ -566,14 +569,14 @@ impl Graph

{ let mut versioned_sources = Vec::with_capacity(versioned_nodes.len()); for (version, profile_to_nodes) in versioned_nodes { - for (profile_idx, input_node_indixies) in profile_to_nodes { + for (profile_idx, input_node_indexes) in profile_to_nodes { let mut sources = Sources::new(); // all input nodes will be processed - let mut processed_sources = input_node_indixies.iter().copied().collect(); + let mut processed_sources = input_node_indexes.iter().copied().collect(); // we only process input nodes (from sources, tests for example) - for idx in input_node_indixies { + for idx in input_node_indexes { // insert the input node in the sources set and remove it from the available // set let (path, source) =