refactor(solc): bump svm-rs and use returned install path (#1034)

* chore(deps): bump svm-rs

* refactor: use solc install path directly

* style: use if elese over option
This commit is contained in:
Matthias Seitz 2022-03-15 10:16:22 +01:00 committed by GitHub
parent f6d123241e
commit 24236997a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 15 deletions

2
Cargo.lock generated
View File

@ -3576,7 +3576,7 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
[[package]] [[package]]
name = "svm-rs" name = "svm-rs"
version = "0.2.9" version = "0.2.9"
source = "git+https://github.com/roynalnaruto/svm-rs#ae79a29f5bde08f1991f981456253fa5b6859047" source = "git+https://github.com/roynalnaruto/svm-rs#37d0095eeac73546c507b706c51e8f901541a7c1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"cfg-if 1.0.0", "cfg-if 1.0.0",

View File

@ -348,34 +348,35 @@ impl Solc {
Ok(version) Ok(version)
} }
/// Installs the provided version of Solc in the machine under the svm dir /// Installs the provided version of Solc in the machine under the svm dir and returns the
/// [Solc] instance pointing to the installation.
///
/// # Example /// # Example
/// ```no_run /// ```no_run
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> { /// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
/// use ethers_solc::{Solc, ISTANBUL_SOLC}; /// use ethers_solc::{Solc, ISTANBUL_SOLC};
/// Solc::install(&ISTANBUL_SOLC).await.unwrap(); /// let solc = Solc::install(&ISTANBUL_SOLC).await.unwrap();
/// let solc = Solc::find_svm_installed_version(&ISTANBUL_SOLC.to_string());
/// # Ok(()) /// # Ok(())
/// # } /// # }
/// ``` /// ```
#[cfg(feature = "svm")] #[cfg(feature = "svm")]
pub async fn install(version: &Version) -> std::result::Result<(), svm::SolcVmError> { pub async fn install(version: &Version) -> std::result::Result<Self, svm::SolcVmError> {
tracing::trace!("installing solc version \"{}\"", version); tracing::trace!("installing solc version \"{}\"", version);
crate::report::solc_installation_start(version); crate::report::solc_installation_start(version);
let result = svm::install(version).await; let result = svm::install(version).await;
crate::report::solc_installation_success(version); crate::report::solc_installation_success(version);
result result.map(Solc::new)
} }
/// Blocking version of `Self::install` /// Blocking version of `Self::install`
#[cfg(all(feature = "svm", feature = "async"))] #[cfg(all(feature = "svm", feature = "async"))]
pub fn blocking_install(version: &Version) -> std::result::Result<(), svm::SolcVmError> { pub fn blocking_install(version: &Version) -> std::result::Result<Self, svm::SolcVmError> {
tracing::trace!("blocking installing solc version \"{}\"", version); tracing::trace!("blocking installing solc version \"{}\"", version);
crate::report::solc_installation_start(version); crate::report::solc_installation_start(version);
match svm::blocking_install(version) { match svm::blocking_install(version) {
Ok(_) => { Ok(path) => {
crate::report::solc_installation_success(version); crate::report::solc_installation_success(version);
Ok(()) Ok(Solc::new(path))
} }
Err(err) => { Err(err) => {
crate::report::solc_installation_error(version, &err.to_string()); crate::report::solc_installation_error(version, &err.to_string());

View File

@ -627,19 +627,22 @@ impl VersionedSources {
let mut sources_by_version = std::collections::BTreeMap::new(); let mut sources_by_version = std::collections::BTreeMap::new();
for (version, sources) in self.inner { for (version, sources) in self.inner {
if !version.is_installed() { let solc = if !version.is_installed() {
if self.offline { if self.offline {
return Err(SolcError::msg(format!( return Err(SolcError::msg(format!(
"missing solc \"{}\" installation in offline mode", "missing solc \"{}\" installation in offline mode",
version version
))) )))
} else { } else {
Solc::blocking_install(version.as_ref())?; // install missing solc
Solc::blocking_install(version.as_ref())?
} }
} } else {
let solc = Solc::find_svm_installed_version(version.to_string())?.ok_or_else(|| { // find installed svm
SolcError::msg(format!("solc \"{}\" should have been installed", version)) Solc::find_svm_installed_version(version.to_string())?.ok_or_else(|| {
})?; SolcError::msg(format!("solc \"{}\" should have been installed", version))
})?
};
if self.offline { if self.offline {
tracing::trace!( tracing::trace!(