From 26de7936982bb7dbe2fb8626683a74b0aea00933 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 14 Mar 2022 12:29:00 +0100 Subject: [PATCH] chore(solc): provide remappings on unresolved import message (#1026) --- ethers-solc/src/report.rs | 18 +++++++++++------- ethers-solc/src/resolver/mod.rs | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/ethers-solc/src/report.rs b/ethers-solc/src/report.rs index b4b38253..b7f1a1bc 100644 --- a/ethers-solc/src/report.rs +++ b/ethers-solc/src/report.rs @@ -14,7 +14,7 @@ // https://github.com/tokio-rs/tracing/blob/master/tracing-core/src/dispatch.rs -use crate::{CompilerInput, CompilerOutput, Solc}; +use crate::{remappings::Remapping, CompilerInput, CompilerOutput, Solc}; use semver::Version; use std::{ any::{Any, TypeId}, @@ -102,8 +102,8 @@ pub trait Reporter: 'static { /// Invoked before a new [`Solc`] bin was successfully installed fn on_solc_installation_success(&self, _version: &Version) {} - /// Invoked if the import couldn't be resolved - fn on_unresolved_import(&self, _import: &Path) {} + /// Invoked if the import couldn't be resolved with these remappings + fn on_unresolved_import(&self, _import: &Path, _remappings: &[Remapping]) {} /// If `self` is the same type as the provided `TypeId`, returns an untyped /// [`NonNull`] pointer to that type. Otherwise, returns `None`. @@ -166,8 +166,8 @@ pub(crate) fn solc_installation_success(version: &Version) { get_default(|r| r.reporter.on_solc_installation_success(version)); } -pub(crate) fn unresolved_import(import: &Path) { - get_default(|r| r.reporter.on_unresolved_import(import)); +pub(crate) fn unresolved_import(import: &Path, remappings: &[Remapping]) { + get_default(|r| r.reporter.on_unresolved_import(import, remappings)); } fn get_global() -> Option<&'static Report> { @@ -308,8 +308,12 @@ impl Reporter for BasicStdoutReporter { println!("Successfully installed solc {}", version); } - fn on_unresolved_import(&self, import: &Path) { - println!("Unable to resolve imported file: \"{}\"", import.display()); + fn on_unresolved_import(&self, import: &Path, remappings: &[Remapping]) { + println!( + "Unable to resolve import: \"{}\" with remappings:\n {}", + import.display(), + remappings.iter().map(|r| r.to_string()).collect::>().join("\n ") + ); } } diff --git a/ethers-solc/src/resolver/mod.rs b/ethers-solc/src/resolver/mod.rs index a62fc258..f0a70bd7 100644 --- a/ethers-solc/src/resolver/mod.rs +++ b/ethers-solc/src/resolver/mod.rs @@ -274,7 +274,7 @@ impl Graph { add_node(&mut unresolved, &mut index, &mut resolved_imports, import)?; } Err(err) => { - crate::report::unresolved_import(import.data()); + crate::report::unresolved_import(import.data(), &paths.remappings); tracing::trace!("failed to resolve import component \"{:?}\"", err) } };