Add reporting back to the compilers

This commit is contained in:
Omar Abdulla
2025-08-28 09:42:54 +03:00
parent b69aab903e
commit 90214f1afe
5 changed files with 97 additions and 8 deletions
+3
View File
@@ -43,6 +43,9 @@ pub trait SolidityCompiler {
/// Returns the version of the compiler. /// Returns the version of the compiler.
fn version(&self) -> &Version; fn version(&self) -> &Version;
/// Returns the path of the compiler executable.
fn path(&self) -> &Path;
/// The low-level compiler interface. /// The low-level compiler interface.
fn build(&self, input: CompilerInput) -> impl Future<Output = Result<CompilerOutput>>; fn build(&self, input: CompilerInput) -> impl Future<Output = Result<CompilerOutput>>;
+4
View File
@@ -67,6 +67,10 @@ impl SolidityCompiler for Resolc {
self.solc.version() self.solc.version()
} }
fn path(&self) -> &std::path::Path {
&self.resolc_path
}
#[tracing::instrument(level = "debug", ret)] #[tracing::instrument(level = "debug", ret)]
async fn build( async fn build(
&self, &self,
+4
View File
@@ -68,6 +68,10 @@ impl SolidityCompiler for Solc {
&self.solc_version &self.solc_version
} }
fn path(&self) -> &std::path::Path {
&self.solc_path
}
#[tracing::instrument(level = "debug", ret)] #[tracing::instrument(level = "debug", ret)]
async fn build( async fn build(
&self, &self,
+80 -6
View File
@@ -16,6 +16,7 @@ use revive_dt_format::metadata::{ContractIdent, ContractInstance, Metadata};
use alloy::{hex::ToHexExt, json_abi::JsonAbi, primitives::Address}; use alloy::{hex::ToHexExt, json_abi::JsonAbi, primitives::Address};
use anyhow::{Context as _, Error, Result}; use anyhow::{Context as _, Error, Result};
use revive_dt_report::ExecutionSpecificReporter;
use semver::Version; use semver::Version;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tokio::sync::{Mutex, RwLock}; use tokio::sync::{Mutex, RwLock};
@@ -67,6 +68,7 @@ impl<'a> CachedCompiler<'a> {
mode: Cow<'a, Mode>, mode: Cow<'a, Mode>,
deployed_libraries: Option<&HashMap<ContractInstance, (ContractIdent, Address, JsonAbi)>>, deployed_libraries: Option<&HashMap<ContractInstance, (ContractIdent, Address, JsonAbi)>>,
compiler: &P::Compiler, compiler: &P::Compiler,
reporter: &ExecutionSpecificReporter,
) -> Result<CompilerOutput> { ) -> Result<CompilerOutput> {
let cache_key = CacheKey { let cache_key = CacheKey {
platform_key: P::config_id(), platform_key: P::config_id(),
@@ -87,6 +89,7 @@ impl<'a> CachedCompiler<'a> {
&mode, &mode,
deployed_libraries, deployed_libraries,
compiler, compiler,
reporter,
) )
.map(|compilation_result| compilation_result.map(CacheValue::new)) .map(|compilation_result| compilation_result.map(CacheValue::new))
.await .await
@@ -138,7 +141,30 @@ impl<'a> CachedCompiler<'a> {
let _guard = mutex.lock().await; let _guard = mutex.lock().await;
match self.artifacts_cache.get(&cache_key).await { match self.artifacts_cache.get(&cache_key).await {
Some(cache_value) => cache_value.compiler_output, Some(cache_value) => {
if deployed_libraries.is_some() {
reporter
.report_post_link_contracts_compilation_succeeded_event(
compiler.version().clone(),
compiler.path(),
true,
None,
cache_value.compiler_output.clone(),
)
.expect("Can't happen");
} else {
reporter
.report_pre_link_contracts_compilation_succeeded_event(
compiler.version().clone(),
compiler.path(),
true,
None,
cache_value.compiler_output.clone(),
)
.expect("Can't happen");
}
cache_value.compiler_output
}
None => { None => {
compilation_callback() compilation_callback()
.await .await
@@ -153,20 +179,20 @@ impl<'a> CachedCompiler<'a> {
} }
} }
#[allow(clippy::too_many_arguments)]
async fn compile_contracts<P: Platform>( async fn compile_contracts<P: Platform>(
metadata_directory: impl AsRef<Path>, metadata_directory: impl AsRef<Path>,
mut files_to_compile: impl Iterator<Item = PathBuf>, mut files_to_compile: impl Iterator<Item = PathBuf>,
mode: &Mode, mode: &Mode,
deployed_libraries: Option<&HashMap<ContractInstance, (ContractIdent, Address, JsonAbi)>>, deployed_libraries: Option<&HashMap<ContractInstance, (ContractIdent, Address, JsonAbi)>>,
compiler: &P::Compiler, compiler: &P::Compiler,
reporter: &ExecutionSpecificReporter,
) -> Result<CompilerOutput> { ) -> Result<CompilerOutput> {
let all_sources_in_dir = FilesWithExtensionIterator::new(metadata_directory.as_ref()) let all_sources_in_dir = FilesWithExtensionIterator::new(metadata_directory.as_ref())
.with_allowed_extension("sol") .with_allowed_extension("sol")
.with_use_cached_fs(true) .with_use_cached_fs(true)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
Compiler::new() let compilation = Compiler::new()
.with_allow_path(metadata_directory) .with_allow_path(metadata_directory)
// Handling the modes // Handling the modes
.with_optimization(mode.optimize_setting) .with_optimization(mode.optimize_setting)
@@ -189,9 +215,57 @@ async fn compile_contracts<P: Platform>(
.fold(compiler, |compiler, (ident, address, path)| { .fold(compiler, |compiler, (ident, address, path)| {
compiler.with_library(path, ident.as_str(), *address) compiler.with_library(path, ident.as_str(), *address)
}) })
}) });
.try_build(compiler)
.await let input = compilation.input().clone();
let output = compilation.try_build(compiler).await;
match (output.as_ref(), deployed_libraries.is_some()) {
(Ok(output), true) => {
reporter
.report_post_link_contracts_compilation_succeeded_event(
compiler.version().clone(),
compiler.path(),
false,
input,
output.clone(),
)
.expect("Can't happen");
}
(Ok(output), false) => {
reporter
.report_pre_link_contracts_compilation_succeeded_event(
compiler.version().clone(),
compiler.path(),
false,
input,
output.clone(),
)
.expect("Can't happen");
}
(Err(err), true) => {
reporter
.report_post_link_contracts_compilation_failed_event(
compiler.version().clone(),
compiler.path().to_path_buf(),
input,
format!("{err:#}"),
)
.expect("Can't happen");
}
(Err(err), false) => {
reporter
.report_pre_link_contracts_compilation_failed_event(
compiler.version().clone(),
compiler.path().to_path_buf(),
input,
format!("{err:#}"),
)
.expect("Can't happen");
}
}
output
} }
struct ArtifactsCache { struct ArtifactsCache {
+6 -2
View File
@@ -523,14 +523,16 @@ where
test.metadata_file_path, test.metadata_file_path,
test.mode.clone(), test.mode.clone(),
None, None,
test.leader_compiler.as_ref() test.leader_compiler.as_ref(),
&leader_reporter,
), ),
cached_compiler.compile_contracts::<F>( cached_compiler.compile_contracts::<F>(
test.metadata, test.metadata,
test.metadata_file_path, test.metadata_file_path,
test.mode.clone(), test.mode.clone(),
None, None,
test.follower_compiler.as_ref() test.follower_compiler.as_ref(),
&follower_reporter
) )
) )
.context("Failed to compile pre-link contracts for leader/follower in parallel")?; .context("Failed to compile pre-link contracts for leader/follower in parallel")?;
@@ -675,6 +677,7 @@ where
test.mode.clone(), test.mode.clone(),
leader_deployed_libraries.as_ref(), leader_deployed_libraries.as_ref(),
test.leader_compiler.as_ref(), test.leader_compiler.as_ref(),
&leader_reporter,
), ),
cached_compiler.compile_contracts::<F>( cached_compiler.compile_contracts::<F>(
test.metadata, test.metadata,
@@ -682,6 +685,7 @@ where
test.mode.clone(), test.mode.clone(),
follower_deployed_libraries.as_ref(), follower_deployed_libraries.as_ref(),
test.follower_compiler.as_ref(), test.follower_compiler.as_ref(),
&follower_reporter
) )
) )
.context("Failed to compile post-link contracts for leader/follower in parallel")?; .context("Failed to compile post-link contracts for leader/follower in parallel")?;