From 19a2ecd58d02221ef31b0c8eedc6212e77813769 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 13 Apr 2022 21:59:43 +0200 Subject: [PATCH] fix(solc): compute content hashes first (#1142) * chore: add tracing for missing content hash * fix: compute content hashes first --- ethers-solc/src/cache.rs | 12 ++++++++++-- ethers-solc/src/compile/project.rs | 5 +++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ethers-solc/src/cache.rs b/ethers-solc/src/cache.rs index f87c4bd4..7dbfa5ec 100644 --- a/ethers-solc/src/cache.rs +++ b/ethers-solc/src/cache.rs @@ -630,8 +630,6 @@ impl<'a, T: ArtifactOutput> ArtifactsCacheInner<'a, T> { /// so that their [OutputSelection] can be optimized in the [CompilerOutput] and their (empty) /// artifacts ignored. fn filter(&mut self, sources: Sources, version: &Version) -> FilteredSources { - self.fill_hashes(&sources); - // all files that are not dirty themselves, but are pulled from a dirty file let mut imports_of_dirty = HashSet::new(); @@ -728,6 +726,8 @@ impl<'a, T: ArtifactOutput> ArtifactsCacheInner<'a, T> { return false } tracing::trace!("Missing cache entry for {}", file.display()); + } else { + tracing::trace!("Missing content hash for {}", file.display()); } true } @@ -833,6 +833,14 @@ impl<'a, T: ArtifactOutput> ArtifactsCache<'a, T> { } } + /// Adds the file's hashes to the set if not set yet + pub fn fill_content_hashes(&mut self, sources: &Sources) { + match self { + ArtifactsCache::Ephemeral(_, _) => {} + ArtifactsCache::Cached(cache) => cache.fill_hashes(sources), + } + } + /// Filters out those sources that don't need to be compiled pub fn filter(&mut self, sources: Sources, version: &Version) -> FilteredSources { match self { diff --git a/ethers-solc/src/compile/project.rs b/ethers-solc/src/compile/project.rs index c831afd3..49b5eb37 100644 --- a/ethers-solc/src/compile/project.rs +++ b/ethers-solc/src/compile/project.rs @@ -331,6 +331,11 @@ impl CompilerSources { sources: VersionedSources, cache: &mut ArtifactsCache, ) -> VersionedFilteredSources { + // fill all content hashes first so they're available for all source sets + sources.iter().for_each(|(_, (_, sources))| { + cache.fill_content_hashes(sources); + }); + sources .into_iter() .map(|(solc, (version, sources))| {