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

Commit

Permalink
wasm compat
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Dec 30, 2021
1 parent 45f10a4 commit 314a703
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
1 change: 1 addition & 0 deletions ethers-solc/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ impl Solc {
}

/// Returns the list of all solc instances installed at `SVM_HOME`
#[cfg(not(target_arch = "wasm32"))]
pub fn installed_versions() -> Vec<SolcVersion> {
if let Some(home) = Self::svm_home() {
utils::installed_versions(home)
Expand Down
31 changes: 18 additions & 13 deletions ethers-solc/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ pub struct Graph {
/// with how many input files we started with, corresponds to `let input_files =
/// nodes[..num_input_files]`.
num_input_files: usize,
/// the root of the project this graph represents
root: PathBuf,
}

impl Graph {
Expand Down Expand Up @@ -166,7 +168,7 @@ impl Graph {
edges.push(resolved_imports);
}

Ok(Graph { nodes, edges, indices: index, num_input_files })
Ok(Graph { nodes, edges, indices: index, num_input_files, root: paths.root.clone() })
}

/// Resolves the dependencies of a project's source contracts
Expand Down Expand Up @@ -236,9 +238,9 @@ impl Graph {
writeln!(
f,
" {} ({:?}) imports {} ({:?})",
node.path.display(),
utils::source_name(&node.path, &self.root).display(),
node.data.version,
dep.path.display(),
utils::source_name(&dep.path, &self.root).display(),
dep.data.version
)?;
}
Expand All @@ -254,23 +256,26 @@ impl Graph {
&self,
idx: usize,
candidates: &mut Vec<&crate::SolcVersion>,
traversed: &mut std::collections::HashSet<usize>,
traversed: &mut std::collections::HashSet<(usize, usize)>,
) -> std::result::Result<(), String> {
let node = self.node(idx);

// check for circular deps
if traversed.contains(&idx) {
let mut msg = String::new();
self.format_imports_list(idx, &mut msg).unwrap();
return Err(format!("Encountered circular dependencies in:\n{}", msg))
}
traversed.insert(idx);

if let Some(ref req) = node.data.version_req {
candidates.retain(|v| req.matches(v.as_ref()));
}
for dep in self.imported_nodes(idx) {
self.retain_compatible_versions(*dep, candidates, traversed)?;
let dep = *dep;
// check for circular deps which would result in endless recursion SO here
// a circular dependency exists, if there was already a `dependency imports current
// node` relationship in the traversed path
if traversed.contains(&(dep, idx)) {
let mut msg = String::new();
self.format_imports_list(dep, &mut msg).unwrap();
return Err(format!("Encountered circular dependencies in:\n{}", msg))
}
traversed.insert((idx, dep));

self.retain_compatible_versions(dep, candidates, traversed)?;
}
Ok(())
}
Expand Down

0 comments on commit 314a703

Please sign in to comment.