Skip to content

Commit 5ee3d00

Browse files
committed
start.c: if we are compiling the app to pyo, then search for a main.pyo, not a main.py in C bootstrap
1 parent f9e4777 commit 5ee3d00

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

src/jni/application/python/start.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ PyMODINIT_FUNC initandroidembed(void) {
3131
(void) Py_InitModule("androidembed", AndroidEmbedMethods);
3232
}
3333

34+
int file_exists(const char * filename)
35+
{
36+
FILE *file;
37+
if (file = fopen(filename, "r")) {
38+
fclose(file);
39+
return 1;
40+
}
41+
return 0;
42+
}
43+
3444
int main(int argc, char **argv) {
3545

3646
char *env_argument = NULL;
@@ -85,15 +95,31 @@ int main(int argc, char **argv) {
8595
*/
8696
LOG("Run user program, change dir and execute main.py");
8797
chdir(env_argument);
88-
fd = fopen("main.py", "r");
98+
99+
/* search the initial main.py
100+
*/
101+
char *main_py = "main.pyo";
102+
if ( file_exists(main_py) == 0 ) {
103+
if ( file_exists("main.py") )
104+
main_py = "main.py";
105+
else
106+
main_py = NULL;
107+
}
108+
109+
if ( main_py == NULL ) {
110+
LOG("No main.pyo / main.py found.");
111+
return -1;
112+
}
113+
114+
fd = fopen(main_py, "r");
89115
if ( fd == NULL ) {
90-
LOG("Open the main.py failed");
116+
LOG("Open the main.py(o) failed");
91117
return -1;
92118
}
93119

94120
/* run python !
95121
*/
96-
ret = PyRun_SimpleFile(fd, "main.py");
122+
ret = PyRun_SimpleFile(fd, main_py);
97123

98124
if (PyErr_Occurred() != NULL) {
99125
ret = 1;

0 commit comments

Comments
 (0)