This commit is contained in:
pgherveou
2025-10-08 06:28:57 +00:00
parent 765569a8b6
commit 1f84ce6f61
34 changed files with 1093 additions and 503 deletions
+30 -9
View File
@@ -22,8 +22,9 @@ pub(crate) async fn get_or_download(
working_directory: &Path,
downloader: &SolcDownloader,
) -> anyhow::Result<(Version, PathBuf)> {
let target_directory =
working_directory.join(SOLC_CACHE_DIRECTORY).join(downloader.version.to_string());
let target_directory = working_directory
.join(SOLC_CACHE_DIRECTORY)
.join(downloader.version.to_string());
let target_file = target_directory.join(downloader.target);
let mut cache = SOLC_CACHER.lock().await;
@@ -33,11 +34,19 @@ pub(crate) async fn get_or_download(
}
create_dir_all(&target_directory).with_context(|| {
format!("Failed to create solc cache directory: {}", target_directory.display())
format!(
"Failed to create solc cache directory: {}",
target_directory.display()
)
})?;
download_to_file(&target_file, downloader)
.await
.with_context(|| format!("Failed to write downloaded solc to {}", target_file.display()))?;
.with_context(|| {
format!(
"Failed to write downloaded solc to {}",
target_file.display()
)
})?;
cache.insert(target_file.clone());
Ok((downloader.version.clone(), target_file))
@@ -61,9 +70,15 @@ async fn download_to_file(path: &Path, downloader: &SolcDownloader) -> anyhow::R
}
let mut file = BufWriter::new(file);
file.write_all(&downloader.download().await.context("Failed to download solc binary bytes")?)
.with_context(|| format!("Failed to write solc binary to {}", path.display()))?;
file.flush().with_context(|| format!("Failed to flush file {}", path.display()))?;
file.write_all(
&downloader
.download()
.await
.context("Failed to download solc binary bytes")?,
)
.with_context(|| format!("Failed to write solc binary to {}", path.display()))?;
file.flush()
.with_context(|| format!("Failed to flush file {}", path.display()))?;
drop(file);
#[cfg(target_os = "macos")]
@@ -76,11 +91,17 @@ async fn download_to_file(path: &Path, downloader: &SolcDownloader) -> anyhow::R
.stdout(std::process::Stdio::null())
.spawn()
.with_context(|| {
format!("Failed to spawn xattr to remove quarantine attribute on {}", path.display())
format!(
"Failed to spawn xattr to remove quarantine attribute on {}",
path.display()
)
})?
.wait()
.with_context(|| {
format!("Failed waiting for xattr operation to complete on {}", path.display())
format!(
"Failed waiting for xattr operation to complete on {}",
path.display()
)
})?;
Ok(())
+41 -8
View File
@@ -130,7 +130,11 @@ impl SolcDownloader {
})?;
let path = build.path.clone();
let expected_digest = build.sha256.strip_prefix("0x").unwrap_or(&build.sha256).to_string();
let expected_digest = build
.sha256
.strip_prefix("0x")
.unwrap_or(&build.sha256)
.to_string();
let url = format!("{}/{}/{}", Self::BASE_URL, self.target, path.display());
let file = reqwest::get(&url)
@@ -155,25 +159,54 @@ mod tests {
#[tokio::test]
async fn try_get_windows() {
let version = List::download(List::WINDOWS_URL).await.unwrap().latest_release;
SolcDownloader::windows(version).await.unwrap().download().await.unwrap();
let version = List::download(List::WINDOWS_URL)
.await
.unwrap()
.latest_release;
SolcDownloader::windows(version)
.await
.unwrap()
.download()
.await
.unwrap();
}
#[tokio::test]
async fn try_get_macosx() {
let version = List::download(List::MACOSX_URL).await.unwrap().latest_release;
SolcDownloader::macosx(version).await.unwrap().download().await.unwrap();
let version = List::download(List::MACOSX_URL)
.await
.unwrap()
.latest_release;
SolcDownloader::macosx(version)
.await
.unwrap()
.download()
.await
.unwrap();
}
#[tokio::test]
async fn try_get_linux() {
let version = List::download(List::LINUX_URL).await.unwrap().latest_release;
SolcDownloader::linux(version).await.unwrap().download().await.unwrap();
let version = List::download(List::LINUX_URL)
.await
.unwrap()
.latest_release;
SolcDownloader::linux(version)
.await
.unwrap()
.download()
.await
.unwrap();
}
#[tokio::test]
async fn try_get_wasm() {
let version = List::download(List::WASM_URL).await.unwrap().latest_release;
SolcDownloader::wasm(version).await.unwrap().download().await.unwrap();
SolcDownloader::wasm(version)
.await
.unwrap()
.download()
.await
.unwrap();
}
}