Skip to content

Commit e13c497

Browse files
committedSep 15, 2017
Merge pull request #29357 from FRidh/ld_library_path
Python 3.4 and 3.5: support LD_LIBRARY_PATH (cherry picked from commit fdbe81b)
1 parent 631b96a commit e13c497

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-0
lines changed
 

Diff for: ‎pkgs/development/interpreters/python/cpython/3.4/default.nix

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ in stdenv.mkDerivation {
6666

6767
patches = [
6868
./no-ldconfig.patch
69+
./ld_library_path.patch
6970
];
7071

7172
postPatch = ''
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
From 85991e0d7f0e631240f3f6233bd65d1128a66dec Mon Sep 17 00:00:00 2001
2+
From: Frederik Rietdijk <fridh@fridh.nl>
3+
Date: Thu, 14 Sep 2017 10:00:31 +0200
4+
Subject: [PATCH] ctypes.util: support LD_LIBRARY_PATH
5+
6+
Backports support for LD_LIBRARY_PATH from 3.6
7+
---
8+
Lib/ctypes/util.py | 26 +++++++++++++++++++++++++-
9+
1 file changed, 25 insertions(+), 1 deletion(-)
10+
11+
diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
12+
index 780cd5d21b..d7ac15070f 100644
13+
--- a/Lib/ctypes/util.py
14+
+++ b/Lib/ctypes/util.py
15+
@@ -181,8 +181,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+
--
50+
2.14.1
51+

Diff for: ‎pkgs/development/interpreters/python/cpython/3.5/default.nix

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ in stdenv.mkDerivation {
6666

6767
patches = [
6868
./no-ldconfig.patch
69+
./ld_library_path.patch
6970
];
7071

7172
postPatch = ''
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
From 918201682127ed8a270a4bd1a448b490019e4ada Mon Sep 17 00:00:00 2001
2+
From: Frederik Rietdijk <fridh@fridh.nl>
3+
Date: Thu, 14 Sep 2017 10:00:31 +0200
4+
Subject: [PATCH] ctypes.util: support LD_LIBRARY_PATH
5+
6+
Backports support for LD_LIBRARY_PATH from 3.6
7+
---
8+
Lib/ctypes/util.py | 26 +++++++++++++++++++++++++-
9+
1 file changed, 25 insertions(+), 1 deletion(-)
10+
11+
diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
12+
index 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+
--
50+
2.14.1
51+

0 commit comments

Comments
 (0)
Please sign in to comment.