Skip to content

Commit

Permalink
Create Linux-Ubuntu.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkrzyskow authored Mar 2, 2024
1 parent aa27f69 commit 0369424
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions Linux-Ubuntu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import inspect
import os
import re
import subprocess
from ctypes.util import (
_findLib_gcc,
_findLib_ld,
_findSoname_ldconfig,
_get_soname,
_is_elf,
)

library_names = ("cairo-2", "cairo", "libcairo-2")
filenames = ("libcairo.so.2", "libcairo.2.dylib", "libcairo-2.dll")
found_path = ""

print(inspect.getsource(_findLib_gcc))
print("---")
print(inspect.getsource(_findLib_ld))
print("---")
print(inspect.getsource(_findSoname_ldconfig))
print("---")

libpath = os.environ.get('LD_LIBRARY_PATH')
print("LD_LIBRARY_PATH =", libpath)

for name in library_names:
expr = r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)
command = ['ld', '-t']
if libpath:
for d in libpath.split(':'):
command.extend(['-L', d])
command.extend(['-o', os.devnull, '-l%s' % name])
print("Running", " ".join(command))
try:
out, _ = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
).communicate()
result = re.findall(expr, os.fsdecode(out))
print(" Result", "\n".join(result) or "is empty")
if not result:
continue
for path in result:
if not _is_elf(path):
continue
path = os.fsdecode(path)
found_path = _get_soname(path)
filenames = (found_path, ) + filenames
break
except Exception as err:
print(" Error during ld command:", err)
if found_path:
break
else:
found_path = "not found"

print(f"The path is {found_path}")
print("List of files that FFI will try to load:")
for filename in filenames:
print("-", filename)

0 comments on commit 0369424

Please sign in to comment.