From 9c44eeac062f102cece132c37bb48792583ff9b8 Mon Sep 17 00:00:00 2001 From: DavidK Date: Mon, 6 Jan 2025 16:09:53 +0200 Subject: [PATCH 1/2] Adds import callback resolution to resolc compiler --- crates/solidity/src/lib.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/solidity/src/lib.rs b/crates/solidity/src/lib.rs index ea71225d..4bcb2aa4 100644 --- a/crates/solidity/src/lib.rs +++ b/crates/solidity/src/lib.rs @@ -52,7 +52,7 @@ pub use self::warning::Warning; pub mod test_utils; pub mod tests; -use std::collections::BTreeSet; +use std::collections::{BTreeMap, BTreeSet}; use std::path::PathBuf; /// Runs the Yul mode. @@ -149,7 +149,7 @@ pub fn standard_output( suppressed_warnings, )?; - let source_code_files = solc_input + let mut source_code_files: BTreeMap = solc_input .sources .iter() .map(|(path, source)| (path.to_owned(), source.content.to_owned())) @@ -180,6 +180,17 @@ pub fn standard_output( } } + // load import callbacks unspecified in input + if let Some(sources) = &solc_output.sources { + for source_path in sources.keys() { + if !source_code_files.contains_key(source_path) { + let source = std::fs::read_to_string(source_path) + .map_err(|e| anyhow::anyhow!("Can't read source file at `{}`: {}", source_path, e))?; + let _ = source_code_files.insert(source_path.clone(), source); + } + } + } + let project = solc_output.try_to_project( source_code_files, libraries, From 3184397c4374e6c044df29d3b5fa38f8526515c5 Mon Sep 17 00:00:00 2001 From: DavidK Date: Mon, 6 Jan 2025 16:29:59 +0200 Subject: [PATCH 2/2] cargo fmt --- crates/solidity/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/solidity/src/lib.rs b/crates/solidity/src/lib.rs index 4bcb2aa4..751bbbd3 100644 --- a/crates/solidity/src/lib.rs +++ b/crates/solidity/src/lib.rs @@ -184,8 +184,9 @@ pub fn standard_output( if let Some(sources) = &solc_output.sources { for source_path in sources.keys() { if !source_code_files.contains_key(source_path) { - let source = std::fs::read_to_string(source_path) - .map_err(|e| anyhow::anyhow!("Can't read source file at `{}`: {}", source_path, e))?; + let source = std::fs::read_to_string(source_path).map_err(|e| { + anyhow::anyhow!("Can't read source file at `{}`: {}", source_path, e) + })?; let _ = source_code_files.insert(source_path.clone(), source); } }