Skip to content

Commit

Permalink
keep Solc::version
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Oct 1, 2024
1 parent 8a2d332 commit 4e0a469
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions crates/compilers/src/compilers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ pub trait Compiler: Send + Sync + Clone {

pub(crate) fn cache_version(
path: PathBuf,
args: &Vec<String>,
args: &[String],
f: impl FnOnce(&Path) -> Result<Version>,
) -> Result<Version> {
#[allow(clippy::complexity)]
Expand All @@ -295,7 +295,7 @@ pub(crate) fn cache_version(

let version = f(&path)?;

lock.entry(path).or_default().insert(args.clone(), version.clone());
lock.entry(path).or_default().insert(args.to_vec(), version.clone());

Ok(version)
}
16 changes: 11 additions & 5 deletions crates/compilers/src/compilers/solc/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl Solc {
/// Returns error if `solc` is not found in the system or if the version cannot be retrieved.
pub fn new(path: impl Into<PathBuf>) -> Result<Self> {
let path = path.into();
let version = Self::version(path.clone(), &Vec::new())?;
let version = Self::version(path.clone())?;
Ok(Self::new_with_version(path, version))
}

Expand All @@ -102,9 +102,9 @@ impl Solc {
path: impl Into<PathBuf>,
extra_args: impl IntoIterator<Item: Into<String>>,
) -> Result<Self> {
let args = extra_args.into_iter().map(Into::into).collect();
let args = extra_args.into_iter().map(Into::into).collect::<Vec<_>>();
let path = path.into();
let version = Self::version(path.clone(), &args)?;
let version = Self::version_with_args(path.clone(), &args)?;

let mut solc = Self::new_with_version(path, version);
solc.extra_args = args;
Expand Down Expand Up @@ -446,7 +446,13 @@ impl Solc {

/// Invokes `solc --version` and parses the output as a SemVer [`Version`].
#[instrument(level = "debug", skip_all)]
pub fn version(solc: impl Into<PathBuf>, args: &Vec<String>) -> Result<Version> {
pub fn version(solc: impl Into<PathBuf>) -> Result<Version> {
Self::version_with_args(solc, &Vec::new())
}

/// Invokes `solc --version` and parses the output as a SemVer [`Version`].
#[instrument(level = "debug", skip_all)]
pub fn version_with_args(solc: impl Into<PathBuf>, args: &[String]) -> Result<Version> {
crate::cache_version(solc.into(), args, |solc| {
let mut cmd = Command::new(solc);
cmd.args(args)
Expand Down Expand Up @@ -643,7 +649,7 @@ mod tests {

#[test]
fn solc_version_works() {
Solc::version(solc().solc, &Vec::new()).unwrap();
Solc::version(solc().solc).unwrap();
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion crates/compilers/src/compilers/vyper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl Vyper {
/// Invokes `vyper --version` and parses the output as a SemVer [`Version`].
#[instrument(level = "debug", skip_all)]
pub fn version(vyper: impl Into<PathBuf>) -> Result<Version> {
crate::cache_version(vyper.into(), &Vec::new(), |vyper| {
crate::cache_version(vyper.into(), &[], |vyper| {
let mut cmd = Command::new(vyper);
cmd.arg("--version")
.stdin(Stdio::piped())
Expand Down

0 comments on commit 4e0a469

Please sign in to comment.