Skip to content

Commit

Permalink
chore(forge): use ethers-solc functions (gakonst#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Jan 7, 2022
1 parent de0323b commit f37d9ff
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 45 deletions.
6 changes: 3 additions & 3 deletions cli/src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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)
}
}

Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion cli/src/forge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
42 changes: 1 addition & 41 deletions cli/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -92,42 +88,6 @@ pub fn find_git_root_path() -> eyre::Result<PathBuf> {
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 `<root>/contracts` will be returned.
pub fn find_contracts_dir(root: impl AsRef<Path>) -> 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 `<root>/artifacts` will be returned.
pub fn find_artifacts_dir(root: impl AsRef<Path>) -> PathBuf {
find_fave_or_alt_path(root, "out", "artifacts")
}

pub fn find_libs(root: impl AsRef<Path>) -> Vec<PathBuf> {
vec![find_fave_or_alt_path(root, "lib", "node_modules")]
}

/// Returns the right subpath in a dir
///
/// Returns `<root>/<fave>` if it exists or `<root>/<alt>` does not exist,
/// Returns `<root>/<alt>` if it exists and `<root>/<fave>` does not exist.
fn find_fave_or_alt_path(root: impl AsRef<Path>, 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 {
Expand Down

0 comments on commit f37d9ff

Please sign in to comment.