From 6ad7f4d79fc757cb2d1a74d3fd82de5c248b0712 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 4 Sep 2022 10:12:49 +0200 Subject: [PATCH] Fix installation of make-depends uninstalls depends too --- src/interact/macros.rs | 19 ++++++++++++ src/internal/dependencies.rs | 57 ++++++++++++++--------------------- src/operations/aur_install.rs | 12 ++++---- 3 files changed, 47 insertions(+), 41 deletions(-) diff --git a/src/interact/macros.rs b/src/interact/macros.rs index 544f777..085ddd6 100644 --- a/src/interact/macros.rs +++ b/src/interact/macros.rs @@ -19,3 +19,22 @@ macro_rules! multi_select { $crate::interact::Interact::interact($crate::interact::AmeMultiSelect::new(format!($($arg)+)).items($items)) } } + +#[macro_export] +/// Returns a singular or plural expression depending on the given len +macro_rules! numeric { + ($len:expr, $sin:literal[$plu:literal]) => { + if $len == 1 { + format!("{} {}", $len, $sin) + } else { + format!("{} {}{}", $len, $sin, $plu) + } + }; + ($len:expr, $sin:literal or $plu:literal) => { + if $len == 1 { + format!("{} {}", $len, $sin) + } else { + format!("{} {}", $len, plu) + } + }; +} diff --git a/src/internal/dependencies.rs b/src/internal/dependencies.rs index cce6eaa..9501761 100644 --- a/src/internal/dependencies.rs +++ b/src/internal/dependencies.rs @@ -209,54 +209,41 @@ impl DependencyInformation { Ok(repo_deps) } - pub fn make_depends(&self) -> Vec<&str> { - let mut make_depends = Vec::new(); - let mut aur_depends = self - .make_depends + pub fn make_depends(&self) -> HashSet<&str> { + let depends = self.depends(); + self.make_depends .aur .iter() .map(|p| p.metadata.name.as_str()) - .collect::>(); - let mut repo_depends = self - .make_depends - .repo - .iter() - .map(String::as_str) - .collect::>(); - make_depends.append(&mut aur_depends); - make_depends.append(&mut repo_depends); + .chain(self.make_depends.repo.iter().map(String::as_str)) + .filter(|d| !depends.contains(d)) + .collect() + } - make_depends + pub fn depends(&self) -> HashSet<&str> { + self.depends + .aur + .iter() + .map(|d| d.metadata.name.as_str()) + .chain(self.depends.repo.iter().map(String::as_str)) + .collect() } pub fn all_aur_depends(&self) -> Vec<&PackageInfo> { - let mut depends = Vec::new(); - let mut aur_depends = self.make_depends.aur.iter().collect::>(); - let mut aur_make_depends = self.depends.aur.iter().collect::>(); - depends.append(&mut aur_depends); - depends.append(&mut aur_make_depends); - - depends + self.make_depends + .aur + .iter() + .chain(self.depends.aur.iter()) + .collect() } pub fn all_repo_depends(&self) -> Vec<&str> { - let mut depends = Vec::new(); - let mut repo_depends = self - .make_depends - .repo - .iter() - .map(String::as_str) - .collect::>(); - let mut repo_make_depends = self - .depends + self.make_depends .repo .iter() + .chain(self.depends.repo.iter()) .map(String::as_str) - .collect::>(); - depends.append(&mut repo_depends); - depends.append(&mut repo_make_depends); - - depends + .collect() } } diff --git a/src/operations/aur_install.rs b/src/operations/aur_install.rs index 4eb5307..828354f 100644 --- a/src/operations/aur_install.rs +++ b/src/operations/aur_install.rs @@ -23,7 +23,7 @@ use crate::internal::utils::{get_cache_dir, wrap_text}; use crate::logging::get_logger; use crate::logging::output::{print_aur_package_list, print_dependency_list}; use crate::logging::piped_stdio::StdioReader; -use crate::{cancelled, crash, multi_select, prompt, Options}; +use crate::{cancelled, crash, multi_select, numeric, prompt, Options}; #[derive(Debug)] pub struct BuildContext { @@ -186,8 +186,8 @@ pub async fn aur_install(packages: Vec, options: Options) { if !aur_dependencies.is_empty() { tracing::info!( - "Installing {} dependencies from the aur", - aur_dependencies.len() + "Installing {} from the aur", + numeric!(aur_dependencies.len(), "package"["s"]) ); let batches = create_dependency_batches(aur_dependencies); tracing::debug!("aur install batches: {batches:?}"); @@ -197,7 +197,7 @@ pub async fn aur_install(packages: Vec, options: Options) { } } - tracing::info!("Installing {} packages", contexts.len()); + tracing::info!("Installing {}", numeric!(contexts.len(), "package"["s"])); if let Err(e) = build_and_install( contexts, @@ -276,8 +276,8 @@ async fn build_and_install( } } - tracing::info!("Built {} packages", ctxs.len()); - tracing::info!("Installing packages..."); + tracing::info!("Built {}", numeric!(ctxs.len(), "package"["s"])); + tracing::info!("Installing packages"); install_packages(ctxs, install_opts).await?;