Skip to content

Commit

Permalink
Analysis: ctypes: Guard against errors triggered by find_library(). (#…
Browse files Browse the repository at this point in the history
…5734)

On some Linux C compiler combinations:

    ctypes.util.find_library("libc.so")

Unintentionally trips a FileNotFoundError instead of simply returning
None.

Fixes #5734.
  • Loading branch information
bwoodsend committed Apr 15, 2021
1 parent 745f03c commit 577e755
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion PyInstaller/depend/utils.py
Expand Up @@ -306,7 +306,13 @@ def _restorePaths(old):
# local paths to library search paths, then replaces original values.
old = _setPaths()
for cbin in cbinaries:
cpath = find_library(os.path.splitext(cbin)[0])
try:
# There is an issue with find_library() where it can run into
# errors trying to locate the library. See #5734.
cpath = find_library(os.path.splitext(cbin)[0])
except FileNotFoundError:
# In these cases, find_library() should return None.
cpath = None
if is_unix:
# CAVEAT: find_library() is not the correct function. Ctype's
# documentation says that it is meant to resolve only the filename
Expand Down
2 changes: 2 additions & 0 deletions news/5734.bugfix.rst
@@ -0,0 +1,2 @@
Fix a build error triggered by scanning ``ctypes.CDLL('libc.so')`` on certain
Linux C compiler combinations.
10 changes: 10 additions & 0 deletions tests/functional/test_regression.py
Expand Up @@ -92,3 +92,13 @@ def test_issue_4141(pyi_builder): #script_dir,
pyi_builder.test_script('pyi_issue_4141.py',
app_name="main", run_from_path=True,
pyi_args=['--path', str(extra_path)])


def test_5734():
"""
In a regression this will raise a:
FileNotFoundError: [Errno 2] No such file or directory: b'liblibc.a'
on some Linux/gcc combinations.
"""
from PyInstaller.depend.utils import _resolveCtypesImports
_resolveCtypesImports(["libc"])

0 comments on commit 577e755

Please sign in to comment.