From 7b87c44a54e121b6e49ecbac04f91b51e66f7101 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 7 Oct 2022 19:03:38 +0200 Subject: [PATCH] chore(solc): create artifacts folder on output (#1772) --- ethers-solc/src/artifact_output/mod.rs | 7 ++++++- ethers-solc/src/utils.rs | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ethers-solc/src/artifact_output/mod.rs b/ethers-solc/src/artifact_output/mod.rs index a841b39f..5b79e7c3 100644 --- a/ethers-solc/src/artifact_output/mod.rs +++ b/ethers-solc/src/artifact_output/mod.rs @@ -10,7 +10,7 @@ use crate::{ error::Result, sourcemap::{SourceMap, SyntaxError}, sources::VersionedSourceFile, - utils, HardhatArtifact, ProjectPathsConfig, SolFilesCache, SolcError, + utils, HardhatArtifact, ProjectPathsConfig, SolFilesCache, SolcError, SolcIoError, }; use ethers_core::{abi::Abi, types::Bytes}; use semver::Version; @@ -577,6 +577,11 @@ pub trait ArtifactOutput { ctx: OutputContext, ) -> Result> { let mut artifacts = self.output_to_artifacts(contracts, sources, ctx); + fs::create_dir_all(&layout.artifacts).map_err(|err| { + error!(dir=?layout.artifacts, "Failed to create artifacts folder"); + SolcIoError::new(err, &layout.artifacts) + })?; + artifacts.join_all(&layout.artifacts); artifacts.write_all()?; diff --git a/ethers-solc/src/utils.rs b/ethers-solc/src/utils.rs index deca64de..0e23b010 100644 --- a/ethers-solc/src/utils.rs +++ b/ethers-solc/src/utils.rs @@ -468,6 +468,17 @@ mod tests { assert!(path.parent().unwrap().is_dir()); } + #[test] + fn can_create_parent_dirs_versioned() { + let tmp_dir = tempdir("out").unwrap(); + let path = tmp_dir.path().join("IVersioned.sol/IVersioned.0.8.16.json"); + create_parent_dir_all(&path).unwrap(); + assert!(path.parent().unwrap().is_dir()); + let path = tmp_dir.path().join("IVersioned.sol/IVersioned.json"); + create_parent_dir_all(&path).unwrap(); + assert!(path.parent().unwrap().is_dir()); + } + #[test] fn can_determine_local_paths() { assert!(is_local_source_name(&[""], "./local/contract.sol"));