Skip to content
This repository was archived by the owner on Oct 19, 2024. It is now read-only.

Commit 27a4454

Browse files
authored
feat(solc): report on unresolved imports (#905)
* chore: fix unused import warning * feat: add additional report message
1 parent d28e695 commit 27a4454

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

Diff for: ethers-solc/src/compile/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,12 @@ pub const BERLIN_SOLC: Version = Version::new(0, 8, 5);
4242
/// https://blog.soliditylang.org/2021/08/11/solidity-0.8.7-release-announcement/
4343
pub const LONDON_SOLC: Version = Version::new(0, 8, 7);
4444

45-
#[cfg(any(test, all(feature = "svm", feature = "async")))]
46-
use once_cell::sync::Lazy;
47-
4845
#[cfg(any(test, feature = "tests"))]
4946
use std::sync::Mutex;
5047

5148
#[cfg(any(test, feature = "tests"))]
5249
#[allow(unused)]
53-
static LOCK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
50+
static LOCK: once_cell::sync::Lazy<Mutex<()>> = once_cell::sync::Lazy::new(|| Mutex::new(()));
5451

5552
/// take the lock in tests, we use this to enforce that
5653
/// a test does not run while a compiler version is being installed

Diff for: ethers-solc/src/report.rs

+12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use semver::Version;
55
use std::{
66
error::Error,
77
fmt,
8+
path::Path,
89
sync::{
910
atomic::{AtomicUsize, Ordering},
1011
Arc,
@@ -65,6 +66,9 @@ pub trait Reporter: 'static {
6566

6667
/// Invoked before a new [`Solc`] bin was successfully installed
6768
fn on_solc_installation_success(&self, _version: &Version) {}
69+
70+
/// Invoked if the import couldn't be resolved
71+
fn on_unresolved_import(&self, _import: &Path) {}
6872
}
6973

7074
pub(crate) fn solc_spawn(solc: &Solc, version: &Version, input: &CompilerInput) {
@@ -85,6 +89,10 @@ pub(crate) fn solc_installation_success(version: &Version) {
8589
with_global(|r| r.reporter.on_solc_installation_success(version));
8690
}
8791

92+
pub(crate) fn unresolved_import(import: &Path) {
93+
with_global(|r| r.reporter.on_unresolved_import(import));
94+
}
95+
8896
fn get_global() -> Option<&'static Report> {
8997
if GLOBAL_REPORTER_STATE.load(Ordering::SeqCst) != SET {
9098
return None
@@ -139,6 +147,10 @@ impl Reporter for BasicStdoutReporter {
139147
fn on_solc_installation_success(&self, version: &Version) {
140148
println!("Successfully installed solc {}", version);
141149
}
150+
151+
fn on_unresolved_import(&self, import: &Path) {
152+
println!("Unable to resolve imported file: \"{}\"", import.display());
153+
}
142154
}
143155

144156
/// Returned if setting the global reporter fails.

Diff for: ethers-solc/src/resolver.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,10 @@ impl Graph {
239239
Ok(import) => {
240240
add_node(&mut unresolved, &mut index, &mut resolved_imports, import)?;
241241
}
242-
Err(err) => tracing::trace!("failed to resolve import component \"{:?}\"", err),
242+
Err(err) => {
243+
crate::report::unresolved_import(import.data());
244+
tracing::trace!("failed to resolve import component \"{:?}\"", err)
245+
}
243246
};
244247
}
245248
nodes.push(node);

0 commit comments

Comments
 (0)