8
8
9
9
import lddwrap
10
10
11
+
12
+ class LibcNotFoundError (Exception ):
13
+ pass
14
+
15
+
11
16
LIBC_PATH_POSSIBILITIES = [
12
17
"/lib/libc.so.6" ,
13
18
"/lib/libc.so.7" ,
@@ -26,19 +31,21 @@ def find_libc():
26
31
libc_path = None
27
32
try :
28
33
libc_path = find_library_full ("c" )
29
- except FileNotFoundError :
34
+ except ( FileNotFoundError , AttributeError , RuntimeError ) :
30
35
# ldconfig is not accessible as user
36
+ # or running on Windows
37
+ # or other errors
31
38
try :
32
39
libc_path = find_libc_ldd ()
33
40
except FileNotFoundError :
34
41
# test hardcoded paths
35
42
logging .debug ("Finding libc path: hardcoded paths" )
36
43
for maybe_libc in LIBC_PATH_POSSIBILITIES :
37
- if Path (maybe_libc ).exists ():
44
+ if Path (maybe_libc ).resolve (). exists ():
38
45
libc_path = maybe_libc
39
46
break
40
47
if libc_path is None :
41
- raise RuntimeError ("Cannot find a suitable libc path on your system" )
48
+ raise LibcNotFoundError ("Cannot find a suitable libc path on your system" )
42
49
logging .debug ("Found libc: %s" , libc_path )
43
50
return libc_path
44
51
@@ -64,9 +71,14 @@ def find_libc_ldd():
64
71
65
72
66
73
def find_library_full (name ):
67
- """https://stackoverflow.com/a/29227195/3017219"""
74
+ """https://stackoverflow.com/a/29227195/3017219
75
+
76
+ :raise:
77
+ AttributeError: if an attribute is not found on OS module
78
+ RuntimeError"""
68
79
logging .debug ("Finding libc path: ldconfig" )
69
80
# see ctypes.find_library code
81
+ # Note: os.uname is OS dependant, will raise AttributeError
70
82
uname = os .uname ()[4 ]
71
83
if uname .startswith ("arm" ):
72
84
uname = "arm"
0 commit comments