Skip to content

Commit 6241ac1

Browse files
committed
update ctypes patch, it now does no checking for system type and just assumes android and runs our custom library lookup function
1 parent f0c7499 commit 6241ac1

File tree

1 file changed

+250
-20
lines changed

1 file changed

+250
-20
lines changed
Lines changed: 250 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,251 @@
1+
diff -ur Python-2.7.2.orig/Lib/ctypes/util.py Python-2.7.2/Lib/ctypes/util.py
12
--- Python-2.7.2.orig/Lib/ctypes/util.py 2011-06-11 16:46:24.000000000 +0100
2-
+++ Python-2.7.2/Lib/ctypes/util.py 2015-03-26 13:45:33.322172603 +0000
3-
@@ -83,7 +83,17 @@
4-
except ValueError:
5-
continue
6-
return None
7-
-
8-
+elif os.name == "posix" and sys.platform == "linux3":
9-
+ def find_library(name):
10-
+ """ hack to find librarys for kivy and android
11-
+ split the path and get the first parts which will give us
12-
+ the app path something like /data/data/org.app.foo/"""
13-
+ app_root = os.path.abspath('./').split(os.path.sep)[0:4]
14-
+ lib_search = os.path.sep.join(app_root) + os.path.sep + 'lib'
15-
+ for filename in os.listdir(lib_search):
16-
+ if filename.endswith('.so') and name in filename:
17-
+ return lib_search + os.path.sep + filename
18-
+ return None
19-
elif os.name == "posix":
20-
# Andreas Degert's find functions, using gcc, /sbin/ldconfig, objdump
21-
import re, tempfile, errno
3+
+++ Python-2.7.2/Lib/ctypes/util.py 2015-05-10 10:37:49.258720992 +0100
4+
@@ -3,237 +3,16 @@
5+
######################################################################
6+
import sys, os
7+
8+
-# find_library(name) returns the pathname of a library, or None.
9+
-if os.name == "nt":
10+
-
11+
- def _get_build_version():
12+
- """Return the version of MSVC that was used to build Python.
13+
-
14+
- For Python 2.3 and up, the version number is included in
15+
- sys.version. For earlier versions, assume the compiler is MSVC 6.
16+
- """
17+
- # This function was copied from Lib/distutils/msvccompiler.py
18+
- prefix = "MSC v."
19+
- i = sys.version.find(prefix)
20+
- if i == -1:
21+
- return 6
22+
- i = i + len(prefix)
23+
- s, rest = sys.version[i:].split(" ", 1)
24+
- majorVersion = int(s[:-2]) - 6
25+
- minorVersion = int(s[2:3]) / 10.0
26+
- # I don't think paths are affected by minor version in version 6
27+
- if majorVersion == 6:
28+
- minorVersion = 0
29+
- if majorVersion >= 6:
30+
- return majorVersion + minorVersion
31+
- # else we don't know what version of the compiler this is
32+
- return None
33+
-
34+
- def find_msvcrt():
35+
- """Return the name of the VC runtime dll"""
36+
- version = _get_build_version()
37+
- if version is None:
38+
- # better be safe than sorry
39+
- return None
40+
- if version <= 6:
41+
- clibname = 'msvcrt'
42+
- else:
43+
- clibname = 'msvcr%d' % (version * 10)
44+
-
45+
- # If python was built with in debug mode
46+
- import imp
47+
- if imp.get_suffixes()[0][0] == '_d.pyd':
48+
- clibname += 'd'
49+
- return clibname+'.dll'
50+
-
51+
- def find_library(name):
52+
- if name in ('c', 'm'):
53+
- return find_msvcrt()
54+
- # See MSDN for the REAL search order.
55+
- for directory in os.environ['PATH'].split(os.pathsep):
56+
- fname = os.path.join(directory, name)
57+
- if os.path.isfile(fname):
58+
- return fname
59+
- if fname.lower().endswith(".dll"):
60+
- continue
61+
- fname = fname + ".dll"
62+
- if os.path.isfile(fname):
63+
- return fname
64+
- return None
65+
-
66+
-if os.name == "ce":
67+
- # search path according to MSDN:
68+
- # - absolute path specified by filename
69+
- # - The .exe launch directory
70+
- # - the Windows directory
71+
- # - ROM dll files (where are they?)
72+
- # - OEM specified search path: HKLM\Loader\SystemPath
73+
- def find_library(name):
74+
- return name
75+
-
76+
-if os.name == "posix" and sys.platform == "darwin":
77+
- from ctypes.macholib.dyld import dyld_find as _dyld_find
78+
- def find_library(name):
79+
- possible = ['lib%s.dylib' % name,
80+
- '%s.dylib' % name,
81+
- '%s.framework/%s' % (name, name)]
82+
- for name in possible:
83+
- try:
84+
- return _dyld_find(name)
85+
- except ValueError:
86+
- continue
87+
- return None
88+
-
89+
-elif os.name == "posix":
90+
- # Andreas Degert's find functions, using gcc, /sbin/ldconfig, objdump
91+
- import re, tempfile, errno
92+
-
93+
- def _findLib_gcc(name):
94+
- expr = r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)
95+
- fdout, ccout = tempfile.mkstemp()
96+
- os.close(fdout)
97+
- cmd = 'if type gcc >/dev/null 2>&1; then CC=gcc; elif type cc >/dev/null 2>&1; then CC=cc;else exit 10; fi;' \
98+
- '$CC -Wl,-t -o ' + ccout + ' 2>&1 -l' + name
99+
- try:
100+
- f = os.popen(cmd)
101+
- try:
102+
- trace = f.read()
103+
- finally:
104+
- rv = f.close()
105+
- finally:
106+
- try:
107+
- os.unlink(ccout)
108+
- except OSError, e:
109+
- if e.errno != errno.ENOENT:
110+
- raise
111+
- if rv == 10:
112+
- raise OSError, 'gcc or cc command not found'
113+
- res = re.search(expr, trace)
114+
- if not res:
115+
- return None
116+
- return res.group(0)
117+
-
118+
-
119+
- if sys.platform == "sunos5":
120+
- # use /usr/ccs/bin/dump on solaris
121+
- def _get_soname(f):
122+
- if not f:
123+
- return None
124+
- cmd = "/usr/ccs/bin/dump -Lpv 2>/dev/null " + f
125+
- f = os.popen(cmd)
126+
- try:
127+
- data = f.read()
128+
- finally:
129+
- f.close()
130+
- res = re.search(r'\[.*\]\sSONAME\s+([^\s]+)', data)
131+
- if not res:
132+
- return None
133+
- return res.group(1)
134+
- else:
135+
- def _get_soname(f):
136+
- # assuming GNU binutils / ELF
137+
- if not f:
138+
- return None
139+
- cmd = 'if ! type objdump >/dev/null 2>&1; then exit 10; fi;' \
140+
- "objdump -p -j .dynamic 2>/dev/null " + f
141+
- f = os.popen(cmd)
142+
- dump = f.read()
143+
- rv = f.close()
144+
- if rv == 10:
145+
- raise OSError, 'objdump command not found'
146+
- f = os.popen(cmd)
147+
- try:
148+
- data = f.read()
149+
- finally:
150+
- f.close()
151+
- res = re.search(r'\sSONAME\s+([^\s]+)', data)
152+
- if not res:
153+
- return None
154+
- return res.group(1)
155+
-
156+
- if (sys.platform.startswith("freebsd")
157+
- or sys.platform.startswith("openbsd")
158+
- or sys.platform.startswith("dragonfly")):
159+
-
160+
- def _num_version(libname):
161+
- # "libxyz.so.MAJOR.MINOR" => [ MAJOR, MINOR ]
162+
- parts = libname.split(".")
163+
- nums = []
164+
- try:
165+
- while parts:
166+
- nums.insert(0, int(parts.pop()))
167+
- except ValueError:
168+
- pass
169+
- return nums or [ sys.maxint ]
170+
-
171+
- def find_library(name):
172+
- ename = re.escape(name)
173+
- expr = r':-l%s\.\S+ => \S*/(lib%s\.\S+)' % (ename, ename)
174+
- f = os.popen('/sbin/ldconfig -r 2>/dev/null')
175+
- try:
176+
- data = f.read()
177+
- finally:
178+
- f.close()
179+
- res = re.findall(expr, data)
180+
- if not res:
181+
- return _get_soname(_findLib_gcc(name))
182+
- res.sort(cmp= lambda x,y: cmp(_num_version(x), _num_version(y)))
183+
- return res[-1]
184+
-
185+
- else:
186+
-
187+
- def _findLib_ldconfig(name):
188+
- # XXX assuming GLIBC's ldconfig (with option -p)
189+
- expr = r'/[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)
190+
- f = os.popen('LC_ALL=C LANG=C /sbin/ldconfig -p 2>/dev/null')
191+
- try:
192+
- data = f.read()
193+
- finally:
194+
- f.close()
195+
- res = re.search(expr, data)
196+
- if not res:
197+
- # Hm, this works only for libs needed by the python executable.
198+
- cmd = 'ldd %s 2>/dev/null' % sys.executable
199+
- f = os.popen(cmd)
200+
- try:
201+
- data = f.read()
202+
- finally:
203+
- f.close()
204+
- res = re.search(expr, data)
205+
- if not res:
206+
- return None
207+
- return res.group(0)
208+
-
209+
- def _findSoname_ldconfig(name):
210+
- import struct
211+
- if struct.calcsize('l') == 4:
212+
- machine = os.uname()[4] + '-32'
213+
- else:
214+
- machine = os.uname()[4] + '-64'
215+
- mach_map = {
216+
- 'x86_64-64': 'libc6,x86-64',
217+
- 'ppc64-64': 'libc6,64bit',
218+
- 'sparc64-64': 'libc6,64bit',
219+
- 's390x-64': 'libc6,64bit',
220+
- 'ia64-64': 'libc6,IA-64',
221+
- }
222+
- abi_type = mach_map.get(machine, 'libc6')
223+
-
224+
- # XXX assuming GLIBC's ldconfig (with option -p)
225+
- expr = r'(\S+)\s+\((%s(?:, OS ABI:[^\)]*)?)\)[^/]*(/[^\(\)\s]*lib%s\.[^\(\)\s]*)' \
226+
- % (abi_type, re.escape(name))
227+
- f = os.popen('/sbin/ldconfig -p 2>/dev/null')
228+
- try:
229+
- data = f.read()
230+
- finally:
231+
- f.close()
232+
- res = re.search(expr, data)
233+
- if not res:
234+
- return None
235+
- return res.group(1)
236+
-
237+
- def find_library(name):
238+
- return _findSoname_ldconfig(name) or _get_soname(_findLib_gcc(name))
239+
+def find_library(name):
240+
+ """ hack to find librarys for kivy and android
241+
+ split the path and get the first parts which will give us
242+
+ the app path something like /data/data/org.app.foo/"""
243+
+ app_root = os.path.abspath('./').split(os.path.sep)[0:4]
244+
+ lib_search = os.path.sep.join(app_root) + os.path.sep + 'lib'
245+
+ for filename in os.listdir(lib_search):
246+
+ if filename.endswith('.so') and name in filename:
247+
+ return lib_search + os.path.sep + filename
248+
+ return None
249+
250+
################################################################
251+
# test code

0 commit comments

Comments
 (0)