feat(solc): report on unresolved imports (#905)
* chore: fix unused import warning * feat: add additional report message
This commit is contained in:
parent
d28e6959db
commit
27a4454ac0
|
@ -42,15 +42,12 @@ pub const BERLIN_SOLC: Version = Version::new(0, 8, 5);
|
||||||
/// https://blog.soliditylang.org/2021/08/11/solidity-0.8.7-release-announcement/
|
/// https://blog.soliditylang.org/2021/08/11/solidity-0.8.7-release-announcement/
|
||||||
pub const LONDON_SOLC: Version = Version::new(0, 8, 7);
|
pub const LONDON_SOLC: Version = Version::new(0, 8, 7);
|
||||||
|
|
||||||
#[cfg(any(test, all(feature = "svm", feature = "async")))]
|
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
|
|
||||||
#[cfg(any(test, feature = "tests"))]
|
#[cfg(any(test, feature = "tests"))]
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
#[cfg(any(test, feature = "tests"))]
|
#[cfg(any(test, feature = "tests"))]
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
static LOCK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
|
static LOCK: once_cell::sync::Lazy<Mutex<()>> = once_cell::sync::Lazy::new(|| Mutex::new(()));
|
||||||
|
|
||||||
/// take the lock in tests, we use this to enforce that
|
/// take the lock in tests, we use this to enforce that
|
||||||
/// a test does not run while a compiler version is being installed
|
/// a test does not run while a compiler version is being installed
|
||||||
|
|
|
@ -5,6 +5,7 @@ use semver::Version;
|
||||||
use std::{
|
use std::{
|
||||||
error::Error,
|
error::Error,
|
||||||
fmt,
|
fmt,
|
||||||
|
path::Path,
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{AtomicUsize, Ordering},
|
atomic::{AtomicUsize, Ordering},
|
||||||
Arc,
|
Arc,
|
||||||
|
@ -65,6 +66,9 @@ 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
|
||||||
|
fn on_unresolved_import(&self, _import: &Path) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn solc_spawn(solc: &Solc, version: &Version, input: &CompilerInput) {
|
pub(crate) fn solc_spawn(solc: &Solc, version: &Version, input: &CompilerInput) {
|
||||||
|
@ -85,6 +89,10 @@ pub(crate) fn solc_installation_success(version: &Version) {
|
||||||
with_global(|r| r.reporter.on_solc_installation_success(version));
|
with_global(|r| r.reporter.on_solc_installation_success(version));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn unresolved_import(import: &Path) {
|
||||||
|
with_global(|r| r.reporter.on_unresolved_import(import));
|
||||||
|
}
|
||||||
|
|
||||||
fn get_global() -> Option<&'static Report> {
|
fn get_global() -> Option<&'static Report> {
|
||||||
if GLOBAL_REPORTER_STATE.load(Ordering::SeqCst) != SET {
|
if GLOBAL_REPORTER_STATE.load(Ordering::SeqCst) != SET {
|
||||||
return None
|
return None
|
||||||
|
@ -139,6 +147,10 @@ impl Reporter for BasicStdoutReporter {
|
||||||
fn on_solc_installation_success(&self, version: &Version) {
|
fn on_solc_installation_success(&self, version: &Version) {
|
||||||
println!("Successfully installed solc {}", version);
|
println!("Successfully installed solc {}", version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn on_unresolved_import(&self, import: &Path) {
|
||||||
|
println!("Unable to resolve imported file: \"{}\"", import.display());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returned if setting the global reporter fails.
|
/// Returned if setting the global reporter fails.
|
||||||
|
|
|
@ -239,7 +239,10 @@ impl Graph {
|
||||||
Ok(import) => {
|
Ok(import) => {
|
||||||
add_node(&mut unresolved, &mut index, &mut resolved_imports, import)?;
|
add_node(&mut unresolved, &mut index, &mut resolved_imports, import)?;
|
||||||
}
|
}
|
||||||
Err(err) => tracing::trace!("failed to resolve import component \"{:?}\"", err),
|
Err(err) => {
|
||||||
|
crate::report::unresolved_import(import.data());
|
||||||
|
tracing::trace!("failed to resolve import component \"{:?}\"", err)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
nodes.push(node);
|
nodes.push(node);
|
||||||
|
|
Loading…
Reference in New Issue