python: sync musl find_library fix (via Alpine)

This commit is contained in:
Alessio Sergi 2016-11-17 16:46:46 +01:00
parent d757e81847
commit 93305fd847
2 changed files with 17 additions and 16 deletions

View file

@ -1,11 +1,12 @@
http://bugs.alpinelinux.org/issues/5038
--- Lib/ctypes/util.py
--- Lib/ctypes/util.py.orig
+++ Lib/ctypes/util.py
@@ -238,8 +238,37 @@ elif os.name == "posix":
return None
return res.group(1)
@@ -204,6 +204,41 @@
def find_library(name, is64 = False):
return _get_soname(_findLib_crle(name, is64) or _findLib_gcc(name))
+ elif True:
+
+ # Patched for Alpine Linux / musl - search manually system paths
+ def _is_elf(filepath):
+ try:
+ with open(filepath, 'rb') as fh:
@ -13,15 +14,18 @@ http://bugs.alpinelinux.org/issues/5038
+ except:
+ return False
+
+ def _find_libfile(name):
+ def find_library(name):
+ from glob import glob
+ # absolute name?
+ if os.path.isabs(name):
+ return name
+ # special case for libm, libcrypt and libpthread and musl
+ if name in ['m', 'crypt', 'pthread']:
+ name = 'c'
+ elif name in ['libm.so', 'libcrypt.so', 'libpthread.so']:
+ name = 'libc.so'
+ # search in standard locations
+ paths = ['/lib', '/usr/lib', '/usr/local/lib']
+ # search in standard locations (musl order)
+ paths = ['/lib', '/usr/local/lib', '/usr/lib']
+ if 'LD_LIBRARY_PATH' in os.environ:
+ paths = os.environ['LD_LIBRARY_PATH'].split(':') + paths
+ for d in paths:
@ -30,14 +34,11 @@ http://bugs.alpinelinux.org/issues/5038
+ return os.path.basename(f)
+
+ prefix = os.path.join(d, 'lib'+name)
+ for suffix in ['.so', '.so.*', '.*.so.*']:
+ for suffix in ['.so', '.so.*']:
+ for f in glob('{0}{1}'.format(prefix, suffix)):
+ if _is_elf(f):
+ return os.path.basename(f)
+
def find_library(name):
- return _findSoname_ldconfig(name) or _get_soname(_findLib_gcc(name))
+ return _find_libfile(name) or _findSoname_ldconfig(name) or _get_soname(_findLib_gcc(name))
else:
################################################################
# test code
def _findSoname_ldconfig(name):

View file

@ -4,7 +4,7 @@
#
pkgname=python
version=2.7.12
revision=2
revision=3
wrksrc="Python-${version}"
hostmakedepends="pkg-config"
makedepends="