Skip to content

Commit f36d340

Browse files
opacamAndreMiras
authored andcommitted
Minimal fixes to make pygame bootstrap work with python2legacy (kivy#1587)
* Force SDL and pygame recipes to be build with python2legacy instead of python2 We don't know if pygame will work for the new python2, for now we force to be build only for python2legacy because we know for sure that it works (we always can grant python2 compatibility later or not...this could be the first step to deprecate pygame bootstrap) * Make setup_pygame.py to use python2legacy Because we will fix the pygame bootstrap build for python2legacy not for python2 * Adapt pygame bootstrap to new python build/distribution system (make use of refactored distribution methods) * Adapt pygame bootstrap file `Application.mk` to newer ndks And: - remove hardcoded entries - add cflags to allow build with newer ndks - comment APP_STL line and set it to c++_static because the gnustl will be removed in android ndk 18, plus the default behaviour is to use the static stl lib...so...better let the android build decide depending on the ndk used. * Fix sdl's jpeg build with newer ndks Because with the latest changes in master branch we need an ndk with the `unified headers feature`...so...we expect to find an ndk > 15 (preferably ndk17c or ndk18b at the time of writing)...this will allow us to use the same ndk for all bootstrap builds, otherwise we should use an old ndk to build the pygame bootstrap * Fix start.c for pygame bootstrap and reduce specific code for pygame bootstrap * Fix ant build for pygame bootstrap The ideal would be to move the apk build from ant to gradle...but this will require more work...for now we fix the java version problem we have with ant's build....because the other option it's far more complicated...maybe we will get there in future commits...
1 parent e3123f4 commit f36d340

File tree

11 files changed

+88
-62
lines changed

11 files changed

+88
-62
lines changed

pythonforandroid/bootstraps/common/build/jni/application/src/start.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
#include "bootstrap_name.h"
1818
#ifndef BOOTSTRAP_USES_NO_SDL_HEADERS
1919
#include "SDL.h"
20+
#ifndef BOOTSTRAP_NAME_PYGAME
2021
#include "SDL_opengles2.h"
2122
#endif
23+
#endif
2224
#ifdef BOOTSTRAP_NAME_PYGAME
2325
#include "jniwrapperstuff.h"
2426
#endif
@@ -335,10 +337,8 @@ JNIEXPORT void JNICALL Java_org_kivy_android_PythonService_nativeStart(
335337
jobject thiz,
336338
jstring j_android_private,
337339
jstring j_android_argument,
338-
#if (!defined(BOOTSTRAP_NAME_PYGAME))
339340
jstring j_service_entrypoint,
340341
jstring j_python_name,
341-
#endif
342342
jstring j_python_home,
343343
jstring j_python_path,
344344
jstring j_arg) {
@@ -347,14 +347,10 @@ JNIEXPORT void JNICALL Java_org_kivy_android_PythonService_nativeStart(
347347
(*env)->GetStringUTFChars(env, j_android_private, &iscopy);
348348
const char *android_argument =
349349
(*env)->GetStringUTFChars(env, j_android_argument, &iscopy);
350-
#if (!defined(BOOTSTRAP_NAME_PYGAME))
351350
const char *service_entrypoint =
352351
(*env)->GetStringUTFChars(env, j_service_entrypoint, &iscopy);
353352
const char *python_name =
354353
(*env)->GetStringUTFChars(env, j_python_name, &iscopy);
355-
#else
356-
const char python_name[] = "python2";
357-
#endif
358354
const char *python_home =
359355
(*env)->GetStringUTFChars(env, j_python_home, &iscopy);
360356
const char *python_path =
@@ -364,10 +360,7 @@ JNIEXPORT void JNICALL Java_org_kivy_android_PythonService_nativeStart(
364360
setenv("ANDROID_PRIVATE", android_private, 1);
365361
setenv("ANDROID_ARGUMENT", android_argument, 1);
366362
setenv("ANDROID_APP_PATH", android_argument, 1);
367-
368-
#if (!defined(BOOTSTRAP_NAME_PYGAME))
369363
setenv("ANDROID_ENTRYPOINT", service_entrypoint, 1);
370-
#endif
371364
setenv("PYTHONOPTIMIZE", "2", 1);
372365
setenv("PYTHON_NAME", python_name, 1);
373366
setenv("PYTHONHOME", python_home, 1);

pythonforandroid/bootstraps/pygame/__init__.py

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
from pythonforandroid.toolchain import Bootstrap, current_directory, info, info_main, shprint
2+
from pythonforandroid.util import ensure_dir
23
from os.path import join, exists
3-
from os import walk
4-
import glob
54
import sh
65

76

87
class PygameBootstrap(Bootstrap):
98
name = 'pygame'
109

11-
recipe_depends = ['hostpython2', 'python2', 'pyjnius', 'sdl', 'pygame',
12-
'android', 'kivy']
10+
recipe_depends = ['hostpython2legacy', 'python2legacy', 'pyjnius',
11+
'sdl', 'pygame', 'android', 'kivy']
1312

1413
def run_distribute(self):
1514
info_main('# Creating Android project from build and {} bootstrap'.format(
@@ -45,53 +44,30 @@ def run_distribute(self):
4544
fileh.write('sdk.dir={}'.format(self.ctx.sdk_dir))
4645

4746
info('Copying python distribution')
48-
hostpython = sh.Command(self.ctx.hostpython)
49-
try:
50-
shprint(hostpython, '-OO', '-m', 'compileall', self.ctx.get_python_install_dir(),
51-
_tail=10, _filterout="^Listing")
52-
except sh.ErrorReturnCode:
53-
pass
54-
if not exists('python-install'):
55-
shprint(sh.cp, '-a', self.ctx.get_python_install_dir(), './python-install')
56-
57-
self.distribute_libs(arch, [join(self.build_dir, 'libs', arch.arch), self.ctx.get_libs_dir(arch.arch)])
47+
48+
python_bundle_dir = join('_python_bundle', '_python_bundle')
49+
if 'python2legacy' in self.ctx.recipe_build_order:
50+
# a special case with its own packaging location
51+
python_bundle_dir = 'private'
52+
# And also must had an install directory, make sure of that
53+
self.ctx.python_recipe.create_python_install(self.dist_dir)
54+
55+
self.distribute_libs(
56+
arch, [join(self.build_dir, 'libs', arch.arch),
57+
self.ctx.get_libs_dir(arch.arch)])
5858
self.distribute_aars(arch)
5959
self.distribute_javaclasses(self.ctx.javaclass_dir)
6060

61-
info('Filling private directory')
62-
if not exists(join('private', 'lib')):
63-
shprint(sh.cp, '-a', join('python-install', 'lib'), 'private')
64-
shprint(sh.mkdir, '-p', join('private', 'include', 'python2.7'))
65-
66-
shprint(sh.mv, join('libs', arch.arch, 'libpymodules.so'), 'private/')
67-
shprint(sh.cp, join('python-install', 'include', 'python2.7', 'pyconfig.h'), join('private', 'include', 'python2.7/'))
68-
69-
info('Removing some unwanted files')
70-
shprint(sh.rm, '-f', join('private', 'lib', 'libpython2.7.so'))
71-
shprint(sh.rm, '-rf', join('private', 'lib', 'pkgconfig'))
72-
73-
with current_directory(join(self.dist_dir, 'private', 'lib', 'python2.7')):
74-
# shprint(sh.xargs, 'rm', sh.grep('-E', '*\.(py|pyx|so\.o|so\.a|so\.libs)$', sh.find('.')))
75-
removes = []
76-
for dirname, something, filens in walk('.'):
77-
for filename in filens:
78-
for suffix in ('py', 'pyc', 'so.o', 'so.a', 'so.libs'):
79-
if filename.endswith(suffix):
80-
removes.append(filename)
81-
shprint(sh.rm, '-f', *removes)
82-
83-
info('Deleting some other stuff not used on android')
84-
# To quote the original distribute.sh, 'well...'
85-
# shprint(sh.rm, '-rf', 'ctypes')
86-
shprint(sh.rm, '-rf', 'lib2to3')
87-
shprint(sh.rm, '-rf', 'idlelib')
88-
for filename in glob.glob('config/libpython*.a'):
89-
shprint(sh.rm, '-f', filename)
90-
shprint(sh.rm, '-rf', 'config/python.o')
91-
shprint(sh.rm, '-rf', 'lib-dynload/_ctypes_test.so')
92-
shprint(sh.rm, '-rf', 'lib-dynload/_testcapi.so')
61+
ensure_dir(python_bundle_dir)
62+
site_packages_dir = self.ctx.python_recipe.create_python_bundle(
63+
join(self.dist_dir, python_bundle_dir), arch)
64+
65+
if 'sqlite3' not in self.ctx.recipe_build_order:
66+
with open('blacklist.txt', 'a') as fileh:
67+
fileh.write('\nsqlite3/*\nlib-dynload/_sqlite3.so\n')
9368

9469
self.strip_libraries(arch)
70+
self.fry_eggs(site_packages_dir)
9571
super(PygameBootstrap, self).run_distribute()
9672

9773

pythonforandroid/bootstraps/pygame/build/build.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ def make_package(args):
215215
default_icon = 'templates/kivy-icon.png'
216216
default_presplash = 'templates/kivy-presplash.jpg'
217217
default_ouya_icon = 'templates/kivy-ouya-icon.png'
218+
default_ant_properties = 'templates/ant.properties'
218219
# Figure out the version code, if necessary.
219220
if not args.numeric_version:
220221
for i in args.version.split('.'):
@@ -345,6 +346,9 @@ def make_package(args):
345346
shutil.copy(args.presplash or default_presplash,
346347
'res/drawable/presplash.jpg')
347348

349+
# Copy over the ant.properties file.
350+
shutil.copy(default_ant_properties, 'ant.properties')
351+
348352
# If OUYA support was requested, copy over the OUYA icon
349353
if args.ouya_category:
350354
if not os.path.isdir('res/drawable-xhdpi'):

pythonforandroid/bootstraps/pygame/build/jni/Application.mk

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ APP_PROJECT_PATH := $(call my-dir)/..
88
APP_MODULES := application sdl sdl_main tremor png jpeg freetype sdl_ttf sdl_image sqlite3
99

1010
APP_ABI := $(ARCH)
11-
# AND: I have no idea why I have to specify app_platform when distribute.sh seems to just set the sysroot cflag
12-
# AND: Either way, this has to *at least* be configurable
13-
APP_PLATFORM := android-14
14-
APP_STL := gnustl_static
11+
APP_PLATFORM := $(NDK_API)
12+
#APP_STL := c++_static
1513
APP_CFLAGS += $(OFLAG)
14+
APP_CFLAGS += -std=gnu89 -Wno-return-type

pythonforandroid/bootstraps/pygame/build/src/org/renpy/android/SDLSurfaceView.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,8 @@ public void run() {
707707
nativeInitJavaCallbacks();
708708
nativeSetEnv("ANDROID_PRIVATE", mFilesDirectory);
709709
nativeSetEnv("ANDROID_UNPACK", mFilesDirectory);
710+
nativeSetEnv("ANDROID_ENTRYPOINT", mArgument + "/main.py");
711+
nativeSetEnv("PYTHON_NAME", "python");
710712
nativeSetEnv("ANDROID_ARGUMENT", mArgument);
711713
nativeSetEnv("ANDROID_APP_PATH", mArgument);
712714
nativeSetEnv("PYTHONOPTIMIZE", "2");
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
java.target=1.7
2+
java.source=1.7

pythonforandroid/recipes/pygame/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class PygameRecipe(Recipe):
1212
version = '1.9.1'
1313
url = 'http://pygame.org/ftp/pygame-{version}release.tar.gz'
1414

15-
depends = ['python2', 'sdl']
15+
depends = ['python2legacy', 'sdl']
1616
conflicts = ['sdl2']
1717

1818
patches = ['patches/fix-surface-access.patch',

pythonforandroid/recipes/pygame_bootstrap_components/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,11 @@ def prebuild_arch(self, arch):
2525
info('Unpacking was successful, deleting original container dir')
2626
shprint(sh.rm, '-rf', self.get_build_dir(arch))
2727

28+
info('Applying jpeg assembler patch')
29+
ndk_15_plus_patch = join(self.get_recipe_dir(), 'jpeg-ndk15-plus.patch')
30+
shprint(sh.patch, '-t', '-d',
31+
join(self.get_build_container_dir(arch), 'jpeg'), '-p1',
32+
'-i', ndk_15_plus_patch, _tail=10)
33+
2834

2935
recipe = PygameJNIComponentsRecipe()
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
The distributed jpeg has troubles to be build with newer ndks, starting from
2+
the introduction of the `unified headers` (ndk > 15). This patch allow us to
3+
build the distributed `external jpeg` in sdl package, got the solution in here:
4+
https://github.com/oNaiPs/droidVncServer/issues/53
5+
--- jpeg/Android.mk.orig 2015-06-21 15:14:54.000000000 +0200
6+
+++ jpeg/Android.mk 2019-01-14 10:57:06.384806168 +0100
7+
@@ -20,7 +20,7 @@
8+
endif
9+
10+
# temp fix until we understand why this broke cnn.com
11+
-#ANDROID_JPEG_NO_ASSEMBLER := true
12+
+ANDROID_JPEG_NO_ASSEMBLER := true
13+
14+
ifeq ($(strip $(ANDROID_JPEG_NO_ASSEMBLER)),true)
15+
LOCAL_SRC_FILES += jidctint.c jidctfst.c
16+
--- jpeg/jidctfst.S.orig 2019-01-14 11:00:38.000000000 +0100
17+
+++ jpeg/jidctfst.S 2019-01-14 11:00:56.844803970 +0100
18+
@@ -63,7 +63,7 @@
19+
20+
21+
jpeg_idct_ifast:
22+
- PLD [r2, #0]
23+
+ pld [r2, #0]
24+
stmdb sp!, {r4,r5, r6,r7, r8,r9, r10,r11, r12,lr}
25+
ldr r4, [sp, #4*10]
26+
sub sp, #local_SIZE
27+
@@ -256,7 +256,7 @@
28+
29+
HLoopStart:
30+
// reset pointers
31+
- PLD [sp, #off_WORKSPACE]
32+
+ pld [sp, #off_WORKSPACE]
33+
add ip, sp, #off_WORKSPACE
34+
ldr r10, local_RANGE_TABLE
35+
36+
@@ -268,7 +268,7 @@
37+
str r0, local_OUTPUT_BUF
38+
add fp, r2, r1
39+
40+
- PLD [ip, #32]
41+
+ pld [ip, #32]
42+
ldmia ip!, {r0-r7}
43+
44+
cmp r1, #0

pythonforandroid/recipes/sdl/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class LibSDLRecipe(BootstrapNDKRecipe):
88
version = "1.2.14"
99
url = None
1010
name = 'sdl'
11-
depends = ['python2', 'pygame_bootstrap_components']
11+
depends = ['python2legacy', 'pygame_bootstrap_components']
1212
conflicts = ['sdl2']
1313

1414
def build_arch(self, arch):

testapps/setup_pygame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from setuptools import find_packages
44

55
options = {'apk': {'debug': None,
6-
'requirements': 'pygame,pyjnius,kivy,python2,android',
6+
'requirements': 'pygame,pyjnius,kivy,python2legacy,android',
77
'android-api': 27,
88
'ndk-api': 19,
99
'ndk-dir': '/home/asandy/android/crystax-ndk-10.3.2',

0 commit comments

Comments
 (0)