From 784670c01f3e09ef8536a85d0ec815fabdd875f2 Mon Sep 17 00:00:00 2001 From: Mohammad Anwar Date: Tue, 3 Aug 2021 09:07:06 +0600 Subject: [PATCH 1/3] pygame version upgrade --- .../common/build/jni/application/src/start.c | 91 +++---------------- pythonforandroid/recipes/pygame/__init__.py | 4 +- 2 files changed, 17 insertions(+), 78 deletions(-) diff --git a/pythonforandroid/bootstraps/common/build/jni/application/src/start.c b/pythonforandroid/bootstraps/common/build/jni/application/src/start.c index f57098069f..98d00cb96a 100644 --- a/pythonforandroid/bootstraps/common/build/jni/application/src/start.c +++ b/pythonforandroid/bootstraps/common/build/jni/application/src/start.c @@ -80,6 +80,9 @@ int main(int argc, char *argv[]) { int ret = 0; FILE *fd; + char *workSpace = NULL; + char *pyScript = NULL; + LOGP("Initializing Python for Android"); // Set a couple of built-in environment vars: @@ -97,6 +100,9 @@ int main(int argc, char *argv[]) { setenv("PYTHON_NAME", "python", 1); } + workSpace = getenv("WORKSPACE"); + pyScript = getenv("PYSCRIPT"); + // Set additional file-provided environment vars: LOGP("Setting additional env vars from p4a_env_vars.txt"); char env_file_path[256]; @@ -140,25 +146,15 @@ int main(int argc, char *argv[]) { LOGP("Warning: no p4a_env_vars.txt found / failed to open!"); } - LOGP("Changing directory to the one provided by ANDROID_ARGUMENT"); - LOGP(env_argument); - chdir(env_argument); - -#if PY_MAJOR_VERSION < 3 - Py_NoSiteFlag=1; -#endif - -#if PY_MAJOR_VERSION < 3 - Py_SetProgramName("android_python"); -#else - Py_SetProgramName(L"android_python"); -#endif + LOGP("Changing directory to the one provided by ANDROID_ARGUMENT"); + LOGP(env_argument); +// chdir(env_argument); + chdir(workSpace); -#if PY_MAJOR_VERSION >= 3 - /* our logging module for android + Py_SetProgramName(L"android_python"); + /* our logging module for android */ PyImport_AppendInittab("androidembed", initandroidembed); -#endif LOGP("Preparing to initialize python"); @@ -196,10 +192,6 @@ int main(int argc, char *argv[]) { LOGP("AND: Init threads"); PyEval_InitThreads(); -#if PY_MAJOR_VERSION < 3 - initandroidembed(); -#endif - PyRun_SimpleString("import androidembed\nandroidembed.log('testing python " "print redirection')"); @@ -241,10 +233,6 @@ int main(int argc, char *argv[]) { "print('os.environ is', os.environ)\n" "print('Android kivy bootstrap done. __name__ is', __name__)"); -#if PY_MAJOR_VERSION < 3 - PyRun_SimpleString("import site; print site.getsitepackages()\n"); -#endif - LOGP("AND: Ran string"); /* run it ! @@ -253,66 +241,17 @@ int main(int argc, char *argv[]) { /* Get the entrypoint, search the .pyo then .py */ - char *dot = strrchr(env_entrypoint, '.'); -#if PY_MAJOR_VERSION > 2 - char *ext = ".pyc"; -#else - char *ext = ".pyo"; -#endif - if (dot <= 0) { - LOGP("Invalid entrypoint, abort."); - return -1; - } - if (strlen(env_entrypoint) > ENTRYPOINT_MAXLEN - 2) { - LOGP("Entrypoint path is too long, try increasing ENTRYPOINT_MAXLEN."); - return -1; - } - if (!strcmp(dot, ext)) { - if (!file_exists(env_entrypoint)) { - /* fallback on .py */ - strcpy(entrypoint, env_entrypoint); - entrypoint[strlen(env_entrypoint) - 1] = '\0'; - LOGP(entrypoint); - if (!file_exists(entrypoint)) { - LOGP("Entrypoint not found (.pyc, fallback on .py), abort"); - return -1; - } - } else { - strcpy(entrypoint, env_entrypoint); - } - } else if (!strcmp(dot, ".py")) { - /* if .py is passed, check the pyo version first */ - strcpy(entrypoint, env_entrypoint); - entrypoint[strlen(env_entrypoint) + 1] = '\0'; -#if PY_MAJOR_VERSION > 2 - entrypoint[strlen(env_entrypoint)] = 'c'; -#else - entrypoint[strlen(env_entrypoint)] = 'o'; -#endif - if (!file_exists(entrypoint)) { - /* fallback on pure python version */ - if (!file_exists(env_entrypoint)) { - LOGP("Entrypoint not found (.py), abort."); - return -1; - } - strcpy(entrypoint, env_entrypoint); - } - } else { - LOGP("Entrypoint have an invalid extension (must be .py or .pyc), abort."); - return -1; - } // LOGP("Entrypoint is:"); - // LOGP(entrypoint); - fd = fopen(entrypoint, "r"); + fd = fopen(pyScript, "r"); if (fd == NULL) { LOGP("Open the entrypoint failed"); - LOGP(entrypoint); + LOGP(pyScript); return -1; } /* run python ! */ - ret = PyRun_SimpleFile(fd, entrypoint); + ret = PyRun_SimpleFile(fd, pyScript); fclose(fd); if (PyErr_Occurred() != NULL) { diff --git a/pythonforandroid/recipes/pygame/__init__.py b/pythonforandroid/recipes/pygame/__init__.py index 7dfe505691..3088b6e8c0 100644 --- a/pythonforandroid/recipes/pygame/__init__.py +++ b/pythonforandroid/recipes/pygame/__init__.py @@ -13,8 +13,8 @@ class Pygame2Recipe(CompiledComponentsPythonRecipe): not part of the build. It's usable, but not complete. """ - version = '2.0.0-dev7' - url = 'https://github.com/pygame/pygame/archive/android-{version}.tar.gz' + version = '2.0.1' + url = 'https://github.com/pygame/pygame/archive/{version}.tar.gz' site_packages_name = 'pygame' name = 'pygame' From 114725689975d33d04a4f37362e72240c0489608 Mon Sep 17 00:00:00 2001 From: Mohammad Anwar Date: Thu, 5 Aug 2021 17:39:47 +0600 Subject: [PATCH 2/3] [fixed] process exit code --- .../common/build/jni/application/src/start.c | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/pythonforandroid/bootstraps/common/build/jni/application/src/start.c b/pythonforandroid/bootstraps/common/build/jni/application/src/start.c index 98d00cb96a..017e5cd1a7 100644 --- a/pythonforandroid/bootstraps/common/build/jni/application/src/start.c +++ b/pythonforandroid/bootstraps/common/build/jni/application/src/start.c @@ -257,9 +257,10 @@ int main(int argc, char *argv[]) { if (PyErr_Occurred() != NULL) { ret = 1; PyErr_Print(); /* This exits with the right code if SystemExit. */ - PyObject *f = PySys_GetObject("stdout"); - if (PyFile_WriteString("\n", f)) - PyErr_Clear(); + PyErr_Clear(); +// PyObject *f = PySys_GetObject("stdout"); +// if (PyFile_WriteString("\n", f)) +// PyErr_Clear(); } LOGP("Python for android ended."); @@ -272,25 +273,21 @@ int main(int argc, char *argv[]) { https://github.com/kivy/kivy/pull/6107#issue-246120816 */ - char terminatecmd[256]; + +/* char terminatecmd[256]; snprintf( terminatecmd, sizeof(terminatecmd), "import sys; sys.exit(%d)\n", ret ); - PyRun_SimpleString(terminatecmd); + PyRun_SimpleString(terminatecmd);*/ /* This should never actually be reached, but we'll leave the clean-up * here just to be safe. */ -#if PY_MAJOR_VERSION < 3 - Py_Finalize(); - LOGP("Unexpectedly reached Py_FinalizeEx(), but was successful."); -#else if (Py_FinalizeEx() != 0) // properly check success on Python 3 - LOGP("Unexpectedly reached Py_FinalizeEx(), and got error!"); + LOGP("Unexpectedly reached Py_FinalizeEx(), and got error!"); else - LOGP("Unexpectedly reached Py_FinalizeEx(), but was successful."); -#endif + LOGP("Unexpectedly reached Py_FinalizeEx(), but was successful."); return ret; } From c52761b9a18a066de9e6079eda0eb1f840bd9d3b Mon Sep 17 00:00:00 2001 From: Mohammad Anwar Date: Tue, 28 Sep 2021 01:40:55 +0600 Subject: [PATCH 3/3] [release] android release 1.4.57 --- .../common/build/jni/application/src/start.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pythonforandroid/bootstraps/common/build/jni/application/src/start.c b/pythonforandroid/bootstraps/common/build/jni/application/src/start.c index 017e5cd1a7..e1029ae3ba 100644 --- a/pythonforandroid/bootstraps/common/build/jni/application/src/start.c +++ b/pythonforandroid/bootstraps/common/build/jni/application/src/start.c @@ -201,16 +201,32 @@ int main(int argc, char *argv[]) { PyRun_SimpleString("import sys, posix\n"); char add_site_packages_dir[256]; + char add_prefix[256]; + char add_lib_path[256]; + char add_current_workspace_path[256]; if (dir_exists(python_bundle_dir)) { snprintf(add_site_packages_dir, 256, "sys.path.append('%s/site-packages')", python_bundle_dir); + snprintf(add_lib_path, 256, + "sys.path.append('%s/lib/python3.8/site-packages')", + getenv("ANDROID_UNPACK")); + + snprintf(add_current_workspace_path, 256, + "sys.path.append('%s')", workSpace); + + snprintf(add_prefix, 256, + "sys.prefix = '%s'", + getenv("ANDROID_UNPACK")); PyRun_SimpleString("import sys\n" "sys.argv = ['notaninterpreterreally']\n" "from os.path import realpath, join, dirname"); + PyRun_SimpleString(add_prefix); PyRun_SimpleString(add_site_packages_dir); + PyRun_SimpleString(add_lib_path); + PyRun_SimpleString(add_current_workspace_path); /* "sys.path.append(join(dirname(realpath(__file__)), 'site-packages'))") */ PyRun_SimpleString("sys.path = ['.'] + sys.path"); }