chore(solc): create artifacts folder on output (#1772)

This commit is contained in:
Matthias Seitz 2022-10-07 19:03:38 +02:00 committed by GitHub
parent 7439dea0bb
commit 7b87c44a54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -10,7 +10,7 @@ use crate::{
error::Result, error::Result,
sourcemap::{SourceMap, SyntaxError}, sourcemap::{SourceMap, SyntaxError},
sources::VersionedSourceFile, sources::VersionedSourceFile,
utils, HardhatArtifact, ProjectPathsConfig, SolFilesCache, SolcError, utils, HardhatArtifact, ProjectPathsConfig, SolFilesCache, SolcError, SolcIoError,
}; };
use ethers_core::{abi::Abi, types::Bytes}; use ethers_core::{abi::Abi, types::Bytes};
use semver::Version; use semver::Version;
@ -577,6 +577,11 @@ pub trait ArtifactOutput {
ctx: OutputContext, ctx: OutputContext,
) -> Result<Artifacts<Self::Artifact>> { ) -> Result<Artifacts<Self::Artifact>> {
let mut artifacts = self.output_to_artifacts(contracts, sources, ctx); 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.join_all(&layout.artifacts);
artifacts.write_all()?; artifacts.write_all()?;

View File

@ -468,6 +468,17 @@ mod tests {
assert!(path.parent().unwrap().is_dir()); 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] #[test]
fn can_determine_local_paths() { fn can_determine_local_paths() {
assert!(is_local_source_name(&[""], "./local/contract.sol")); assert!(is_local_source_name(&[""], "./local/contract.sol"));