feat: add blacklisted paths to implicit dependencies processing

It has been found that in some cases additional packages have been added
as dependencies, like usr/share/applications, usr/lib/cmake, etc

This commit adds an ability to blacklist specific paths from processing
This commit is contained in:
Evgenii Alekseev 2024-08-20 16:41:24 +03:00
parent 0861548b56
commit 61a09ce705
2 changed files with 21 additions and 2 deletions

View File

@ -38,6 +38,7 @@ class PackageArchive:
helper for package archives helper for package archives
Attributes: Attributes:
BLACKLISTED_PATHS(list[Path]): (class attribute) paths blacklisted from scan
package(Package): package descriptor package(Package): package descriptor
root(Path): path to root filesystem root(Path): path to root filesystem
pacman(Pacman): alpm wrapper instance pacman(Pacman): alpm wrapper instance
@ -47,6 +48,16 @@ class PackageArchive:
package: Package package: Package
pacman: Pacman pacman: Pacman
BLACKLISTED_PATHS = [
Path("boot"),
Path("etc"),
Path("opt"),
Path("run"),
Path("usr") / "lib" / "cmake", # well-known case, cmake doesn't contain this directory
Path("usr") / "share", # share mostly contains like icons, cursors. etc
Path("var"),
]
@staticmethod @staticmethod
def dynamic_needed(binary_path: Path) -> list[str]: def dynamic_needed(binary_path: Path) -> list[str]:
""" """
@ -165,6 +176,10 @@ class PackageArchive:
if any(package.package_name in base_packages for package in packages): if any(package.package_name in base_packages for package in packages):
continue continue
# skip blacklisted paths
if any(path.is_relative_to(parent) for parent in self.BLACKLISTED_PATHS):
continue
# remove explicit dependencies # remove explicit dependencies
packages = [package for package in packages if package.is_root_package(packages, include_optional=False)] packages = [package for package in packages if package.is_root_package(packages, include_optional=False)]
# remove optional dependencies # remove optional dependencies

View File

@ -134,8 +134,10 @@ def test_refine_dependencies(package_archive_ahriman: PackageArchive, mocker: Mo
path1 = Path("usr") / "lib" / "python3.12" path1 = Path("usr") / "lib" / "python3.12"
path2 = path1 / "site-packages" path2 = path1 / "site-packages"
path3 = Path("etc") path3 = Path("base") / "path"
path4 = Path("var") / "lib" / "whatever" path4 = Path("usr") / "lib" / "whatever"
path5 = Path("usr") / "share" / "applications"
path6 = Path("etc")
package1 = FilesystemPackage(package_name="package1", depends={"package5"}, opt_depends={"package2"}) package1 = FilesystemPackage(package_name="package1", depends={"package5"}, opt_depends={"package2"})
package2 = FilesystemPackage(package_name="package2", depends={"package1"}, opt_depends=set()) package2 = FilesystemPackage(package_name="package2", depends={"package1"}, opt_depends=set())
@ -149,6 +151,8 @@ def test_refine_dependencies(package_archive_ahriman: PackageArchive, mocker: Mo
path2: [package1, package2, package3, package5], path2: [package1, package2, package3, package5],
path3: [package1, package4], path3: [package1, package4],
path4: [package1], path4: [package1],
path5: [package1],
path6: [package1],
}) == { }) == {
path1: [package6], path1: [package6],
path2: [package1, package5], path2: [package1, package5],