Skip to content

Commit 3aa79e5

Browse files
author
agilewalker
committed
Python 3.6 support.
1 parent f609ff3 commit 3aa79e5

File tree

2 files changed

+122
-9
lines changed

2 files changed

+122
-9
lines changed

pythonforandroid/recipes/python3crystax/__init__.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030
#error "Unsupported ABI"
3131
#endif
3232
"""
33-
33+
LATEST_FULL_VERSION = {
34+
'3.5': '3.5.4',
35+
'3.6': '3.6.4'
36+
}
3437

3538
def realpath(fname):
3639
"""
@@ -58,8 +61,7 @@ def realpath(fname):
5861

5962
class Python3Recipe(TargetPythonRecipe):
6063
version = '3.5'
61-
url = ('https://github.com/crystax/android-vendor-python-{}-{}'
62-
'/archive/master.tar.gz'.format(*version.split('.')))
64+
url = None
6365
name = 'python3crystax'
6466

6567
depends = ['hostpython3crystax']
@@ -69,6 +71,8 @@ class Python3Recipe(TargetPythonRecipe):
6971

7072
def download_if_necessary(self):
7173
if 'openssl' in self.ctx.recipe_build_order:
74+
full_version = LATEST_FULL_VERSION[self.version]
75+
Python3Recipe.url = 'https://www.python.org/ftp/python/{0}.{1}.{2}/Python-{0}.{1}.{2}.tgz'.format(*full_version.split('.'))
7276
super(Python3Recipe, self).download_if_necessary()
7377

7478
def get_dir_name(self):
@@ -153,6 +157,26 @@ def find_Android_mk(self):
153157
if os.path.exists(mk_path):
154158
return mk_path
155159

160+
def prebuild_arch(self, arch):
161+
super(Python3Recipe, self).prebuild_arch(arch)
162+
if self.version == '3.6':
163+
Python3Recipe.patches = ['patch_python3.6.patch']
164+
build_dir = self.get_build_dir(arch.arch)
165+
shprint(sh.ln, '-sf',
166+
realpath(join(build_dir, 'Lib/site-packages/README.txt')),
167+
join(build_dir, 'Lib/site-packages/README'))
168+
python_build_files = ['android.mk', 'config.c', 'interpreter.c']
169+
ndk_build_tools_python_dir = join(self.ctx.ndk_dir, 'build', 'tools', 'build-target-python')
170+
for python_build_file in python_build_files:
171+
shprint(sh.cp, join(ndk_build_tools_python_dir, python_build_file+'.3.5'),
172+
join(ndk_build_tools_python_dir, python_build_file+'.3.6'))
173+
ndk_sources_python_dir = join(self.ctx.ndk_dir, 'sources', 'python')
174+
if not os.path.exists(join(ndk_sources_python_dir, '3.6')):
175+
os.mkdir(join(ndk_sources_python_dir, '3.6'))
176+
sh.sed('s#3.5#3.6#',
177+
join(ndk_sources_python_dir, '3.5/Android.mk'),
178+
_out=join(ndk_sources_python_dir, '3.6/Android.mk'))
179+
156180
def build_arch(self, arch):
157181
# If openssl is needed we may have to recompile cPython to get the
158182
# ssl.py module working properly
@@ -203,12 +227,12 @@ def build_arch(self, arch):
203227
info('Copying openssl libs to ndk')
204228
arch_ndk_lib = join(openssl_ndk_dir, 'libs', arch.arch)
205229
ensure_dir(arch_ndk_lib)
206-
shprint(sh.cp,
207-
join(openssl_build_dir, 'libcrypto{}.so'.format(ssl_recipe.version)),
208-
join(openssl_build_dir, 'libcrypto.so'))
209-
shprint(sh.cp,
210-
join(openssl_build_dir, 'libssl{}.so'.format(ssl_recipe.version)),
211-
join(openssl_build_dir, 'libssl.so'))
230+
shprint(sh.ln, '-sf',
231+
realpath(join(openssl_build_dir, 'libcrypto{}.so'.format(ssl_recipe.version))),
232+
join(openssl_build_dir, 'libcrypto.so'))
233+
shprint(sh.ln, '-sf',
234+
realpath(join(openssl_build_dir, 'libssl{}.so'.format(ssl_recipe.version))),
235+
join(openssl_build_dir, 'libssl.so'))
212236
libs = ['libcrypto.a', 'libcrypto.so', 'libssl.a', 'libssl.so']
213237
cmd = [join(openssl_build_dir, lib) for lib in libs] + [arch_ndk_lib]
214238
shprint(sh.cp, '-f', *cmd)
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
diff --git a/Modules/expat/xmlparse.c b/Modules/expat/xmlparse.c
2+
--- a/Modules/expat/xmlparse.c 2017-12-19 12:53:56.000000000 +0800
3+
+++ b/Modules/expat/xmlparse.c 2017-12-21 17:32:08.624143428 +0800
4+
@@ -84,6 +84,8 @@
5+
# define LOAD_LIBRARY_SEARCH_SYSTEM32 0x00000800
6+
#endif
7+
8+
+#define XML_POOR_ENTROPY 1
9+
+
10+
#if !defined(HAVE_GETRANDOM) && !defined(HAVE_SYSCALL_GETRANDOM) \
11+
&& !defined(HAVE_ARC4RANDOM_BUF) && !defined(HAVE_ARC4RANDOM) \
12+
&& !defined(XML_DEV_URANDOM) \
13+
diff --git a/Modules/getpath.c b/Modules/getpath.c
14+
--- a/Modules/getpath.c
15+
+++ b/Modules/getpath.c
16+
@@ -101,8 +101,35 @@
17+
#endif
18+
19+
20+
-#if !defined(PREFIX) || !defined(EXEC_PREFIX) || !defined(VERSION) || !defined(VPATH)
21+
-#error "PREFIX, EXEC_PREFIX, VERSION, and VPATH must be constant defined"
22+
+ /* These variables were set this way in old versions of Python, but
23+
+ changed somewhere between 3.5.0 and 3.5.3. Here we just force
24+
+ the old way again. A better solution would be to work out where
25+
+ they should be defined, and make the CrystaX build scripts do
26+
+ so. */
27+
+
28+
+/* #if !defined(PREFIX) || !defined(EXEC_PREFIX) || !defined(VERSION) || !defined(VPATH) */
29+
+/* #error "PREFIX, EXEC_PREFIX, VERSION, and VPATH must be constant defined" */
30+
+/* #endif */
31+
+
32+
+#ifndef VERSION
33+
+#define VERSION "2.1"
34+
+#endif
35+
+
36+
+#ifndef VPATH
37+
+#define VPATH "."
38+
+#endif
39+
+
40+
+#ifndef PREFIX
41+
+# define PREFIX "/usr/local"
42+
+#endif
43+
+
44+
+#ifndef EXEC_PREFIX
45+
+#define EXEC_PREFIX PREFIX
46+
+#endif
47+
+
48+
+#ifndef PYTHONPATH
49+
+#define PYTHONPATH PREFIX "/lib/python" VERSION ":" \
50+
+ EXEC_PREFIX "/lib/python" VERSION "/lib-dynload"
51+
#endif
52+
53+
#ifndef LANDMARK
54+
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
55+
--- a/Modules/timemodule.c
56+
+++ b/Modules/timemodule.c
57+
@@ -358,18 +358,20 @@ time_gmtime(PyObject *self, PyObject *args)
58+
#endif
59+
}
60+
61+
-#ifndef HAVE_TIMEGM
62+
-static time_t
63+
-timegm(struct tm *p)
64+
-{
65+
- /* XXX: the following implementation will not work for tm_year < 1970.
66+
- but it is likely that platforms that don't have timegm do not support
67+
- negative timestamps anyways. */
68+
- return p->tm_sec + p->tm_min*60 + p->tm_hour*3600 + p->tm_yday*86400 +
69+
- (p->tm_year-70)*31536000 + ((p->tm_year-69)/4)*86400 -
70+
- ((p->tm_year-1)/100)*86400 + ((p->tm_year+299)/400)*86400;
71+
-}
72+
-#endif
73+
+/* In the Android build, HAVE_TIMEGM apparently should be defined but isn't. A better fix would be to work out why and fix that. */
74+
+
75+
+/* #ifndef HAVE_TIMEGM */
76+
+/* static time_t */
77+
+/* timegm(struct tm *p) */
78+
+/* { */
79+
+/* /\* XXX: the following implementation will not work for tm_year < 1970. */
80+
+/* but it is likely that platforms that don't have timegm do not support */
81+
+/* negative timestamps anyways. *\/ */
82+
+/* return p->tm_sec + p->tm_min*60 + p->tm_hour*3600 + p->tm_yday*86400 + */
83+
+/* (p->tm_year-70)*31536000 + ((p->tm_year-69)/4)*86400 - */
84+
+/* ((p->tm_year-1)/100)*86400 + ((p->tm_year+299)/400)*86400; */
85+
+/* } */
86+
+/* #endif */
87+
88+
PyDoc_STRVAR(gmtime_doc,
89+
"gmtime([seconds]) -> (tm_year, tm_mon, tm_mday, tm_hour, tm_min,\n\

0 commit comments

Comments
 (0)