This repository has been archived by the owner on Jul 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip(solidity/references): changed to foundry compiler
- Loading branch information
1 parent
95b81cb
commit 42bbb4c
Showing
11 changed files
with
148 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
use thiserror::Error; | ||
|
||
use crate::solc::error::CommandError; | ||
use crate::forge::error::CommandError; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum SolcWrapperError { | ||
#[error("Solc error: {0}")] | ||
Solc(#[from] CommandError), | ||
#[error("JSON parsing error: {0}")] | ||
Json(#[from] serde_json::Error) | ||
Json(#[from] serde_json::Error), | ||
#[error("No build info produced by foundry")] | ||
NoBuildInfo, | ||
#[error("Cannot read build info file")] | ||
ReadBuildInfo(#[from] std::io::Error), | ||
#[error("Cannot read source file")] | ||
ReadSourceFile(std::io::Error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use std::process::Command; | ||
use std::process::Stdio; | ||
use std::path::PathBuf; | ||
|
||
use super::error::{CommandError, CommandType}; | ||
|
||
pub struct ForgeCommand { | ||
args: Vec<String>, | ||
bin_path : PathBuf, | ||
current_dir: String | ||
} | ||
|
||
impl Default for ForgeCommand { | ||
fn default() -> Self { | ||
ForgeCommand::new("forge") | ||
} | ||
} | ||
|
||
impl ForgeCommand { | ||
|
||
pub fn new(path: impl Into<PathBuf>) -> Self { | ||
ForgeCommand { | ||
args: Vec::new(), | ||
bin_path: path.into(), | ||
current_dir: String::from(".") | ||
} | ||
} | ||
|
||
pub fn current_dir(mut self, current_dir: String) -> Self { | ||
self.current_dir = current_dir; | ||
self | ||
} | ||
|
||
pub fn arg<T: Into<String>>(mut self, arg: T) -> Self { | ||
self.args.push(arg.into()); | ||
self | ||
} | ||
|
||
pub fn args<I, S>(mut self, args: I) -> Self | ||
where | ||
I: IntoIterator<Item = S>, | ||
S: Into<String>, | ||
{ | ||
for arg in args { | ||
self = self.arg(arg); | ||
} | ||
self | ||
} | ||
|
||
pub fn execute(&self) -> Result<(), CommandError> { | ||
Command::new(&self.bin_path) | ||
.current_dir(&self.current_dir) | ||
.args(&self.args) | ||
.stdout(Stdio::piped()) | ||
.output() | ||
.map_err(|e| { | ||
eprintln!("Forge Command Error: {}", e.to_string()); | ||
CommandError { error: e.to_string(), command_type: CommandType::ParseFile } | ||
})?; | ||
Ok(()) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use std::io; | ||
use std::path::PathBuf; | ||
use std::fs::{read_dir, DirEntry}; | ||
use crate::SolcJsonFile; | ||
use crate::error::SolcWrapperError; | ||
use serde_json; | ||
|
||
pub fn get_files_from_solc_output(base_path: &str) -> Result<Vec<SolcJsonFile>, SolcWrapperError> { | ||
let mut files = Vec::new(); | ||
|
||
let output = std::fs::read_to_string(get_last_build_info(base_path)?)?; | ||
let json: serde_json::Value = serde_json::from_str(&output)?; | ||
for (file, json) in json["output"]["sources"].as_object().ok_or(SolcWrapperError::NoBuildInfo)? { | ||
files.push(SolcJsonFile { | ||
json: json["ast"].clone(), | ||
file: file.clone() | ||
}); | ||
}; | ||
|
||
Ok(files) | ||
} | ||
|
||
fn get_last_build_info(base_path: &str) -> Result<PathBuf, SolcWrapperError> { | ||
let out = read_dir(base_path.to_string() + "/out/build-info")?; | ||
|
||
let mut entries: Vec<DirEntry> = out.flatten().collect(); | ||
entries.sort_by(|a, b| { | ||
sort_latest(a, b).unwrap_or(std::cmp::Ordering::Equal) | ||
}); | ||
let last_build_info = entries.first().ok_or(SolcWrapperError::NoBuildInfo)?; | ||
Ok(last_build_info.path()) | ||
} | ||
|
||
fn sort_latest(a: &DirEntry, b: &DirEntry) -> Result<std::cmp::Ordering, io::Error> { | ||
if let Ok(met_a) = a.metadata() { | ||
if let Ok(met_b) = b.metadata() { | ||
if met_a.created()? > met_b.created()? { | ||
return Ok(std::cmp::Ordering::Greater); | ||
} else { | ||
return Ok(std::cmp::Ordering::Less); | ||
} | ||
} | ||
} | ||
Ok(std::cmp::Ordering::Equal) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters