Skip to content

Commit

Permalink
fix(solc): only write cache file if build was successful (gakonst#1177)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Apr 27, 2022
1 parent a866cd5 commit 86908bc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
8 changes: 6 additions & 2 deletions ethers-solc/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T::Artifact>,
write_to_disk: bool,
) -> Result<Artifacts<T::Artifact>> {
match self {
ArtifactsCache::Ephemeral(_, _) => Ok(Default::default()),
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion ethers-solc/src/compile/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ impl<'a, T: ArtifactOutput> ArtifactsState<'a, T> {
fn write_cache(self) -> Result<ProjectCompileOutput<T>> {
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,
Expand Down
4 changes: 3 additions & 1 deletion ethers-solc/src/project_util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ pub struct TempProject<T: ArtifactOutput = ConfigurableArtifacts> {
impl<T: ArtifactOutput> TempProject<T> {
/// Makes sure all resources are created
pub fn create_new(root: TempDir, inner: Project<T>) -> std::result::Result<Self, SolcIoError> {
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)
}

Expand Down

0 comments on commit 86908bc

Please sign in to comment.