Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
chore: support latest svm (#2523)
Browse files Browse the repository at this point in the history
* fix: use SVM_DATA_DIR instead of SVM_HOME

* chore: update test

* chore: use correct folder if exists

* fix: change svm home folder detection

* clippy

* actually check if path exists or not
  • Loading branch information
Evalir authored Jul 24, 2023
1 parent 030bf43 commit d587981
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions ethers-solc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ regex.workspace = true
thiserror.workspace = true
hex.workspace = true
yansi = "0.5.1"
dirs = "5.0"
glob = "0.3.1"
tracing.workspace = true
num_cpus = "1.15.0"
Expand Down
23 changes: 17 additions & 6 deletions ethers-solc/src/compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,21 @@ impl Solc {

/// Returns the directory in which [svm](https://github.com/roynalnaruto/svm-rs) stores all versions
///
/// This will be `~/.svm` on unix
/// This will be:
/// `~/.svm` on unix, if it exists
/// - $XDG_DATA_HOME (~/.local/share/svm) if the svm folder does not exist.
#[cfg(not(target_arch = "wasm32"))]
pub fn svm_home() -> Option<PathBuf> {
home::home_dir().map(|dir| dir.join(".svm"))
match home::home_dir().map(|dir| dir.join(".svm")) {
Some(dir) => {
if !dir.exists() {
dirs::data_dir().map(|dir| dir.join("svm"))
} else {
Some(dir)
}
}
None => dirs::data_dir().map(|dir| dir.join("svm")),
}
}

/// Returns the `semver::Version` [svm](https://github.com/roynalnaruto/svm-rs)'s `.global_version` is currently set to.
Expand Down Expand Up @@ -353,7 +364,7 @@ impl Solc {
let _lock = take_solc_installer_lock();

// load the local / remote versions
let versions = utils::installed_versions(svm::SVM_HOME.as_path()).unwrap_or_default();
let versions = utils::installed_versions(svm::SVM_DATA_DIR.as_path()).unwrap_or_default();

let local_versions = Self::find_matching_installation(&versions, sol_version);
let remote_versions = Self::find_matching_installation(&RELEASES.1, sol_version);
Expand Down Expand Up @@ -845,7 +856,7 @@ mod tests {
(">=0.4.0 <0.5.0", "0.4.26"),
// latest - this has to be updated every time a new version is released.
// Requires the SVM version list to be updated as well.
(">=0.5.0", "0.8.20"),
(">=0.5.0", "0.8.21"),
] {
let source = source(pragma);
let res = Solc::detect_version(&source).unwrap();
Expand All @@ -861,14 +872,14 @@ mod tests {
let _lock = LOCK.lock();
let ver = "0.8.6";
let version = Version::from_str(ver).unwrap();
if utils::installed_versions(svm::SVM_HOME.as_path())
if utils::installed_versions(svm::SVM_DATA_DIR.as_path())
.map(|versions| !versions.contains(&version))
.unwrap_or_default()
{
Solc::blocking_install(&version).unwrap();
}
let res = Solc::find_svm_installed_version(version.to_string()).unwrap().unwrap();
let expected = svm::SVM_HOME.join(ver).join(format!("solc-{ver}"));
let expected = svm::SVM_DATA_DIR.join(ver).join(format!("solc-{ver}"));
assert_eq!(res.solc, expected);
}

Expand Down

0 comments on commit d587981

Please sign in to comment.