From 2033d7b362f608a6f8740a81f5ebc75ed45a1022 Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Tue, 12 Feb 2019 16:08:41 -0800 Subject: Try harder to find liberasurecode Allow the use of LD_LIBRARY_PATH when finding shared libraries; see https://bugs.python.org/issue9998 which was addressed in Python 3.6 Change-Id: I45f89152f94ca1bf9a8f097fbe69521892d285fe --- setup.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/setup.py b/setup.py index 46a336d..d205c0c 100644 --- a/setup.py +++ b/setup.py @@ -26,6 +26,8 @@ import os import platform +import re +import subprocess import sys import ctypes @@ -72,6 +74,27 @@ def _find_library(name): target_lib = p else: target_lib = os.path.join(os.path.dirname(target_lib), p) + elif not target_lib: + # See https://bugs.python.org/issue9998 + expr = r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name) + cmd = ['ld', '-t'] + libpath = os.environ.get('LD_LIBRARY_PATH') + if libpath: + for d in libpath.split(':'): + cmd.extend(['-L', d]) + cmd.extend(['-o', os.devnull, '-l%s' % name]) + try: + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True) + out, _ = p.communicate() + if hasattr(os, 'fsdecode'): + out = os.fsdecode(out) + res = re.search(expr, out) + if res: + target_lib = res.group(0) + except Exception: + pass # result will be None # return absolute path to the library if found return target_lib -- cgit v1.2.1