From f37d9ff0e61a11a51d0a7ebdb8e53e4f087c994d Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 7 Jan 2022 11:36:56 +0100 Subject: [PATCH] chore(forge): use ethers-solc functions (#395) --- cli/src/cmd/build.rs | 6 +++--- cli/src/forge.rs | 3 ++- cli/src/utils.rs | 42 +----------------------------------------- 3 files changed, 6 insertions(+), 45 deletions(-) diff --git a/cli/src/cmd/build.rs b/cli/src/cmd/build.rs index 130c335a5..7dc8b508c 100644 --- a/cli/src/cmd/build.rs +++ b/cli/src/cmd/build.rs @@ -94,7 +94,7 @@ impl BuildArgs { root.join("contracts") } else { // no contract source directory was provided, determine the source directory - utils::find_contracts_dir(&root) + ProjectPathsConfig::find_source_dir(&root) } } @@ -107,7 +107,7 @@ impl BuildArgs { root.join("artifacts") } else { // no artifacts source directory was provided, determine the artifacts directory - utils::find_artifacts_dir(&root) + ProjectPathsConfig::find_artifacts_dir(&root) } } @@ -119,7 +119,7 @@ impl BuildArgs { vec![root.join("node_modules")] } else { // no libs directories provided - utils::find_libs(&root) + ProjectPathsConfig::find_libs(&root) } } else { let mut libs = self.lib_paths.clone(); diff --git a/cli/src/forge.rs b/cli/src/forge.rs index 3e4022c32..d32b5df70 100644 --- a/cli/src/forge.rs +++ b/cli/src/forge.rs @@ -56,7 +56,8 @@ fn main() -> eyre::Result<()> { let root = root.unwrap_or_else(|| std::env::current_dir().unwrap()); let root = dunce::canonicalize(root)?; - let lib_paths = if lib_paths.is_empty() { vec![root.join("lib")] } else { lib_paths }; + let lib_paths = + if lib_paths.is_empty() { ProjectPathsConfig::find_libs(&root) } else { lib_paths }; let remappings: Vec<_> = lib_paths.iter().flat_map(Remapping::find_many).collect(); remappings.iter().for_each(|x| println!("{}", x)); } diff --git a/cli/src/utils.rs b/cli/src/utils.rs index d6f9cb525..3307fa330 100644 --- a/cli/src/utils.rs +++ b/cli/src/utils.rs @@ -5,11 +5,7 @@ use ethers::{ use evm_adapters::sputnik::Executor; use eyre::{ContextCompat, WrapErr}; -use std::{ - env::VarError, - path::{Path, PathBuf}, - process::Command, -}; +use std::{env::VarError, path::PathBuf, process::Command}; #[cfg(feature = "evmodin-evm")] use evmodin::Revision; @@ -92,42 +88,6 @@ pub fn find_git_root_path() -> eyre::Result { Ok(PathBuf::from(path)) } -/// Determines the source directory to use given the root path to a project's workspace. -/// -/// By default the dapptools style `src` directory takes precedence unless it does not exist but -/// hardhat style `contracts` exists, in which case `/contracts` will be returned. -pub fn find_contracts_dir(root: impl AsRef) -> PathBuf { - find_fave_or_alt_path(root, "src", "contracts") -} - -/// Determines the artifacts directory to use given the root path to a project's workspace. -/// -/// By default the dapptools style `out` directory takes precedence unless it does not exist but -/// hardhat style `artifacts` exists, in which case `/artifacts` will be returned. -pub fn find_artifacts_dir(root: impl AsRef) -> PathBuf { - find_fave_or_alt_path(root, "out", "artifacts") -} - -pub fn find_libs(root: impl AsRef) -> Vec { - vec![find_fave_or_alt_path(root, "lib", "node_modules")] -} - -/// Returns the right subpath in a dir -/// -/// Returns `/` if it exists or `/` does not exist, -/// Returns `/` if it exists and `/` does not exist. -fn find_fave_or_alt_path(root: impl AsRef, fave: &str, alt: &str) -> PathBuf { - let root = root.as_ref(); - let p = root.join(fave); - if !p.exists() { - let alt = root.join(alt); - if alt.exists() { - return alt - } - } - p -} - #[cfg(feature = "sputnik-evm")] pub fn sputnik_cfg(evm: EvmVersion) -> Config { match evm {