Use the solc version required in tests rather than one on PATH

This commit is contained in:
James Wilson
2025-08-21 12:23:54 +01:00
parent 85033cfead
commit 491a9a32b2
11 changed files with 263 additions and 307 deletions
+31 -12
View File
@@ -7,6 +7,7 @@ use std::path::{Path, PathBuf};
use cache::get_or_download;
use download::SolcDownloader;
use semver::Version;
use revive_dt_common::types::VersionOrRequirement;
@@ -14,6 +15,25 @@ pub mod cache;
pub mod download;
pub mod list;
/// Return a [`SolcDownloader`] which can be used to download a `solc`
/// binary or return the resolved version it will download.
async fn downloader(
version: impl Into<VersionOrRequirement>,
wasm: bool,
) -> anyhow::Result<SolcDownloader> {
if wasm {
SolcDownloader::wasm(version).await
} else if cfg!(target_os = "linux") {
SolcDownloader::linux(version).await
} else if cfg!(target_os = "macos") {
SolcDownloader::macosx(version).await
} else if cfg!(target_os = "windows") {
SolcDownloader::windows(version).await
} else {
unimplemented!()
}
}
/// Downloads the solc binary for Wasm is `wasm` is set, otherwise for
/// the target platform.
///
@@ -24,17 +44,16 @@ pub async fn download_solc(
version: impl Into<VersionOrRequirement>,
wasm: bool,
) -> anyhow::Result<PathBuf> {
let downloader = if wasm {
SolcDownloader::wasm(version).await
} else if cfg!(target_os = "linux") {
SolcDownloader::linux(version).await
} else if cfg!(target_os = "macos") {
SolcDownloader::macosx(version).await
} else if cfg!(target_os = "windows") {
SolcDownloader::windows(version).await
} else {
unimplemented!()
}?;
let downloader = downloader(version, wasm).await?;
get_or_download(cache_directory, &downloader).await
}
/// Return the version of solc that will be downloaded via [`download_solc`]
/// given the version requirements and wasm flag.
pub async fn solc_version(
version: impl Into<VersionOrRequirement>,
wasm: bool,
) -> anyhow::Result<Version> {
let downloader = downloader(version, wasm).await?;
Ok(downloader.version.clone())
}