diff --git a/crates/compiler/src/lib.rs b/crates/compiler/src/lib.rs index 12feb3a..b9608e0 100644 --- a/crates/compiler/src/lib.rs +++ b/crates/compiler/src/lib.rs @@ -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>; diff --git a/crates/compiler/src/revive_resolc.rs b/crates/compiler/src/revive_resolc.rs index 3cdc7fb..7c0b9da 100644 --- a/crates/compiler/src/revive_resolc.rs +++ b/crates/compiler/src/revive_resolc.rs @@ -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, diff --git a/crates/compiler/src/solc.rs b/crates/compiler/src/solc.rs index 9f0a336..ed016d9 100644 --- a/crates/compiler/src/solc.rs +++ b/crates/compiler/src/solc.rs @@ -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, diff --git a/crates/core/src/cached_compiler.rs b/crates/core/src/cached_compiler.rs index 7fca5af..ed59546 100644 --- a/crates/core/src/cached_compiler.rs +++ b/crates/core/src/cached_compiler.rs @@ -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>, compiler: &P::Compiler, + reporter: &ExecutionSpecificReporter, ) -> Result { 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( metadata_directory: impl AsRef, mut files_to_compile: impl Iterator, mode: &Mode, deployed_libraries: Option<&HashMap>, compiler: &P::Compiler, + reporter: &ExecutionSpecificReporter, ) -> Result { let all_sources_in_dir = FilesWithExtensionIterator::new(metadata_directory.as_ref()) .with_allowed_extension("sol") .with_use_cached_fs(true) .collect::>(); - 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( .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 { diff --git a/crates/core/src/main.rs b/crates/core/src/main.rs index 167b183..80caab3 100644 --- a/crates/core/src/main.rs +++ b/crates/core/src/main.rs @@ -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::( 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::( 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")?;