at 23.05-pre 1.9 kB view raw
1From 918201682127ed8a270a4bd1a448b490019e4ada Mon Sep 17 00:00:00 2001 2From: Frederik Rietdijk <fridh@fridh.nl> 3Date: Thu, 14 Sep 2017 10:00:31 +0200 4Subject: [PATCH] ctypes.util: support LD_LIBRARY_PATH 5 6Backports support for LD_LIBRARY_PATH from 3.6 7--- 8 Lib/ctypes/util.py | 26 +++++++++++++++++++++++++- 9 1 file changed, 25 insertions(+), 1 deletion(-) 10 11diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py 12index e9957d7951..9926f6c881 100644 13--- a/Lib/ctypes/util.py 14+++ b/Lib/ctypes/util.py 15@@ -219,8 +219,32 @@ elif os.name == "posix": 16 def _findSoname_ldconfig(name): 17 return None 18 19+ def _findLib_ld(name): 20+ # See issue #9998 for why this is needed 21+ expr = r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name) 22+ cmd = ['ld', '-t'] 23+ libpath = os.environ.get('LD_LIBRARY_PATH') 24+ if libpath: 25+ for d in libpath.split(':'): 26+ cmd.extend(['-L', d]) 27+ cmd.extend(['-o', os.devnull, '-l%s' % name]) 28+ result = None 29+ try: 30+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE, 31+ stderr=subprocess.PIPE, 32+ universal_newlines=True) 33+ out, _ = p.communicate() 34+ res = re.search(expr, os.fsdecode(out)) 35+ if res: 36+ result = res.group(0) 37+ except Exception as e: 38+ pass # result will be None 39+ return result 40+ 41 def find_library(name): 42- return _findSoname_ldconfig(name) or _get_soname(_findLib_gcc(name)) 43+ # See issue #9998 44+ return _findSoname_ldconfig(name) or \ 45+ _get_soname(_findLib_gcc(name) or _findLib_ld(name)) 46 47 ################################################################ 48 # test code 49-- 502.14.1 51