From 86908bc5334b7d2008e2143b197c7bd0697d8566 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 27 Apr 2022 14:29:09 +0200 Subject: [PATCH] fix(solc): only write cache file if build was successful (#1177) --- ethers-solc/src/cache.rs | 8 ++++++-- ethers-solc/src/compile/project.rs | 3 ++- ethers-solc/src/project_util/mod.rs | 4 +++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ethers-solc/src/cache.rs b/ethers-solc/src/cache.rs index 7dbfa5ec..59dcb858 100644 --- a/ethers-solc/src/cache.rs +++ b/ethers-solc/src/cache.rs @@ -854,9 +854,10 @@ impl<'a, T: ArtifactOutput> ArtifactsCache<'a, T> { /// compiled and written to disk `written_artifacts`. /// /// Returns all the _cached_ artifacts. - pub fn write_cache( + pub fn consume( self, written_artifacts: &Artifacts, + write_to_disk: bool, ) -> Result> { match self { ArtifactsCache::Ephemeral(_, _) => Ok(Default::default()), @@ -913,8 +914,11 @@ impl<'a, T: ArtifactOutput> ArtifactsCache<'a, T> { .extend(dirty_source_files.into_iter().map(|(file, (entry, _))| (file, entry))); cache.strip_artifact_files_prefixes(project.artifacts_path()); + // write to disk - cache.write(project.cache_path())?; + if write_to_disk { + cache.write(project.cache_path())?; + } Ok(cached_artifacts) } diff --git a/ethers-solc/src/compile/project.rs b/ethers-solc/src/compile/project.rs index 545cfd2e..e7a82d97 100644 --- a/ethers-solc/src/compile/project.rs +++ b/ethers-solc/src/compile/project.rs @@ -304,7 +304,8 @@ impl<'a, T: ArtifactOutput> ArtifactsState<'a, T> { fn write_cache(self) -> Result> { let ArtifactsState { output, cache, compiled_artifacts } = self; let ignored_error_codes = cache.project().ignored_error_codes.clone(); - let cached_artifacts = cache.write_cache(&compiled_artifacts)?; + let skip_write_to_disk = cache.project().no_artifacts || output.has_error(); + let cached_artifacts = cache.consume(&compiled_artifacts, !skip_write_to_disk)?; Ok(ProjectCompileOutput { compiler_output: output, compiled_artifacts, diff --git a/ethers-solc/src/project_util/mod.rs b/ethers-solc/src/project_util/mod.rs index afa3298f..dcb5e76b 100644 --- a/ethers-solc/src/project_util/mod.rs +++ b/ethers-solc/src/project_util/mod.rs @@ -34,8 +34,10 @@ pub struct TempProject { impl TempProject { /// Makes sure all resources are created pub fn create_new(root: TempDir, inner: Project) -> std::result::Result { - let project = Self { _root: root, inner }; + let mut project = Self { _root: root, inner }; project.paths().create_all()?; + // ignore license warnings + project.inner.ignored_error_codes.push(1878); Ok(project) }