8000 More sdl2 bootstrap changes for python3 · kived/python-for-android@76bcf99 · GitHub
[go: up one dir, main page]

Skip to content

Commit 76bcf99

Browse files
committed
More sdl2 bootstrap changes for python3
1 parent 9fb3af2 commit 76bcf99

File tree

2 files changed

+54
-19
lines changed

2 files changed

+54
-19
lines changed

pythonforandroid/bootstraps/sdl2/__init__.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def run_distribute(self):
3232
shprint(sh.mkdir, 'private')
3333
if not exists('crystax_python') and self.ctx.ndk_is_crystax:
3434
shprint(sh.mkdir, 'crystax_python')
35+
shprint(sh.mkdir, 'crystax_python/crystax_python')
3536
if not exists('assets'):
3637
shprint(sh.mkdir, 'assets')
3738

@@ -89,10 +90,19 @@ def run_distribute(self):
8990
python_dir = join(ndk_dir, 'sources', 'python', '3.5',
9091
'libs', arch.arch)
9192

92-
shprint(sh.cp, '-r', join(python_dir, 'stdlib.zip'), 'crystax_python/')
93-
shprint(sh.cp, '-r', join(python_dir, 'modules'), 'crystax_python/')
94-
shprint(sh.cp, '-r', self.ctx.get_python_install_dir(), 'crystax_python/site-packages')
95-
93+
shprint(sh.cp, '-r', join(python_dir, 'stdlib.zip'), 'crystax_python/crystax_python')
94+
shprint(sh.cp, '-r', join(python_dir, 'modules'), 'crystax_python/crystax_python')
95+
shprint(sh.cp, '-r', self.ctx.get_python_install_dir(), 'crystax_python/crystax_python/site-packages')
96+
97+
info('Renaming .so files to reflect cross-compile')
98+
site_packages_dir = 'crystax_python/crystax_python/site-packages'
99+
filens = shprint(sh.find, site_packages_dir, '-iname', '*.so').stdout.split('\n')[:-1]
100+
for filen in filens:
101+
parts = filen.split('.')
102+
if len(parts) <= 2:
103+
continue
104+
shprint(sh.mv, filen, filen.split('.')[0] + '.so')
105+
96106

97107
self.strip_libraries(arch)
98108
super(SDL2Bootstrap, self).run_distribute()

pythonforandroid/bootstraps/sdl2/build/jni/src/start.c

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <stdio.h>
99
#include <stdlib.h>
1010
#include <unistd.h>
11+
#include <dirent.h>
1112
#include <jni.h>
1213

1314
#include "SDL.h"
@@ -53,18 +54,27 @@ PyMODINIT_FUNC initandroidembed(void) {
5354
/* (void) Py_InitModule("androidembed", AndroidEmbedMethods); */
5455
}
5556

56-
int dir_exists(char* filename)
57-
/* Function from http://stackoverflow.com/questions/12510874/how-can-i-check-if-a-directory-exists-on-linux-in-c# */
58-
{
59-
if (0 != access("filename", F_OK)) {
60-
if (ENOENT == errno) {
61-
return 0;
62-
}
63-
if (ENOTDIR == errno) {
64-
return 0;
65-
}
57+
/* int dir_exists(char* filename) */
58+
/* /\* Function from http://stackoverflow.com/questions/12510874/how-can-i-check-if-a-directory-exists-on-linux-in-c# *\/ */
59+
/* { */
60+
/* if (0 != access(filename, F_OK)) { */
61+
/* if (ENOENT == errno) { */
62+
/* return 0; */
63+
/* } */
64+
/* if (ENOTDIR == errno) { */
65+
/* return 0; */
66+
/* } */
67+
/* return 1; */
68+
/* } */
69+
/* } */
70+
71+
int dir_exists(char* filename) {
72+
DIR *dip;
73+
if (dip = opendir(filename)) {
74+
closedir(filename);
6675
return 1;
6776
}
77+
return 0;
6878
}
6979

7080
int file_exists(const char * filename)
@@ -108,7 +118,21 @@ int main(int argc, char *argv[]) {
108118
*/
109119
PyImport_AppendInittab("androidembed", initandroidembed);
110120

121+
LOG("Preparing to initialize python");
122+
123+
if (dir_exists("../libs")) {
124+
LOG("libs exists");
125+
} else {
126+
LOG("libs does not exist");
127+
}
128+
129+
if (dir_exists("crystax_python")) {
130+
LOG("exists without slash");
131+
}
132+
111133
if (dir_exists("crystax_python/")) {
134+
/* if (1) { */
135+
LOG("crystax_python exists");
112136
char paths[256];
113137
snprintf(paths, 256, "%s/crystax_python/stdlib.zip:%s/crystax_python/modules", env_argument, env_argument);
114138
/* snprintf(paths, 256, "%s/stdlib.zip:%s/modules", env_argument, env_argument); */
@@ -118,7 +142,7 @@ int main(int argc, char *argv[]) {
118142
wchar_t* wchar_paths = Py_DecodeLocale(paths, NULL);
119143
Py_SetPath(wchar_paths);
120144
LOG("set wchar paths...");
121-
}
145+
} else { LOG("crystax_python does not exist");}
122146

123147
Py_Initialize();
124148

@@ -152,18 +176,19 @@ int main(int argc, char *argv[]) {
152176
" private + '/lib/python2.7/lib-dynload/', \n" \
153177
" private + '/lib/python2.7/site-packages/', \n" \
154178
" argument ]\n");
155-
} else {
179+
} else {
156180

157181
char add_site_packages_dir[256];
158182
snprintf(add_site_packages_dir, 256, "sys.path.append('%s/crystax_python/site-packages')",
159183
env_argument);
160184

161185
PyRun_SimpleString(
162-
"import sys\n" \
163-
"sys.argv = ['notaninterpreterreally']\n" \
186+
"import sys\n" \
187+
"sys.argv = ['notaninterpreterreally']\n" \
164188
"from os.path import realpath, join, dirname");
165189
PyRun_SimpleString(add_site_packages_dir);
166-
/* "sys.path.append(join(dirname(realpath(__file__)), 'site-packages'))") */
190+
/* "sys.path.append(join(dirname(realpath(__file__)), 'site-packages'))") */
191+
PyRun_SimpleString("sys.path = ['.'] + sys.path");
167192
}
168193

169194
PyRun_SimpleString(

0 commit comments

Comments
 (0)
0