From 27d37198c7876cb4d91d305414200c61e5677ac9 Mon Sep 17 00:00:00 2001 From: Gabriele Musco Date: Sat, 10 May 2025 10:35:19 +0200 Subject: [PATCH] fix: refactor and optimize missing dependency filtering --- src/depcheck/basalt_deps.rs | 8 ++------ src/depcheck/libsurvive_deps.rs | 8 ++------ src/depcheck/mercury_deps.rs | 10 ++++------ src/depcheck/mod.rs | 18 ++++++++++++++++++ src/depcheck/monado_deps.rs | 8 ++------ src/depcheck/openhmd_deps.rs | 8 ++------ src/depcheck/wivrn_deps.rs | 8 ++------ src/depcheck/xrizer_deps.rs | 8 ++------ 8 files changed, 34 insertions(+), 42 deletions(-) diff --git a/src/depcheck/basalt_deps.rs b/src/depcheck/basalt_deps.rs index 2a05826..00a29b6 100644 --- a/src/depcheck/basalt_deps.rs +++ b/src/depcheck/basalt_deps.rs @@ -1,7 +1,7 @@ use super::{ boost_deps::boost_deps, common::{dep_cmake, dep_eigen, dep_gpp, dep_libgl, dep_ninja, dep_opencv}, - DepType, Dependency, DependencyCheckResult, + DepType, DepcheckResultGetMissing, Dependency, DependencyCheckResult, }; use crate::linux_distro::LinuxDistro; use std::collections::HashMap; @@ -181,9 +181,5 @@ pub fn check_basalt_deps() -> Vec { } pub fn get_missing_basalt_deps() -> Vec { - check_basalt_deps() - .iter() - .filter(|res| !res.found) - .map(|res| res.dependency.clone()) - .collect() + check_basalt_deps().filter_missing_deps() } diff --git a/src/depcheck/libsurvive_deps.rs b/src/depcheck/libsurvive_deps.rs index c9e8d9c..46eec55 100644 --- a/src/depcheck/libsurvive_deps.rs +++ b/src/depcheck/libsurvive_deps.rs @@ -1,6 +1,6 @@ use super::{ common::{dep_cmake, dep_eigen, dep_gcc, dep_git, dep_gpp, dep_ninja}, - Dependency, DependencyCheckResult, + DepcheckResultGetMissing, Dependency, DependencyCheckResult, }; fn libsurvive_deps() -> Vec { @@ -19,9 +19,5 @@ pub fn check_libsurvive_deps() -> Vec { } pub fn get_missing_libsurvive_deps() -> Vec { - check_libsurvive_deps() - .iter() - .filter(|res| !res.found) - .map(|res| res.dependency.clone()) - .collect() + check_libsurvive_deps().filter_missing_deps() } diff --git a/src/depcheck/mercury_deps.rs b/src/depcheck/mercury_deps.rs index cad3c80..a7e59be 100644 --- a/src/depcheck/mercury_deps.rs +++ b/src/depcheck/mercury_deps.rs @@ -1,4 +1,6 @@ -use super::{common::dep_opencv, DepType, Dependency, DependencyCheckResult}; +use super::{ + common::dep_opencv, DepType, DepcheckResultGetMissing, Dependency, DependencyCheckResult, +}; use crate::linux_distro::LinuxDistro; use std::collections::HashMap; @@ -39,9 +41,5 @@ pub fn check_mercury_deps() -> Vec { } pub fn get_missing_mercury_deps() -> Vec { - check_mercury_deps() - .iter() - .filter(|res| !res.found) - .map(|res| res.dependency.clone()) - .collect() + check_mercury_deps().filter_missing_deps() } diff --git a/src/depcheck/mod.rs b/src/depcheck/mod.rs index e46b1e7..92154bb 100644 --- a/src/depcheck/mod.rs +++ b/src/depcheck/mod.rs @@ -109,6 +109,24 @@ impl Display for DependencyCheckResult { } } +pub trait DepcheckResultGetMissing { + fn filter_missing_deps(self) -> Vec; +} + +impl DepcheckResultGetMissing for Vec { + fn filter_missing_deps(self) -> Vec { + self.into_iter() + .filter_map(|res| { + if !res.found { + Some(res.dependency) + } else { + None + } + }) + .collect() + } +} + fn shared_obj_paths() -> Vec { vec![ "/lib".into(), diff --git a/src/depcheck/monado_deps.rs b/src/depcheck/monado_deps.rs index b4894da..e1cd9f9 100644 --- a/src/depcheck/monado_deps.rs +++ b/src/depcheck/monado_deps.rs @@ -4,7 +4,7 @@ use super::{ dep_libgl, dep_libudev, dep_libx11, dep_libxcb, dep_ninja, dep_openxr, dep_vulkan_headers, dep_vulkan_icd_loader, }, - DepType, Dependency, DependencyCheckResult, + DepType, DepcheckResultGetMissing, Dependency, DependencyCheckResult, }; use crate::{depcheck::common::dep_libxrandr, linux_distro::LinuxDistro}; use std::collections::HashMap; @@ -131,9 +131,5 @@ pub fn check_monado_deps() -> Vec { } pub fn get_missing_monado_deps() -> Vec { - check_monado_deps() - .iter() - .filter(|res| !res.found) - .map(|res| res.dependency.clone()) - .collect() + check_monado_deps().filter_missing_deps() } diff --git a/src/depcheck/openhmd_deps.rs b/src/depcheck/openhmd_deps.rs index 819324f..d31d013 100644 --- a/src/depcheck/openhmd_deps.rs +++ b/src/depcheck/openhmd_deps.rs @@ -1,6 +1,6 @@ use super::{ common::{dep_gcc, dep_git, dep_gpp, dep_ninja}, - Dependency, DependencyCheckResult, + DepcheckResultGetMissing, Dependency, DependencyCheckResult, }; use crate::linux_distro::LinuxDistro; use std::collections::HashMap; @@ -31,9 +31,5 @@ pub fn check_openhmd_deps() -> Vec { } pub fn get_missing_openhmd_deps() -> Vec { - check_openhmd_deps() - .iter() - .filter(|res| !res.found) - .map(|res| res.dependency.clone()) - .collect() + check_openhmd_deps().filter_missing_deps() } diff --git a/src/depcheck/wivrn_deps.rs b/src/depcheck/wivrn_deps.rs index acf9a35..9126272 100644 --- a/src/depcheck/wivrn_deps.rs +++ b/src/depcheck/wivrn_deps.rs @@ -4,7 +4,7 @@ use super::{ dep_libudev, dep_libx11, dep_libxcb, dep_ninja, dep_openxr, dep_vulkan_headers, dep_vulkan_icd_loader, }, - DepType, Dependency, DependencyCheckResult, + DepType, DepcheckResultGetMissing, Dependency, DependencyCheckResult, }; use crate::{ depcheck::common::{dep_libgl, dep_libxrandr}, @@ -270,9 +270,5 @@ pub fn check_wivrn_deps() -> Vec { } pub fn get_missing_wivrn_deps() -> Vec { - check_wivrn_deps() - .iter() - .filter(|res| !res.found) - .map(|res| res.dependency.clone()) - .collect() + check_wivrn_deps().filter_missing_deps() } diff --git a/src/depcheck/xrizer_deps.rs b/src/depcheck/xrizer_deps.rs index ec48b4b..83134c1 100644 --- a/src/depcheck/xrizer_deps.rs +++ b/src/depcheck/xrizer_deps.rs @@ -1,4 +1,4 @@ -use super::{DepType, Dependency, DependencyCheckResult}; +use super::{DepType, DepcheckResultGetMissing, Dependency, DependencyCheckResult}; use crate::linux_distro::LinuxDistro; use std::collections::HashMap; @@ -49,9 +49,5 @@ pub fn check_xrizer_deps() -> Vec { } pub fn get_missing_xrizer_deps() -> Vec { - check_xrizer_deps() - .iter() - .filter(|res| !res.found) - .map(|res| res.dependency.clone()) - .collect() + check_xrizer_deps().filter_missing_deps() }