Skip to content

Commit

Permalink
chore(nargo): remove cached_packages field from Resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Mar 20, 2023
1 parent 1f50994 commit ae84b12
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions crates/nargo/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ struct CachedDep {
/// Downloading will be recursive, so if a package contains packages
/// We need to download those too
pub(crate) struct Resolver<'a> {
cached_packages: HashMap<PathBuf, (CrateId, CachedDep)>,
driver: &'a mut Driver,
}

impl<'a> Resolver<'a> {
fn with_driver(driver: &mut Driver) -> Resolver {
Resolver { cached_packages: HashMap::new(), driver }
Resolver { driver }
}

/// Returns the Driver and the backend to use
Expand Down Expand Up @@ -79,6 +78,8 @@ impl<'a> Resolver<'a> {
parent_crate: CrateId,
manifest: PackageManifest,
) -> Result<(), CliError> {
let mut cached_packages: HashMap<PathBuf, (CrateId, CachedDep)> = HashMap::new();

// First download and add these top level dependencies crates to the Driver
for (dep_pkg_name, pkg_src) in manifest.dependencies.iter() {
let (dir_path, dep_meta) = Resolver::cache_dep(pkg_src)?;
Expand All @@ -94,19 +95,19 @@ impl<'a> Resolver<'a> {
let crate_id = self.driver.create_non_local_crate(entry_path, *crate_type);
self.driver.add_dep(parent_crate, crate_id, dep_pkg_name);

self.cached_packages.insert(dir_path, (crate_id, dep_meta));
cached_packages.insert(dir_path, (crate_id, dep_meta));
}

// Resolve all transitive dependencies
for (dir_path, (crate_id, dep_meta)) in self.cached_packages.iter() {
for (dir_path, (crate_id, dep_meta)) in cached_packages.into_iter() {
if dep_meta.remote && manifest.has_local_path() {
return Err(CliError::Generic(format!(
"remote(git) dependency depends on a local path. \ndependency located at {}",
dir_path.display()
)));
}
let mut new_res = Resolver::with_driver(self.driver);
new_res.resolve_manifest(*crate_id, dep_meta.manifest.clone())?;
new_res.resolve_manifest(crate_id, dep_meta.manifest)?;
}
Ok(())
}
Expand Down

0 comments on commit ae84b12

Please sign in to comment.