-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathpython-3.4.3-android-misc.patch
313 lines (293 loc) · 10.9 KB
/
python-3.4.3-android-misc.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
diff -ru Python-3.3.5/Lib/platform.py Python-3.3.5-android/Lib/platform.py
--- Python-3.3.5/Lib/platform.py 2014-03-09 09:40:13.000000000 +0100
+++ Python-3.3.5-android/Lib/platform.py 2014-08-04 22:19:36.000000000 +0200
@@ -368,6 +368,63 @@
supported_dists=supported_dists,
full_distribution_name=0)
+_android_environment_vars = (
+ 'ANDROID_ROOT', 'ANDROID_ASSETS', 'ANDROID_STORAGE', 'ANDROID_DATA',
+ 'ANDROID_PROPERTY_WORKSPACE', 'ANDROID_BOOTLOGO')
+_android_version_property = 'ro.build.version.release'
+_android_buildstr_property = 'ro.build.version.full'
+
+def android_version(version='', buildstr=''):
+ """ Attempt to get the Android version number and build string.
+
+ The function checks for the getprop binary to retrieve build info,
+ and falls back to manually reading /system/build.prop if available.
+
+ Returns a (version, buildstr) tuple which defaults to the args given
+ as parameters.
+ """
+ if not any(os.getenv(e) for e in _android_environment_vars):
+ # Probably not on Android...
+ return version, buildstr
+
+ version_obtained = False
+ buildstr_obtained = False
+
+ # Try the 'official' API tool first, since /system/build.prop might
+ # not be the only source for properties.
+ if os.access('/system/bin/getprop', os.X_OK):
+ try:
+ output = subprocess.check_output(['/system/bin/getprop',
+ _android_version_property])
+ version = output.decode('ascii').strip()
+ version_obtained = True
+ except (subprocess.CalledProcessError, UnicodeDecodeError):
+ pass
+
+ try:
+ output = subprocess.check_output(['/system/bin/getprop',
+ _android_buildstr_property])
+ buildstr = output.decode('ascii').strip()
+ buildstr_obtained = True
+ except (subprocess.CalledProcessError, UnicodeDecodeError):
+ pass
+ done = version_obtained and buildstr_obtained
+
+ # Fall back to parsing /system/build.prop manually.
+ if not done and os.path.isfile('/system/build.prop'):
+ for line in open('/system/build.prop'):
+ if '=' not in line:
+ continue
+ key, val = line.split('=')
+ key = key.strip()
+
+ if not version_obtained and key == _android_version_property:
+ version = val.strip()
+ elif not buildstr_obtained and key == _android_buildstr_property:
+ buildstr = val.strip()
+
+ return version, buildstr
+
def popen(cmd, mode='r', bufsize=-1):
""" Portable popen() interface.
diff -ru Python-3.3.5/Lib/subprocess.py Python-3.3.5-android/Lib/subprocess.py
--- Python-3.3.5/Lib/subprocess.py 2014-03-09 09:40:13.000000000 +0100
+++ Python-3.3.5-android/Lib/subprocess.py 2014-08-04 22:19:36.000000000 +0200
@@ -1343,9 +1343,18 @@
args = list(args)
if shell:
- args = ["/bin/sh", "-c"] + args
if executable:
- args[0] = executable
+ main = executable
+ elif os.path.isfile('/bin/sh'):
+ main = '/bin/sh'
+ else:
+ import platform
+ if platform.android_version()[0]:
+ main = '/system/bin/sh'
+ else:
+ raise RuntimeError('Could not find system shell')
+
+ args = [main, "-c"] + args
if executable is None:
executable = args[0]
diff -ru Python-3.3.5/Lib/test/test_subprocess.py Python-3.3.5-android/Lib/test/test_subprocess.py
--- Python-3.3.5/Lib/test/test_subprocess.py 2014-03-09 09:40:19.000000000 +0100
+++ Python-3.3.5-android/Lib/test/test_subprocess.py 2014-08-04 22:19:36.000000000 +0200
@@ -17,6 +17,7 @@
import shutil
import gc
import textwrap
+import platform
try:
import resource
@@ -1356,7 +1357,10 @@
fd, fname = mkstemp()
# reopen in text mode
with open(fd, "w", errors="surrogateescape") as fobj:
- fobj.write("#!/bin/sh\n")
+ if platform.android_version()[0]:
+ fobj.write('#!/system/bin/sh\n')
+ else:
+ fobj.write("#!/bin/sh\n")
fobj.write("exec '%s' -c 'import sys; sys.exit(47)'\n" %
sys.executable)
os.chmod(fname, 0o700)
@@ -1401,7 +1405,10 @@
fd, fname = mkstemp()
# reopen in text mode
with open(fd, "w", errors="surrogateescape") as fobj:
- fobj.write("#!/bin/sh\n")
+ if platform.android_version()[0]:
+ fobj.write('#!/system/bin/sh\n')
+ else:
+ fobj.write("#!/bin/sh\n")
fobj.write("exec '%s' -c 'import sys; sys.exit(47)'\n" %
sys.executable)
os.chmod(fname, 0o700)
diff -ru Python-3.4.2/Modules/pwdmodule.c Python-3.4.2-android/Modules/pwdmodule.c
--- Python-3.4.2/Modules/pwdmodule.c 2015-02-24 23:06:31.000000000 +0100
+++ Python-3.4.2-android/Modules/pwdmodule.c 2015-02-24 23:09:14.000000000 +0100
@@ -72,7 +72,11 @@
SETS(setIndex++, p->pw_passwd);
PyStructSequence_SET_ITEM(v, setIndex++, _PyLong_FromUid(p->pw_uid));
PyStructSequence_SET_ITEM(v, setIndex++, _PyLong_FromGid(p->pw_gid));
+#if !defined(__ANDROID__)
SETS(setIndex++, p->pw_gecos);
+#else
+ SETS(setIndex++, "");
+#endif
SETS(setIndex++, p->pw_dir);
SETS(setIndex++, p->pw_shell);
diff -ru Python-3.3.5/Modules/socketmodule.c Python-3.3.5-android/Modules/socketmodule.c
--- Python-3.3.5/Modules/socketmodule.c 2014-03-09 09:40:28.000000000 +0100
+++ Python-3.3.5-android/Modules/socketmodule.c 2014-08-04 22:19:36.000000000 +0200
@@ -150,7 +150,7 @@
On the other hand, not all Linux versions agree, so there the settings
computed by the configure script are needed! */
-#ifndef linux
+#if !defined(linux) || __ANDROID__
# undef HAVE_GETHOSTBYNAME_R_3_ARG
# undef HAVE_GETHOSTBYNAME_R_5_ARG
# undef HAVE_GETHOSTBYNAME_R_6_ARG
@@ -169,7 +169,7 @@
# define HAVE_GETHOSTBYNAME_R_3_ARG
# elif defined(__sun) || defined(__sgi)
# define HAVE_GETHOSTBYNAME_R_5_ARG
-# elif defined(linux)
+# elif defined(linux) && !__ANDROID__
/* Rely on the configure script */
# else
# undef HAVE_GETHOSTBYNAME_R
diff -ru Python-3.3.5/Modules/posixmodule.c Python-3.3.5-android/Modules/posixmodule.c
--- Python-3.3.5/Modules/posixmodule.c 2014-03-09 08:40:28.000000000 +0000
+++ Python-3.3.5-android/Modules/posixmodule.c 2015-02-24 19:57:05.368843433 +0000
@@ -403,6 +403,11 @@
#endif
#endif
+/* Android doesn't expose AT_EACCESS - manually define it. */
+#if !defined(AT_EACCESS) && defined(__ANDROID__)
+#define AT_EACCESS 0x200
+#endif
+
#ifdef MS_WINDOWS
static int
diff -ru Python-3.3.5/Python/pytime.c Python-3.3.5-android/Python/pytime.c
--- Python-3.3.5/Python/pytime.c 2015-02-23 11:54:25.000000000 -0500
+++ Python-3.3.5-android/Python/pytime.c 2015-02-23 11:55:19.000000000 -0500
@@ -3,7 +3,7 @@
#include <windows.h>
#endif
-#if defined(__APPLE__) && defined(HAVE_GETTIMEOFDAY) && defined(HAVE_FTIME)
+#if (defined(__APPLE__) || defined(__ANDROID__)) && defined(HAVE_GETTIMEOFDAY) && defined(HAVE_FTIME)
/*
* _PyTime_gettimeofday falls back to ftime when getttimeofday fails because the latter
* might fail on some platforms. This fallback is unwanted on MacOSX because
diff -ru Python-3.4.2/configure Python-3.4.2-android/configure
--- Python-3.4.2/configure 2015-02-24 23:18:31.000000000 +0100
+++ Python-3.4.2-android/configure 2015-03-01 20:15:02.000000000 +0100
@@ -5406,6 +5406,34 @@
MULTIARCH=$($CC --print-multiarch 2>/dev/null)
+# Test if we're running on Android.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if target is Android-based" >&5
+$as_echo_n "checking if target is Android-based... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+#if __ANDROID__
+yes
+#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ $EGREP "yes" >/dev/null 2>&1; then :
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+ with_android=yes
+
+else
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+ with_android=no
+
+
+fi
+rm -f conftest*
+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking LIBRARY" >&5
@@ -5650,7 +5678,14 @@
SOVERSION=`echo $SOVERSION|cut -d "." -f 1`
;;
esac
- INSTSONAME="$LDLIBRARY".$SOVERSION
+
+ if test "$with_android" != yes
+ then
+ INSTSONAME="$LDLIBRARY".$SOVERSION
+ else
+ INSTSONAME="$LDLIBRARY"
+ fi
+
if test "$with_pydebug" != yes
then
PY3LIBRARY=libpython3.so
diff -ru Python-3.4.2/configure.ac Python-3.4.2-android/configure.ac
--- Python-3.4.2/configure.ac 2015-02-24 23:18:31.000000000 +0100
+++ Python-3.4.2-android/configure.ac 2015-03-01 20:14:54.000000000 +0100
@@ -796,6 +796,21 @@
MULTIARCH=$($CC --print-multiarch 2>/dev/null)
AC_SUBST(MULTIARCH)
+# Test if we're running on Android.
+AC_MSG_CHECKING(if target is Android-based)
+AC_EGREP_CPP(yes,
+[
+#if __ANDROID__
+yes
+#endif
+], [
+ AC_MSG_RESULT(yes)
+ with_android=yes
+ ], [
+ AC_MSG_RESULT(no)
+ with_android=no
+ ]
+)
AC_SUBST(LIBRARY)
AC_MSG_CHECKING(LIBRARY)
@@ -970,7 +985,14 @@
SOVERSION=`echo $SOVERSION|cut -d "." -f 1`
;;
esac
- INSTSONAME="$LDLIBRARY".$SOVERSION
+
+ if test "$with_android" != yes
+ then
+ INSTSONAME="$LDLIBRARY".$SOVERSION
+ else
+ INSTSONAME="$LDLIBRARY"
+ fi
+
if test "$with_pydebug" != yes
then
PY3LIBRARY=libpython3.so
diff -ru Python-3.4.2/Makefile.pre.in Python-3.4.2-android/Makefile.pre.in
--- Python-3.4.2/Makefile.pre.in 2015-03-04 16:25:36.000000000 +0100
+++ Python-3.4.2-android/Makefile.pre.in 2015-03-04 16:27:27.000000000 +0100
@@ -568,7 +568,7 @@
*\ -s*|s*) quiet="-q";; \
*) quiet="";; \
esac; \
- $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \
+ $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED) -lpython$(LDVERSION)' OPT='$(OPT)' \
_TCLTK_INCLUDES='$(TCLTK_INCLUDES)' _TCLTK_LIBS='$(TCLTK_LIBS)' \
$(PYTHON_FOR_BUILD) $(srcdir)/setup.py $$quiet build
diff -Nru Python-3.4.2/Makefile.pre.in Python-3.4.2-android/Makefile.pre.in
--- Python-3.4.2/Makefile.pre.in 2015-06-27 17:04:23.885777456 +0000
+++ Python-3.4.2-android/Makefile.pre.in 2015-06-27 17:05:27.709777315 +0000
@@ -585,11 +585,9 @@
$(RANLIB) $@
libpython$(LDVERSION).so: $(LIBRARY_OBJS)
+ $(BLDSHARED) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
if test $(INSTSONAME) != $(LDLIBRARY); then \
- $(BLDSHARED) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
$(LN) -f $(INSTSONAME) $@; \
- else \
- $(BLDSHARED) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
fi
libpython3.so: libpython$(LDVERSION).so