Skip to content

Commit

Permalink
fix(nargo): Set current dir to package root before executing commands (
Browse files Browse the repository at this point in the history
…#1034)

* Set current dir to package root before executing commands

* Pass pkg root to manifest resolver

* Code review

* Formatting
  • Loading branch information
ax0 authored Mar 25, 2023
1 parent e2b8b65 commit 38bf571
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions crates/nargo/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,13 @@ impl<'a> Resolver<'a> {
let (entry_path, crate_type) = super::lib_or_bin(dir_path)?;

let manifest_path = super::find_package_manifest(dir_path)?;
let manifest = super::manifest::parse(manifest_path)?;
let manifest = super::manifest::parse(&manifest_path)?;

let crate_id = driver.create_local_crate(entry_path, crate_type);

let mut resolver = Resolver::with_driver(&mut driver);
resolver.resolve_manifest(crate_id, manifest)?;
let pkg_root = manifest_path.parent().expect("Every manifest path has a parent.");
resolver.resolve_manifest(crate_id, manifest, pkg_root)?;

add_std_lib(&mut driver);
Ok(driver)
Expand All @@ -100,12 +101,13 @@ impl<'a> Resolver<'a> {
&mut self,
parent_crate: CrateId,
manifest: PackageManifest,
pkg_root: &Path,
) -> Result<(), DependencyResolutionError> {
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)?;
let (dir_path, dep_meta) = Resolver::cache_dep(pkg_src, pkg_root)?;

let (entry_path, crate_type) = (&dep_meta.entry_path, &dep_meta.crate_type);

Expand All @@ -127,7 +129,7 @@ impl<'a> Resolver<'a> {
return Err(DependencyResolutionError::RemoteDepWithLocalDep { dependency_path });
}
let mut new_res = Resolver::with_driver(self.driver);
new_res.resolve_manifest(crate_id, dep_meta.manifest)?;
new_res.resolve_manifest(crate_id, dep_meta.manifest, &dependency_path)?;
}
Ok(())
}
Expand All @@ -138,7 +140,10 @@ impl<'a> Resolver<'a> {
///
/// If it's a local path, the same applies, however it will not
/// be downloaded
fn cache_dep(dep: &Dependency) -> Result<(PathBuf, CachedDep), DependencyResolutionError> {
fn cache_dep(
dep: &Dependency,
pkg_root: &Path,
) -> Result<(PathBuf, CachedDep), DependencyResolutionError> {
fn retrieve_meta(
dir_path: &Path,
remote: bool,
Expand All @@ -157,7 +162,7 @@ impl<'a> Resolver<'a> {
Ok((dir_path, meta))
}
Dependency::Path { path } => {
let dir_path = std::path::PathBuf::from(path);
let dir_path = pkg_root.join(path);
let meta = retrieve_meta(&dir_path, false)?;
Ok((dir_path, meta))
}
Expand Down

0 comments on commit 38bf571

Please sign in to comment.