Skip to content

Commit

Permalink
refactor: renaming to era-compiler-downloader and era-compiler-common (
Browse files Browse the repository at this point in the history
  • Loading branch information
antonbaliasnikov authored Aug 29, 2024
1 parent 9deb616 commit be47c80
Show file tree
Hide file tree
Showing 21 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[workspace]

members = [
"common",
"solc-downloader",
"era-compiler-common",
"era-compiler-downloader",
]
resolver = "2"

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "era-solc-downloader"
name = "era-compiler-downloader"
version = "0.1.0"
authors.workspace = true
license.workspace = true
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub enum Protocol {
/// Download via HTTPS.
#[serde(rename = "https")]
HTTPS,
/// Use the solc-bin JSON list.
#[serde(rename = "solc-bin-list")]
SolcBinList,
/// Use the compiler-bin JSON list.
#[serde(rename = "compiler-bin-list")]
CompilerBinList,
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//!
//! The Solidity compiler JSON list metadata.
//! The compiler JSON list metadata.
//!

use std::collections::BTreeMap;
Expand All @@ -10,26 +10,26 @@ use colored::Colorize;
use serde::Deserialize;

///
/// The Solidity compiler JSON list metadata.
/// The compiler JSON list metadata.
///
#[derive(Debug, Deserialize)]
pub struct SolcList {
pub struct CompilerList {
/// The collection of compiler releases.
pub releases: BTreeMap<String, String>,
}

impl TryFrom<&Path> for SolcList {
impl TryFrom<&Path> for CompilerList {
type Error = anyhow::Error;

fn try_from(path: &Path) -> Result<Self, Self::Error> {
let url =
reqwest::Url::from_str(path.to_str().expect("Always valid")).expect("Always valid");
println!(
" {} solc-bin JSON `{}`",
" {} compiler bin JSON `{}`",
"Downloading".bright_green().bold(),
url
);
let list: SolcList = reqwest::blocking::get(url)?.json()?;
let list: CompilerList = reqwest::blocking::get(url)?.json()?;
Ok(list)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//!

pub mod binary;
pub(crate) mod solc_list;
pub(crate) mod compiler_list;

use std::collections::BTreeMap;
use std::collections::HashMap;
Expand Down Expand Up @@ -41,18 +41,18 @@ impl Config {
} else if cfg!(target_os = "windows") {
"windows-amd64"
} else {
anyhow::bail!("This platform is not supported in `solc`!");
anyhow::bail!("This platform is not supported!");
}
} else if cfg!(target_arch = "aarch64") {
if cfg!(target_os = "linux") {
"linux-arm64"
} else if cfg!(target_os = "macos") {
"macos-arm64"
} else {
anyhow::bail!("This platform is not supported in `solc`!");
anyhow::bail!("This platform is not supported!");
}
} else {
anyhow::bail!("This platform is not supported in `solc`!");
anyhow::bail!("This platform is not supported!");
};

platforms
Expand Down
26 changes: 13 additions & 13 deletions solc-downloader/src/lib.rs → era-compiler-downloader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::str::FromStr;
use colored::Colorize;

use self::config::binary::protocol::Protocol;
use self::config::solc_list::SolcList;
use self::config::compiler_list::CompilerList;
use self::config::Config;

///
Expand All @@ -20,8 +20,8 @@ use self::config::Config;
pub struct Downloader {
/// The `reqwest` HTTP client.
http_client: reqwest::blocking::Client,
/// The solc-bin JSON list metadata.
solc_list: Option<SolcList>,
/// The compiler-bin JSON list metadata.
compiler_list: Option<CompilerList>,
}

impl Downloader {
Expand All @@ -31,7 +31,7 @@ impl Downloader {
pub fn new(http_client: reqwest::blocking::Client) -> Self {
Self {
http_client,
solc_list: None,
compiler_list: None,
}
}

Expand Down Expand Up @@ -113,29 +113,29 @@ impl Downloader {
);
self.http_client.get(source_url).send()?.bytes()?
}
Protocol::SolcBinList => {
Protocol::CompilerBinList => {
if destination_path.exists() {
continue;
}

let solc_list_path = PathBuf::from(source_path.as_str());
let solc_list = self.solc_list.get_or_insert_with(|| {
SolcList::try_from(solc_list_path.as_path())
.expect("solc-bin JSON list downloading error")
let compiler_list_path = PathBuf::from(source_path.as_str());
let compiler_list = self.compiler_list.get_or_insert_with(|| {
CompilerList::try_from(compiler_list_path.as_path())
.expect("compiler-bin JSON list downloading error")
});
if solc_list.releases.is_empty() {
if compiler_list.releases.is_empty() {
return Ok(config);
}

let source_binary_name =
match solc_list.releases.get(version.to_string().as_str()) {
match compiler_list.releases.get(version.to_string().as_str()) {
Some(source_binary_name) => source_binary_name,
None => anyhow::bail!(
"Binary for version v{} not found in the solc JSON list",
"Binary for version v{} not found in the compiler JSON list",
version
),
};
let mut source_path = solc_list_path;
let mut source_path = compiler_list_path;
source_path.pop();
source_path.push(source_binary_name);

Expand Down

0 comments on commit be47c80

Please sign in to comment.