Fix installation of make-depends uninstalls depends too

i18n
trivernis 2 years ago
parent 03ed424910
commit 6ad7f4d79f
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -19,3 +19,22 @@ macro_rules! multi_select {
$crate::interact::Interact::interact($crate::interact::AmeMultiSelect::new(format!($($arg)+)).items($items)) $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)
}
};
}

@ -209,54 +209,41 @@ impl DependencyInformation {
Ok(repo_deps) Ok(repo_deps)
} }
pub fn make_depends(&self) -> Vec<&str> { pub fn make_depends(&self) -> HashSet<&str> {
let mut make_depends = Vec::new(); let depends = self.depends();
let mut aur_depends = self self.make_depends
.make_depends
.aur .aur
.iter() .iter()
.map(|p| p.metadata.name.as_str()) .map(|p| p.metadata.name.as_str())
.collect::<Vec<_>>(); .chain(self.make_depends.repo.iter().map(String::as_str))
let mut repo_depends = self .filter(|d| !depends.contains(d))
.make_depends .collect()
.repo }
.iter()
.map(String::as_str)
.collect::<Vec<_>>();
make_depends.append(&mut aur_depends);
make_depends.append(&mut repo_depends);
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> { pub fn all_aur_depends(&self) -> Vec<&PackageInfo> {
let mut depends = Vec::new(); self.make_depends
let mut aur_depends = self.make_depends.aur.iter().collect::<Vec<_>>(); .aur
let mut aur_make_depends = self.depends.aur.iter().collect::<Vec<_>>(); .iter()
depends.append(&mut aur_depends); .chain(self.depends.aur.iter())
depends.append(&mut aur_make_depends); .collect()
depends
} }
pub fn all_repo_depends(&self) -> Vec<&str> { pub fn all_repo_depends(&self) -> Vec<&str> {
let mut depends = Vec::new(); self.make_depends
let mut repo_depends = self
.make_depends
.repo
.iter()
.map(String::as_str)
.collect::<Vec<_>>();
let mut repo_make_depends = self
.depends
.repo .repo
.iter() .iter()
.chain(self.depends.repo.iter())
.map(String::as_str) .map(String::as_str)
.collect::<Vec<_>>(); .collect()
depends.append(&mut repo_depends);
depends.append(&mut repo_make_depends);
depends
} }
} }

@ -23,7 +23,7 @@ use crate::internal::utils::{get_cache_dir, wrap_text};
use crate::logging::get_logger; use crate::logging::get_logger;
use crate::logging::output::{print_aur_package_list, print_dependency_list}; use crate::logging::output::{print_aur_package_list, print_dependency_list};
use crate::logging::piped_stdio::StdioReader; 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)] #[derive(Debug)]
pub struct BuildContext { pub struct BuildContext {
@ -186,8 +186,8 @@ pub async fn aur_install(packages: Vec<String>, options: Options) {
if !aur_dependencies.is_empty() { if !aur_dependencies.is_empty() {
tracing::info!( tracing::info!(
"Installing {} dependencies from the aur", "Installing {} from the aur",
aur_dependencies.len() numeric!(aur_dependencies.len(), "package"["s"])
); );
let batches = create_dependency_batches(aur_dependencies); let batches = create_dependency_batches(aur_dependencies);
tracing::debug!("aur install batches: {batches:?}"); tracing::debug!("aur install batches: {batches:?}");
@ -197,7 +197,7 @@ pub async fn aur_install(packages: Vec<String>, options: Options) {
} }
} }
tracing::info!("Installing {} packages", contexts.len()); tracing::info!("Installing {}", numeric!(contexts.len(), "package"["s"]));
if let Err(e) = build_and_install( if let Err(e) = build_and_install(
contexts, contexts,
@ -276,8 +276,8 @@ async fn build_and_install(
} }
} }
tracing::info!("Built {} packages", ctxs.len()); tracing::info!("Built {}", numeric!(ctxs.len(), "package"["s"]));
tracing::info!("Installing packages..."); tracing::info!("Installing packages");
install_packages(ctxs, install_opts).await?; install_packages(ctxs, install_opts).await?;

Loading…
Cancel
Save