summaryrefslogtreecommitdiffstats
path: root/src/debputy/plugin/debputy/shlib_metadata_detectors.py
blob: aa28fa9fe73ff4c0a110605c548748307478abc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from typing import List

from debputy import elf_util
from debputy.elf_util import ELF_LINKING_TYPE_DYNAMIC
from debputy.plugin.api import (
    VirtualPath,
    PackageProcessingContext,
)
from debputy.plugin.api.impl import BinaryCtrlAccessorProvider

SKIPPED_DEBUG_DIRS = [
    "lib",
    "lib64",
    "usr",
    "bin",
    "sbin",
    "opt",
    "dev",
    "emul",
    ".build-id",
]

SKIP_DIRS = {f"./usr/lib/debug/{subdir}" for subdir in SKIPPED_DEBUG_DIRS}


def _walk_filter(fs_path: VirtualPath, children: List[VirtualPath]) -> bool:
    if fs_path.path in SKIP_DIRS:
        children.clear()
        return False
    return True


def detect_shlibdeps(
    fs_root: VirtualPath,
    ctrl: BinaryCtrlAccessorProvider,
    _context: PackageProcessingContext,
) -> None:
    elf_files_to_process = elf_util.find_all_elf_files(
        fs_root,
        walk_filter=_walk_filter,
        with_linking_type=ELF_LINKING_TYPE_DYNAMIC,
    )

    if not elf_files_to_process:
        return

    ctrl.dpkg_shlibdeps(elf_files_to_process)