From 19d6a0785168e625f96ce589a5982a325032afb2 Mon Sep 17 00:00:00 2001 From: daimond113 Date: Sun, 9 Mar 2025 01:33:41 +0100 Subject: [PATCH] fix: make bin linkers for non-direct dependencies Previously, binary linkers weren't made for non-direct dependencies despite this being the documented & expected behaviour. --- CHANGELOG.md | 1 + src/cli/install.rs | 40 ++++++++++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7d8627..b504095 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Fixed - Fix path dependencies using project's workspace dependencies by @daimond113 +- Fix binary linkers not being created for non-direct dependencies by @daimond113 ### Changed - Binary linkers are now done in Rust to simplify their implementation and cross-runtime portability by @daimond113 diff --git a/src/cli/install.rs b/src/cli/install.rs index 1c34854..9d3be39 100644 --- a/src/cli/install.rs +++ b/src/cli/install.rs @@ -25,8 +25,9 @@ use pesde::{ version_matches, Project, RefreshedSources, MANIFEST_FILE_NAME, }; use std::{ - collections::{BTreeMap, BTreeSet, HashMap}, + collections::{BTreeMap, BTreeSet, HashMap, HashSet}, num::NonZeroUsize, + path::Path, sync::Arc, time::Instant, }; @@ -47,21 +48,32 @@ impl DownloadAndLinkHooks for InstallHooks { &self, graph: &DependencyGraphWithTarget, ) -> Result<(), Self::Error> { - let mut tasks = graph - .values() - .filter(|node| node.target.bin_path().is_some()) - .filter_map(|node| node.node.direct.as_ref()) - .map(|(alias, _, _)| { - let bin_folder = self.bin_folder.clone(); - let alias = alias.clone(); + let binary_packages = graph + .iter() + .filter_map(|(id, node)| node.target.bin_path().is_some().then_some(id)) + .collect::>(); + + let aliases = graph + .iter() + .flat_map(|(_, node)| node.node.dependencies.iter()) + .filter_map(|(id, alias)| binary_packages.contains(id).then_some(alias)) + .collect::>(); + + let curr_exe: Arc = std::env::current_exe() + .context("failed to get current executable path")? + .as_path() + .into(); + + let mut tasks = aliases + .into_iter() + .map(|alias| { + let bin_exec_file = self + .bin_folder + .join(alias.as_str()) + .with_extension(std::env::consts::EXE_EXTENSION); + let curr_exe = curr_exe.clone(); async move { - let bin_exec_file = bin_folder - .join(alias.as_str()) - .with_extension(std::env::consts::EXE_EXTENSION); - let curr_exe = - std::env::current_exe().context("failed to get current executable path")?; - // TODO: remove this in a major release #[cfg(unix)] if fs::metadata(&bin_exec_file)