mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-07-04 17:07:22 +00:00
Make codebase async
This commit is contained in:
@@ -33,7 +33,7 @@ pub trait SolidityCompiler {
|
||||
&self,
|
||||
input: CompilerInput,
|
||||
additional_options: Self::Options,
|
||||
) -> anyhow::Result<CompilerOutput>;
|
||||
) -> impl Future<Output = anyhow::Result<CompilerOutput>>;
|
||||
|
||||
fn new(solc_executable: PathBuf) -> Self;
|
||||
|
||||
@@ -147,8 +147,13 @@ where
|
||||
self
|
||||
}
|
||||
|
||||
pub fn try_build(self, compiler_path: impl AsRef<Path>) -> anyhow::Result<CompilerOutput> {
|
||||
T::new(compiler_path.as_ref().to_path_buf()).build(self.input, self.additional_options)
|
||||
pub async fn try_build(
|
||||
self,
|
||||
compiler_path: impl AsRef<Path>,
|
||||
) -> anyhow::Result<CompilerOutput> {
|
||||
T::new(compiler_path.as_ref().to_path_buf())
|
||||
.build(self.input, self.additional_options)
|
||||
.await
|
||||
}
|
||||
|
||||
pub fn input(&self) -> CompilerInput {
|
||||
|
||||
@@ -6,7 +6,6 @@ use std::{
|
||||
process::{Command, Stdio},
|
||||
};
|
||||
|
||||
use alloy::json_abi::JsonAbi;
|
||||
use revive_dt_common::types::VersionOrRequirement;
|
||||
use revive_dt_config::Arguments;
|
||||
use revive_solc_json_interface::{
|
||||
@@ -17,8 +16,10 @@ use revive_solc_json_interface::{
|
||||
|
||||
use crate::{CompilerInput, CompilerOutput, SolidityCompiler};
|
||||
|
||||
use alloy::json_abi::JsonAbi;
|
||||
use anyhow::Context;
|
||||
use semver::Version;
|
||||
use tokio::{io::AsyncWriteExt, process::Command as AsyncCommand};
|
||||
|
||||
// TODO: I believe that we need to also pass the solc compiler to resolc so that resolc uses the
|
||||
// specified solc compiler. I believe that currently we completely ignore the specified solc binary
|
||||
@@ -35,7 +36,7 @@ impl SolidityCompiler for Resolc {
|
||||
type Options = Vec<String>;
|
||||
|
||||
#[tracing::instrument(level = "debug", ret)]
|
||||
fn build(
|
||||
async fn build(
|
||||
&self,
|
||||
CompilerInput {
|
||||
enable_optimization,
|
||||
@@ -87,7 +88,7 @@ impl SolidityCompiler for Resolc {
|
||||
},
|
||||
};
|
||||
|
||||
let mut command = Command::new(&self.resolc_path);
|
||||
let mut command = AsyncCommand::new(&self.resolc_path);
|
||||
command
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
@@ -109,9 +110,10 @@ impl SolidityCompiler for Resolc {
|
||||
let mut child = command.spawn()?;
|
||||
|
||||
let stdin_pipe = child.stdin.as_mut().expect("stdin must be piped");
|
||||
serde_json::to_writer(stdin_pipe, &input)?;
|
||||
let serialized_input = serde_json::to_vec(&input)?;
|
||||
stdin_pipe.write_all(&serialized_input).await?;
|
||||
|
||||
let output = child.wait_with_output()?;
|
||||
let output = child.wait_with_output().await?;
|
||||
let stdout = output.stdout;
|
||||
let stderr = output.stderr;
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ use foundry_compilers_artifacts::{
|
||||
solc::*,
|
||||
};
|
||||
use semver::Version;
|
||||
use tokio::{io::AsyncWriteExt, process::Command as AsyncCommand};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Solc {
|
||||
@@ -31,7 +32,7 @@ impl SolidityCompiler for Solc {
|
||||
type Options = ();
|
||||
|
||||
#[tracing::instrument(level = "debug", ret)]
|
||||
fn build(
|
||||
async fn build(
|
||||
&self,
|
||||
CompilerInput {
|
||||
enable_optimization,
|
||||
@@ -90,7 +91,7 @@ impl SolidityCompiler for Solc {
|
||||
},
|
||||
};
|
||||
|
||||
let mut command = Command::new(&self.solc_path);
|
||||
let mut command = AsyncCommand::new(&self.solc_path);
|
||||
command
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
@@ -112,8 +113,9 @@ impl SolidityCompiler for Solc {
|
||||
let mut child = command.spawn()?;
|
||||
|
||||
let stdin = child.stdin.as_mut().expect("should be piped");
|
||||
serde_json::to_writer(stdin, &input)?;
|
||||
let output = child.wait_with_output()?;
|
||||
let serialized_input = serde_json::to_vec(&input)?;
|
||||
stdin.write_all(&serialized_input).await?;
|
||||
let output = child.wait_with_output().await?;
|
||||
|
||||
if !output.status.success() {
|
||||
let json_in = serde_json::to_string_pretty(&input)?;
|
||||
|
||||
Reference in New Issue
Block a user