Return solc_version in CompilerOutput

This commit is contained in:
James Wilson
2025-08-27 10:45:22 +01:00
parent 4af9f6695d
commit dd94b12b34
8 changed files with 131 additions and 178 deletions
+27 -55
View File
@@ -9,7 +9,7 @@ use std::{
use futures::FutureExt;
use revive_dt_common::iterators::FilesWithExtensionIterator;
use revive_dt_compiler::{Compiler, CompilerInput, CompilerOutput, Mode};
use revive_dt_compiler::{Compiler, CompilerInput, CompilerOutput, Mode, SolcCompilerInformation};
use revive_dt_config::Arguments;
use revive_dt_format::metadata::{ContractIdent, ContractInstance, Metadata};
use revive_dt_solc_binaries::solc_version;
@@ -57,29 +57,23 @@ impl CachedCompiler {
mode: &Mode,
config: &Arguments,
deployed_libraries: Option<&HashMap<ContractInstance, (ContractIdent, Address, JsonAbi)>>,
compilation_success_report_callback: impl Fn(
Version,
PathBuf,
bool,
Option<CompilerInput>,
CompilerOutput,
) + Clone,
compilation_success_report_callback: impl Fn(bool, Option<CompilerInput>, CompilerOutput)
+ Clone,
compilation_failure_report_callback: impl Fn(
Option<Version>,
Option<PathBuf>,
Option<SolcCompilerInformation>,
Option<CompilerInput>,
String,
),
) -> Result<(CompilerOutput, Version)> {
) -> Result<CompilerOutput> {
static CACHE_KEY_LOCK: Lazy<RwLock<HashMap<CacheKey, Arc<Mutex<()>>>>> =
Lazy::new(Default::default);
let compiler_version_or_requirement = mode.compiler_version_to_use(config.solc.clone());
let compiler_version = solc_version(compiler_version_or_requirement, config.wasm).await?;
let solc_version_or_requirement = mode.compiler_version_to_use(config.solc.clone());
let solc_version = solc_version(solc_version_or_requirement, false).await?;
let cache_key = CacheKey {
platform_key: P::config_id().to_string(),
compiler_version: compiler_version.clone(),
compiler_version: solc_version.clone(),
metadata_file_path: metadata_file_path.as_ref().to_path_buf(),
solc_mode: mode.clone(),
};
@@ -146,13 +140,11 @@ impl CachedCompiler {
match self.0.get(&cache_key).await {
Some(cache_value) => {
// compilation_success_report_callback(
// compiler_version.clone(),
// compiler_path,
// true,
// None,
// cache_value.compiler_output.clone(),
// );
compilation_success_report_callback(
true,
None,
cache_value.compiler_output.clone(),
);
cache_value.compiler_output
}
None => {
@@ -165,7 +157,7 @@ impl CachedCompiler {
}
};
Ok((compiled_contracts, compiler_version))
Ok(compiled_contracts)
}
}
@@ -176,16 +168,9 @@ async fn compile_contracts<P: Platform>(
config: &Arguments,
mode: &Mode,
deployed_libraries: Option<&HashMap<ContractInstance, (ContractIdent, Address, JsonAbi)>>,
compilation_success_report_callback: impl Fn(
Version,
PathBuf,
bool,
Option<CompilerInput>,
CompilerOutput,
),
compilation_success_report_callback: impl Fn(bool, Option<CompilerInput>, CompilerOutput),
compilation_failure_report_callback: impl Fn(
Option<Version>,
Option<PathBuf>,
Option<SolcCompilerInformation>,
Option<CompilerInput>,
String,
),
@@ -204,15 +189,8 @@ async fn compile_contracts<P: Platform>(
// Adding the contract sources to the compiler.
.try_then(|compiler| {
files_to_compile.try_fold(compiler, |compiler, path| compiler.with_source(path))
// })
// .inspect_err(|err| {
// compilation_failure_report_callback(
// Some(compiler_version.clone()),
// Some(compiler_path.as_ref().to_path_buf()),
// None,
// format!("{err:#}"),
// )
})?
})
.inspect_err(|err| compilation_failure_report_callback(None, None, format!("{err:#}")))?
// Adding the deployed libraries to the compiler.
.then(|compiler| {
deployed_libraries
@@ -233,22 +211,16 @@ async fn compile_contracts<P: Platform>(
let compiler_output = compiler
.try_build(config)
.await
// .inspect_err(|err| {
// compilation_failure_report_callback(
// Some(compiler_version.clone()),
// Some(compiler_path.as_ref().to_path_buf()),
// Some(compiler_input.clone()),
// format!("{err:#}"),
// )
// })
.inspect_err(|err| {
compilation_failure_report_callback(
None,
Some(compiler_input.clone()),
format!("{err:#}"),
)
})
.context("Failed to configure compiler with sources and options")?;
// compilation_success_report_callback(
// compiler_version,
// compiler_path.as_ref().to_path_buf(),
// false,
// Some(compiler_input),
// compiler_output.clone(),
// );
compilation_success_report_callback(false, Some(compiler_input), compiler_output.clone());
Ok(compiler_output)
}
+36 -56
View File
@@ -18,12 +18,12 @@ use futures::StreamExt;
use futures::stream;
use indexmap::IndexMap;
use revive_dt_node_interaction::EthereumNode;
use tempfile::TempDir;
use tokio::{join, try_join};
use revive_dt_report::{
NodeDesignation, ReportAggregator, Reporter, ReporterEvent, TestCaseStatus,
TestSpecificReporter, TestSpecifier,
};
use tempfile::TempDir;
use tokio::{join, try_join};
use tracing::{debug, info, info_span, instrument};
use tracing_appender::non_blocking::WorkerGuard;
use tracing_subscriber::{EnvFilter, FmtSubscriber};
@@ -612,18 +612,14 @@ where
.execution_specific_reporter(follower_node.id(), NodeDesignation::Follower);
let (
(
CompilerOutput {
contracts: leader_pre_link_contracts,
},
_,
),
(
CompilerOutput {
contracts: follower_pre_link_contracts,
},
_,
),
CompilerOutput {
contracts: leader_pre_link_contracts,
..
},
CompilerOutput {
contracts: follower_pre_link_contracts,
..
},
) = try_join!(
cached_compiler.compile_contracts::<L>(
test.metadata,
@@ -631,22 +627,19 @@ where
&test.mode,
config,
None,
|compiler_version, compiler_path, is_cached, compiler_input, compiler_output| {
|is_cached, compiler_input, compiler_output| {
leader_reporter
.report_pre_link_contracts_compilation_succeeded_event(
compiler_version,
compiler_path,
is_cached,
compiler_input,
compiler_output,
)
.expect("Can't fail")
},
|compiler_version, compiler_path, compiler_input, failure_reason| {
|solc_info, compiler_input, failure_reason| {
leader_reporter
.report_pre_link_contracts_compilation_failed_event(
compiler_version,
compiler_path,
solc_info,
compiler_input,
failure_reason,
)
@@ -659,22 +652,19 @@ where
&test.mode,
config,
None,
|compiler_version, compiler_path, is_cached, compiler_input, compiler_output| {
|is_cached, compiler_input, compiler_output| {
follower_reporter
.report_pre_link_contracts_compilation_succeeded_event(
compiler_version,
compiler_path,
is_cached,
compiler_input,
compiler_output,
)
.expect("Can't fail")
},
|compiler_version, compiler_path, compiler_input, failure_reason| {
|solc_info, compiler_input, failure_reason| {
follower_reporter
.report_pre_link_contracts_compilation_failed_event(
compiler_version,
compiler_path,
solc_info,
compiler_input,
failure_reason,
)
@@ -811,18 +801,14 @@ where
}
let (
(
CompilerOutput {
contracts: leader_post_link_contracts,
},
leader_compiler_version,
),
(
CompilerOutput {
contracts: follower_post_link_contracts,
},
follower_compiler_version,
),
CompilerOutput {
solc: leader_solc_info,
contracts: leader_post_link_contracts,
},
CompilerOutput {
solc: follower_solc_info,
contracts: follower_post_link_contracts,
},
) = try_join!(
cached_compiler.compile_contracts::<L>(
test.metadata,
@@ -830,22 +816,19 @@ where
&test.mode,
config,
leader_deployed_libraries.as_ref(),
|compiler_version, compiler_path, is_cached, compiler_input, compiler_output| {
|is_cached, compiler_input, compiler_output| {
leader_reporter
.report_post_link_contracts_compilation_succeeded_event(
compiler_version,
compiler_path,
is_cached,
compiler_input,
compiler_output,
)
.expect("Can't fail")
},
|compiler_version, compiler_path, compiler_input, failure_reason| {
|solc_info, compiler_input, failure_reason| {
leader_reporter
.report_post_link_contracts_compilation_failed_event(
compiler_version,
compiler_path,
solc_info,
compiler_input,
failure_reason,
)
@@ -858,22 +841,19 @@ where
&test.mode,
config,
follower_deployed_libraries.as_ref(),
|compiler_version, compiler_path, is_cached, compiler_input, compiler_output| {
|is_cached, compiler_input, compiler_output| {
follower_reporter
.report_post_link_contracts_compilation_succeeded_event(
compiler_version,
compiler_path,
is_cached,
compiler_input,
compiler_output,
)
.expect("Can't fail")
},
|compiler_version, compiler_path, compiler_input, failure_reason| {
|solc_info, compiler_input, failure_reason| {
follower_reporter
.report_post_link_contracts_compilation_failed_event(
compiler_version,
compiler_path,
solc_info,
compiler_input,
failure_reason,
)
@@ -884,13 +864,13 @@ where
.context("Failed to compile post-link contracts for leader/follower in parallel")?;
let leader_state = CaseState::<L>::new(
leader_compiler_version,
leader_solc_info.version,
leader_post_link_contracts,
leader_deployed_libraries.unwrap_or_default(),
leader_reporter,
);
let follower_state = CaseState::<F>::new(
follower_compiler_version,
follower_solc_info.version,
follower_post_link_contracts,
follower_deployed_libraries.unwrap_or_default(),
follower_reporter,
@@ -963,8 +943,8 @@ async fn compile_corpus(
&mode,
config,
None,
|_, _, _, _, _| {},
|_, _, _, _| {},
|_, _, _| {},
|_, _, _| {},
)
.await;
}
@@ -976,8 +956,8 @@ async fn compile_corpus(
&mode,
config,
None,
|_, _, _, _, _| {},
|_, _, _, _| {},
|_, _, _| {},
|_, _, _| {},
)
.await;
}