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.
fn version(&self) -> &Version;
/// Returns the path of the compiler executable.
fn path(&self) -> &Path;
/// The low-level compiler interface.
fn build(&self, input: CompilerInput) -> impl Future<Output = Result<CompilerOutput>>;
+4
View File
@@ -67,6 +67,10 @@ impl SolidityCompiler for Resolc {
self.solc.version()
}
fn path(&self) -> &std::path::Path {
&self.resolc_path
}
#[tracing::instrument(level = "debug", ret)]
async fn build(
&self,
+4
View File
@@ -68,6 +68,10 @@ impl SolidityCompiler for Solc {
&self.solc_version
}
fn path(&self) -> &std::path::Path {
&self.solc_path
}
#[tracing::instrument(level = "debug", ret)]
async fn build(
&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 anyhow::{Context as _, Error, Result};
use revive_dt_report::ExecutionSpecificReporter;
use semver::Version;
use serde::{Deserialize, Serialize};
use tokio::sync::{Mutex, RwLock};
@@ -67,6 +68,7 @@ impl<'a> CachedCompiler<'a> {
mode: Cow<'a, Mode>,
deployed_libraries: Option<&HashMap<ContractInstance, (ContractIdent, Address, JsonAbi)>>,
compiler: &P::Compiler,
reporter: &ExecutionSpecificReporter,
) -> Result<CompilerOutput> {
let cache_key = CacheKey {
platform_key: P::config_id(),
@@ -87,6 +89,7 @@ impl<'a> CachedCompiler<'a> {
&mode,
deployed_libraries,
compiler,
reporter,
)
.map(|compilation_result| compilation_result.map(CacheValue::new))
.await
@@ -138,7 +141,30 @@ impl<'a> CachedCompiler<'a> {
let _guard = mutex.lock().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 => {
compilation_callback()
.await
@@ -153,20 +179,20 @@ impl<'a> CachedCompiler<'a> {
}
}
#[allow(clippy::too_many_arguments)]
async fn compile_contracts<P: Platform>(
metadata_directory: impl AsRef<Path>,
mut files_to_compile: impl Iterator<Item = PathBuf>,
mode: &Mode,
deployed_libraries: Option<&HashMap<ContractInstance, (ContractIdent, Address, JsonAbi)>>,
compiler: &P::Compiler,
reporter: &ExecutionSpecificReporter,
) -> Result<CompilerOutput> {
let all_sources_in_dir = FilesWithExtensionIterator::new(metadata_directory.as_ref())
.with_allowed_extension("sol")
.with_use_cached_fs(true)
.collect::<Vec<_>>();
Compiler::new()
let compilation = Compiler::new()
.with_allow_path(metadata_directory)
// Handling the modes
.with_optimization(mode.optimize_setting)
@@ -189,9 +215,57 @@ async fn compile_contracts<P: Platform>(
.fold(compiler, |compiler, (ident, address, path)| {
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 {
+6 -2
View File
@@ -523,14 +523,16 @@ where
test.metadata_file_path,
test.mode.clone(),
None,
test.leader_compiler.as_ref()
test.leader_compiler.as_ref(),
&leader_reporter,
),
cached_compiler.compile_contracts::<F>(
test.metadata,
test.metadata_file_path,
test.mode.clone(),
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")?;
@@ -675,6 +677,7 @@ where
test.mode.clone(),
leader_deployed_libraries.as_ref(),
test.leader_compiler.as_ref(),
&leader_reporter,
),
cached_compiler.compile_contracts::<F>(
test.metadata,
@@ -682,6 +685,7 @@ where
test.mode.clone(),
follower_deployed_libraries.as_ref(),
test.follower_compiler.as_ref(),
&follower_reporter
)
)
.context("Failed to compile post-link contracts for leader/follower in parallel")?;