From 8cbdca54cb590260e3b447fde26cbc7e54e7e6d5 Mon Sep 17 00:00:00 2001 From: Ahmad Date: Thu, 23 Mar 2023 17:43:10 +0100 Subject: [PATCH 1/4] Set current dir to package root before executing commands --- crates/nargo/src/cli/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/nargo/src/cli/mod.rs b/crates/nargo/src/cli/mod.rs index ca9c43d029b..5dae7efdb08 100644 --- a/crates/nargo/src/cli/mod.rs +++ b/crates/nargo/src/cli/mod.rs @@ -68,6 +68,7 @@ pub fn start_cli() -> eyre::Result<()> { // Search through parent directories to find package root if necessary. if !matches!(command, NargoCommand::New(_)) { config.program_dir = find_package_root(&config.program_dir)?; + std::env::set_current_dir(&config.program_dir)?; } match command { From abb6133ab1037a4ab6359a8ac243c8fbde1c331b Mon Sep 17 00:00:00 2001 From: Ahmad Date: Fri, 24 Mar 2023 03:39:05 +0100 Subject: [PATCH 2/4] Pass pkg root to manifest resolver --- crates/nargo/src/cli/mod.rs | 1 - crates/nargo/src/resolver.rs | 16 ++++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/crates/nargo/src/cli/mod.rs b/crates/nargo/src/cli/mod.rs index 5dae7efdb08..ca9c43d029b 100644 --- a/crates/nargo/src/cli/mod.rs +++ b/crates/nargo/src/cli/mod.rs @@ -68,7 +68,6 @@ pub fn start_cli() -> eyre::Result<()> { // Search through parent directories to find package root if necessary. if !matches!(command, NargoCommand::New(_)) { config.program_dir = find_package_root(&config.program_dir)?; - std::env::set_current_dir(&config.program_dir)?; } match command { diff --git a/crates/nargo/src/resolver.rs b/crates/nargo/src/resolver.rs index e471e724830..8276f23f75b 100644 --- a/crates/nargo/src/resolver.rs +++ b/crates/nargo/src/resolver.rs @@ -79,12 +79,12 @@ 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)?; + resolver.resolve_manifest(crate_id, manifest, manifest_path.parent().unwrap())?; add_std_lib(&mut driver); Ok(driver) @@ -100,12 +100,13 @@ impl<'a> Resolver<'a> { &mut self, parent_crate: CrateId, manifest: PackageManifest, + pkg_root: &Path, ) -> Result<(), DependencyResolutionError> { let mut cached_packages: HashMap = 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); @@ -127,7 +128,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, pkg_root)?; } Ok(()) } @@ -138,7 +139,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, @@ -157,7 +161,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)) } From 385d146004770fc90fed223ab40d1cf71793204e Mon Sep 17 00:00:00 2001 From: Ahmad Date: Fri, 24 Mar 2023 21:51:47 +0100 Subject: [PATCH 3/4] Code review --- crates/nargo/src/resolver.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/nargo/src/resolver.rs b/crates/nargo/src/resolver.rs index 8276f23f75b..9d351547388 100644 --- a/crates/nargo/src/resolver.rs +++ b/crates/nargo/src/resolver.rs @@ -84,7 +84,8 @@ impl<'a> Resolver<'a> { 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, manifest_path.parent().unwrap())?; + 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) @@ -128,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, pkg_root)?; + new_res.resolve_manifest(crate_id, dep_meta.manifest, &dependency_path)?; } Ok(()) } From cc493d5839d04272710a93ec03ae5325efbb675e Mon Sep 17 00:00:00 2001 From: Ahmad Date: Fri, 24 Mar 2023 21:52:58 +0100 Subject: [PATCH 4/4] Formatting --- crates/nargo/src/resolver.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/nargo/src/resolver.rs b/crates/nargo/src/resolver.rs index 9d351547388..e78d0e73a68 100644 --- a/crates/nargo/src/resolver.rs +++ b/crates/nargo/src/resolver.rs @@ -84,7 +84,7 @@ impl<'a> Resolver<'a> { let crate_id = driver.create_local_crate(entry_path, crate_type); let mut resolver = Resolver::with_driver(&mut driver); - let pkg_root = manifest_path.parent().expect("Every manifest path has a parent."); + 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);