Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate dependencies for referenced shared libs #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 42 additions & 22 deletions src/wheel2deb/debian.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
DPKG_SHLIBS_RE = re.compile(r"find library (.+\.so[.\d]*) needed")

APT_FILE_RE = re.compile(r"(.*lib.+):\s(?:/usr/lib/|/lib/)")
LDD_DEP_RE = re.compile(r"\s+lib.+\s=>\s((?:/usr/lib/|/lib/)\S+)")


def platform_to_arch(platform_tag):
Expand Down Expand Up @@ -265,6 +266,7 @@ def search_shlibs_deps(self):
"""
shlibdeps = set()
missing_libs = set()
external_libs = set()
shlibdeps_file = "shlibdeps.txt"

if (self.root / shlibdeps_file).exists():
Expand All @@ -279,36 +281,30 @@ def search_shlibs_deps(self):
output, _ = shell(args, cwd=self.root)
missing_libs.update(DPKG_SHLIBS_RE.findall(output, re.MULTILINE))

for x in self.wheel.record.libs:
lib = str(self.src / x)
output = shell(["ldd", lib], cwd=self.root)[0]
external_libs.update(LDD_DEP_RE.findall(output, re.MULTILINE))

if missing_libs:
logger.info(
"dpkg-shlibdeps reported the following missing "
"shared libs dependencies: %s",
missing_libs,
)

if external_libs:
logger.info(
"found the following shared libs dependencies: %s",
external_libs,
)

if not shlibdeps:
# search packages providing those libs
for lib in missing_libs:
output, _ = shell(["apt-file", "search", lib, "-a", self.arch])
packages = set(APT_FILE_RE.findall(output))

# remove dbg packages
packages = [p for p in packages if p[-3:] != "dbg"]

if not len(packages):
logger.warning("did not find a package providing %s", lib)
else:
# we pick the package with the shortest name
packages = sorted(packages, key=len)
shlibdeps.add(packages[0])

if len(packages) > 1:
logger.warning(
"several packages providing %s: %s, picking %s, "
"edit debian/control to use another one.",
lib,
packages,
packages[0],
)
for lib in missing_libs | external_libs:
pkg = self.find_package_for_lib(lib)
if pkg:
shlibdeps.add(pkg)

with open(str(self.root / shlibdeps_file), "w") as f:
f.write("\n".join(shlibdeps))
Expand All @@ -318,6 +314,30 @@ def search_shlibs_deps(self):

self.depends = list(set(self.depends) | shlibdeps)

def find_package_for_lib(self, lib):
output, _ = shell(["apt-file", "search", lib, "-a", self.arch])
packages = set(APT_FILE_RE.findall(output))

# remove dbg packages
packages = [p for p in packages if p[-3:] != "dbg"]

if not len(packages):
logger.warning("did not find a package providing %s", lib)
return None

# we pick the package with the shortest name
packages = sorted(packages, key=len)
if len(packages) > 1:
logger.warning(
"several packages providing %s: %s, picking %s, "
"edit debian/control to use another one.",
lib,
packages,
packages[0],
)

return packages[0]

def run_install_scripts(self):

config = configparser.ConfigParser()
Expand Down