chore(solc): provide remappings on unresolved import message (#1026)

This commit is contained in:
Matthias Seitz 2022-03-14 12:29:00 +01:00 committed by GitHub
parent 20a01a260d
commit 26de793698
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

View File

@ -14,7 +14,7 @@
// https://github.com/tokio-rs/tracing/blob/master/tracing-core/src/dispatch.rs // 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 semver::Version;
use std::{ use std::{
any::{Any, TypeId}, any::{Any, TypeId},
@ -102,8 +102,8 @@ pub trait Reporter: 'static {
/// Invoked before a new [`Solc`] bin was successfully installed /// Invoked before a new [`Solc`] bin was successfully installed
fn on_solc_installation_success(&self, _version: &Version) {} fn on_solc_installation_success(&self, _version: &Version) {}
/// Invoked if the import couldn't be resolved /// Invoked if the import couldn't be resolved with these remappings
fn on_unresolved_import(&self, _import: &Path) {} fn on_unresolved_import(&self, _import: &Path, _remappings: &[Remapping]) {}
/// If `self` is the same type as the provided `TypeId`, returns an untyped /// If `self` is the same type as the provided `TypeId`, returns an untyped
/// [`NonNull`] pointer to that type. Otherwise, returns `None`. /// [`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)); get_default(|r| r.reporter.on_solc_installation_success(version));
} }
pub(crate) fn unresolved_import(import: &Path) { pub(crate) fn unresolved_import(import: &Path, remappings: &[Remapping]) {
get_default(|r| r.reporter.on_unresolved_import(import)); get_default(|r| r.reporter.on_unresolved_import(import, remappings));
} }
fn get_global() -> Option<&'static Report> { fn get_global() -> Option<&'static Report> {
@ -308,8 +308,12 @@ impl Reporter for BasicStdoutReporter {
println!("Successfully installed solc {}", version); println!("Successfully installed solc {}", version);
} }
fn on_unresolved_import(&self, import: &Path) { fn on_unresolved_import(&self, import: &Path, remappings: &[Remapping]) {
println!("Unable to resolve imported file: \"{}\"", import.display()); println!(
"Unable to resolve import: \"{}\" with remappings:\n {}",
import.display(),
remappings.iter().map(|r| r.to_string()).collect::<Vec<_>>().join("\n ")
);
} }
} }

View File

@ -274,7 +274,7 @@ impl Graph {
add_node(&mut unresolved, &mut index, &mut resolved_imports, import)?; add_node(&mut unresolved, &mut index, &mut resolved_imports, import)?;
} }
Err(err) => { Err(err) => {
crate::report::unresolved_import(import.data()); crate::report::unresolved_import(import.data(), &paths.remappings);
tracing::trace!("failed to resolve import component \"{:?}\"", err) tracing::trace!("failed to resolve import component \"{:?}\"", err)
} }
}; };