Skip to content

Commit c641127

Browse files
committed
Merge branch 'master' of github.com:kivy/python-for-android
2 parents cf1611f + 5cde14c commit c641127

File tree

35 files changed

+425
-389
lines changed

35 files changed

+425
-389
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Broad goals of the revamp project include:
2727
- (WIP) Support python3 (recipe exists but crashes on android)
2828
- (WIP) Support some kind of binary distribution, including on windows (semi-implemented, just needs finishing)
2929
- ✓ Be a standalone Pypi module (not on pypi yet but setup.py works)
30-
- Support multiple architectures
30+
- Support multiple architectures (full multiarch builds not complete, but arm and x86 with different config both work now)
3131

3232
We are currently working to stabilise all parts of the toolchain and
3333
add more features. Support for pygame-based APKs is almost feature

doc/source/commands.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ supply those that you need.
7070
``--force_build BOOL``
7171
Whether the distribution must be compiled from scratch.
7272

73+
``--arch``
74+
The architecture to build for. Currently only one architecture can be
75+
targeted at a time, and a given distribution can only include one architecture.
76+
77+
7378
.. note:: These options are preliminary. Others will include toggles
7479
for allowing downloads, and setting additional directories
7580
from which to load user dists.

doc/source/quickstart.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ correct and try to continue the build.
254254
Configuration file
255255
~~~~~~~~~~~~~~~~~~
256256

257-
python-for-android look on the current directory if there is a `.p4a`
258-
configuration file. If it found it, it adds all the lines as options
259-
to the command line. For example, you can put the options you would
260-
always write such as:
257+
python-for-android checks in the current directory for a configuration
258+
file named ``.p4a``. If found, it adds all the lines as options to the
259+
command line. For example, you can add the options you would always
260+
include such as:
261261

262262
--dist_name my_example
263263
--android_api 19

pythonforandroid/bootstraps/empty/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pythonforandroid.toolchain import Bootstrap, shprint, current_directory, info, warning, ArchAndroid, logger, info_main, which
1+
from pythonforandroid.toolchain import Bootstrap, shprint, current_directory, info, warning, ArchARM, logger, info_main, which
22
from os.path import join, exists
33
from os import walk
44
import glob

pythonforandroid/bootstraps/pygame/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pythonforandroid.toolchain import Bootstrap, shprint, current_directory, info, warning, ArchAndroid, info_main
1+
from pythonforandroid.toolchain import Bootstrap, shprint, current_directory, info, warning, ArchARM, info_main
22
from os.path import join, exists
33
from os import walk
44
import glob
@@ -19,8 +19,10 @@ def run_distribute(self):
1919
# self.name)
2020
src_path = join(self.bootstrap_dir, 'build')
2121

22-
# AND: Hardcoding armeabi - naughty!
23-
arch = ArchAndroid(self.ctx)
22+
arch = self.ctx.archs[0]
23+
if len(self.ctx.archs) > 1:
24+
raise ValueError('built for more than one arch, but bootstrap cannot handle that yet')
25+
info('Bootstrap running with arch {}'.format(arch))
2426

2527
with current_directory(self.dist_dir):
2628

@@ -58,7 +60,7 @@ def run_distribute(self):
5860
shprint(sh.mkdir, '-p', join('private', 'include', 'python2.7'))
5961

6062
# AND: Copylibs stuff should go here
61-
shprint(sh.mv, join('libs', 'armeabi', 'libpymodules.so'), 'private/')
63+
shprint(sh.mv, join('libs', arch.arch, 'libpymodules.so'), 'private/')
6264
shprint(sh.cp, join('python-install', 'include' , 'python2.7', 'pyconfig.h'), join('private', 'include', 'python2.7/'))
6365

6466
info('Removing some unwanted files')

pythonforandroid/bootstraps/pygame/build/jni/application/Android.mk

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ LOCAL_CFLAGS := $(foreach D, $(APP_SUBDIRS), -I$(LOCAL_PATH)/$(D)) \
1818
-I$(LOCAL_PATH)/../jpeg \
1919
-I$(LOCAL_PATH)/../intl \
2020
-I$(LOCAL_PATH)/.. \
21-
-I$(LOCAL_PATH)/../../../../other_builds/python2/armeabi/python2/python-install/include/python2.7
21+
-I$(LOCAL_PATH)/../../../../other_builds/python2/$(ARCH)/python2/python-install/include/python2.7
2222
# -I$(LOCAL_PATH)/../../../../python-install/include/python2.7
2323
# -I$(LOCAL_PATH)/../../../build/python-install/include/python2.7
2424

@@ -39,7 +39,8 @@ LOCAL_STATIC_LIBRARIES := jpeg png
3939
LOCAL_LDLIBS := -lpython2.7 -lGLESv1_CM -ldl -llog -lz
4040

4141
# AND: Another hardcoded path that should be templated
42-
LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../../../../other_builds/python2/armeabi/python2/python-install/lib $(APPLICATION_ADDITIONAL_LDFLAGS)
42+
# AND: NOT TEMPALTED! We can use $ARCH
43+
LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../../../../other_builds/python2/$(ARCH)/python2/python-install/lib $(APPLICATION_ADDITIONAL_LDFLAGS)
4344

4445
LIBS_WITH_LONG_SYMBOLS := $(strip $(shell \
4546
for f in $(LOCAL_PATH)/../../libs/$ARCH/*.so ; do \

pythonforandroid/bootstraps/sdl2/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pythonforandroid.toolchain import Bootstrap, shprint, current_directory, info, warning, ArchAndroid, info_main
1+
from pythonforandroid.toolchain import Bootstrap, shprint, current_directory, info, warning, ArchARM, info_main
22
from os.path import join, exists
33
from os import walk
44
import glob
@@ -20,8 +20,10 @@ def run_distribute(self):
2020
with open('local.properties', 'w') as fileh:
2121
fileh.write('sdk.dir={}'.format(self.ctx.sdk_dir))
2222

23-
# AND: Hardcoding armeabi - naughty!
24-
arch = ArchAndroid(self.ctx)
23+
arch = self.ctx.archs[0]
24+
if len(self.ctx.archs) > 1:
25+
raise ValueError('built for more than one arch, but bootstrap cannot handle that yet')
26+
info('Bootstrap running with arch {}'.format(arch))
2527

2628
with current_directory(self.dist_dir):
2729
info('Copying python distribution')
@@ -32,7 +34,6 @@ def run_distribute(self):
3234
shprint(sh.mkdir, 'assets')
3335

3436
hostpython = sh.Command(self.ctx.hostpython)
35-
# AND: This *doesn't* need to be in arm env?
3637
shprint(hostpython, '-OO', '-m', 'compileall',
3738
self.ctx.get_python_install_dir(),
3839
_tail=10, _filterout="^Listing", _critical=True)
@@ -50,8 +51,8 @@ def run_distribute(self):
5051
shprint(sh.mkdir, '-p', join('private', 'include', 'python2.7'))
5152

5253
# AND: Copylibs stuff should go here
53-
if exists(join('libs', 'armeabi', 'libpymodules.so')):
54-
shprint(sh.mv, join('libs', 'armeabi', 'libpymodules.so'), 'private/')
54+
if exists(join('libs', arch.arch, 'libpymodules.so')):
55+
shprint(sh.mv, join('libs', arch.arch, 'libpymodules.so'), 'private/')
5556
shprint(sh.cp, join('python-install', 'include' , 'python2.7', 'pyconfig.h'), join('private', 'include', 'python2.7/'))
5657

5758
info('Removing some unwanted files')

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# APP_STL := stlport_static
55

66
# APP_ABI := armeabi armeabi-v7a x86
7-
APP_ABI := armeabi
7+
APP_ABI := $(ARCH)

pythonforandroid/bootstraps/sdl2/build/jni/src/Android.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include
1212
LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c \
1313
start.c
1414

15-
LOCAL_CFLAGS += -I$(LOCAL_PATH)/../../../../other_builds/python2/armeabi/python2/python-install/include/python2.7
15+
LOCAL_CFLAGS += -I$(LOCAL_PATH)/../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/include/python2.7
1616

1717
LOCAL_SHARED_LIBRARIES := SDL2
1818

1919
LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog -lpython2.7
2020

21-
LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../../../../other_builds/python2/armeabi/python2/python-install/lib $(APPLICATION_ADDITIONAL_LDFLAGS)
21+
LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/lib $(APPLICATION_ADDITIONAL_LDFLAGS)
2222

2323
include $(BUILD_SHARED_LIBRARY)

pythonforandroid/bootstraps/sdl2python3/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pythonforandroid.toolchain import Bootstrap, shprint, current_directory, info, warning, ArchAndroid, info_main
1+
from pythonforandroid.toolchain import Bootstrap, shprint, current_directory, info, warning, ArchARM, info_main
22
from os.path import join, exists
33
from os import walk
44
import glob
@@ -23,7 +23,7 @@ def run_distribute(self):
2323
fileh.write('sdk.dir={}'.format(self.ctx.sdk_dir))
2424

2525
# AND: Hardcoding armeabi - naughty!
26-
arch = ArchAndroid(self.ctx)
26+
arch = ArchARM(self.ctx)
2727

2828
with current_directory(self.dist_dir):
2929
info('Copying python distribution')

pythonforandroid/recipes/android/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
from pythonforandroid.toolchain import CythonRecipe, shprint, ensure_dir, current_directory, ArchAndroid, IncludedFilesBehaviour
2+
from pythonforandroid.toolchain import CythonRecipe, shprint, ensure_dir, current_directory, ArchARM, IncludedFilesBehaviour
33
import sh
44
from os.path import exists, join
55

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
from pythonforandroid.toolchain import CythonRecipe, shprint, current_directory, info
3+
import sh
4+
import glob
5+
from os.path import join, exists
6+
7+
8+
class AudiostreamRecipe(CythonRecipe):
9+
version = 'master'
10+
url = 'https://github.com/kivy/audiostream/archive/{version}.zip'
11+
name = 'audiostream'
12+
depends = ['python2', ('sdl', 'sdl2'), 'pyjnius']
13+
14+
def get_recipe_env(self, arch):
15+
if 'sdl' in self.ctx.recipe_build_order:
16+
sdl_include = 'sdl'
17+
sdl_mixer_include = 'sdl_mixer'
18+
elif 'sdl2' in self.ctx.recipe_build_order:
19+
sdl_include = 'SDL'
20+
sdl_mixer_include = 'SDL2_mixer'
21+
22+
#note: audiostream library is not yet able to judge whether it is being used with sdl or with sdl2.
23+
#this causes linking to fail against SDL2 (compiling against SDL2 works)
24+
#need to find a way to fix this in audiostream's setup.py
25+
raise RuntimeError('Audiostream library is not yet able to configure itself to link against SDL2. Patch on audiostream library needed - any help much appreciated!')
26+
27+
env = super(AudiostreamRecipe, self).get_recipe_env(arch)
28+
env['CFLAGS'] += ' -I{jni_path}/{sdl_include}/include -I{jni_path}/{sdl_mixer_include}'.format(
29+
jni_path = join(self.ctx.bootstrap.build_dir, 'jni'),
30+
sdl_include = sdl_include,
31+
sdl_mixer_include = sdl_mixer_include)
32+
return env
33+
34+
35+
36+
recipe = AudiostreamRecipe()
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
VERSION_audiostream=${VERSION_audiostream:-master}
4+
URL_audiostream=https://github.com/kivy/audiostream/archive/$VERSION_audiostream.zip
5+
DEPS_audiostream=(python sdl pyjnius)
6+
MD5_audiostream=
7+
BUILD_audiostream=$BUILD_PATH/audiostream/$(get_directory $URL_audiostream)
8+
RECIPE_audiostream=$RECIPES_PATH/audiostream
9+
10+
function prebuild_audiostream() {
11+
cd $BUILD_audiostream
12+
}
13+
14+
function shouldbuild_audiostream() {
15+
if [ -d "$SITEPACKAGES_PATH/audiostream" ]; then
16+
DO_BUILD=0
17+
fi
18+
}
19+
20+
function build_audiostream() {
21+
cd $BUILD_audiostream
22+
23+
push_arm
24+
25+
# build python extension
26+
export JNI_PATH=$JNI_PATH
27+
export CFLAGS="$CFLAGS -I$JNI_PATH/sdl/include -I$JNI_PATH/sdl_mixer/"
28+
export LDFLAGS="$LDFLAGS -lm -L$LIBS_PATH"
29+
try cd $BUILD_audiostream
30+
$HOSTPYTHON setup.py build_ext &>/dev/null
31+
try find . -iname '*.pyx' -exec $CYTHON {} \;
32+
try $HOSTPYTHON setup.py build_ext -v
33+
try $HOSTPYTHON setup.py install -O2
34+
try cp -a audiostream/platform/android/org $JAVACLASS_PATH
35+
36+
pop_arm
37+
}
38+
39+
function postbuild_audiostream() {
40+
true
41+
}

pythonforandroid/recipes/freetype/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
from pythonforandroid.toolchain import Recipe, shprint, get_directory, current_directory, ArchAndroid
2+
from pythonforandroid.toolchain import Recipe, shprint, get_directory, current_directory, ArchARM
33
from os.path import exists, join, realpath
44
from os import uname
55
import glob
@@ -12,8 +12,8 @@ class FreetypeRecipe(Recipe):
1212

1313
depends = ['harfbuzz']
1414

15-
def should_build(self):
16-
if exists(join(self.get_build_dir('armeabi'), 'objs', '.libs', 'libfreetype.so')):
15+
def should_build(self, arch):
16+
if exists(join(self.get_build_dir(arch.arch), 'objs', '.libs', 'libfreetype.so')):
1717
return False
1818
return True
1919

pythonforandroid/recipes/harfbuzz/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
from pythonforandroid.toolchain import Recipe, shprint, get_directory, current_directory, ArchAndroid
2+
from pythonforandroid.toolchain import Recipe, shprint, get_directory, current_directory, ArchARM
33
from os.path import exists, join, realpath
44
from os import uname
55
import glob
@@ -10,8 +10,8 @@ class HarfbuzzRecipe(Recipe):
1010
version = '0.9.40'
1111
url = 'http://www.freedesktop.org/software/harfbuzz/release/harfbuzz-{version}.tar.bz2'
1212

13-
def should_build(self):
14-
if exists(join(self.get_build_dir('armeabi'), 'src', '.libs', 'libharfbuzz.so')):
13+
def should_build(self, arch):
14+
if exists(join(self.get_build_dir(arch.arch), 'src', '.libs', 'libharfbuzz.so')):
1515
return False
1616
return True
1717

pythonforandroid/recipes/hostpython2/__init__.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,27 @@ class Hostpython2Recipe(Recipe):
1212

1313
conflicts = ['hostpython3']
1414

15-
def prebuild_armeabi(self):
15+
def get_build_container_dir(self, arch=None):
16+
choices = self.check_recipe_choices()
17+
dir_name = '-'.join([self.name] + choices)
18+
return join(self.ctx.build_dir, 'other_builds', dir_name, 'desktop')
19+
20+
def get_build_dir(self, arch=None):
21+
return join(self.get_build_container_dir(), self.name)
22+
23+
def prebuild_arch(self, arch):
1624
# Override hostpython Setup?
1725
shprint(sh.cp, join(self.get_recipe_dir(), 'Setup'),
18-
join(self.get_build_dir('armeabi'), 'Modules', 'Setup'))
19-
20-
def build_armeabi(self):
21-
# AND: Should use an i386 recipe system
22-
warning('Running hostpython build. Arch is armeabi! '
23-
'This is naughty, need to fix the Arch system!')
26+
join(self.get_build_dir(), 'Modules', 'Setup'))
2427

25-
# AND: Fix armeabi again
26-
with current_directory(self.get_build_dir('armeabi')):
28+
def build_arch(self, arch):
29+
with current_directory(self.get_build_dir()):
2730

2831
if exists('hostpython'):
2932
info('hostpython already exists, skipping build')
30-
self.ctx.hostpython = join(self.get_build_dir('armeabi'),
33+
self.ctx.hostpython = join(self.get_build_dir(),
3134
'hostpython')
32-
self.ctx.hostpgen = join(self.get_build_dir('armeabi'),
35+
self.ctx.hostpgen = join(self.get_build_dir(),
3336
'hostpgen')
3437
return
3538

@@ -49,8 +52,8 @@ def build_armeabi(self):
4952
'hostpython build! Exiting.')
5053
exit(1)
5154

52-
self.ctx.hostpython = join(self.get_build_dir('armeabi'), 'hostpython')
53-
self.ctx.hostpgen = join(self.get_build_dir('armeabi'), 'hostpgen')
55+
self.ctx.hostpython = join(self.get_build_dir(), 'hostpython')
56+
self.ctx.hostpgen = join(self.get_build_dir(), 'hostpgen')
5457

5558

5659
recipe = Hostpython2Recipe()

pythonforandroid/recipes/kivy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
from pythonforandroid.toolchain import CythonRecipe, shprint, current_directory, ArchAndroid
2+
from pythonforandroid.toolchain import CythonRecipe, shprint, current_directory, ArchARM
33
from os.path import exists, join
44
import sh
55
import glob

pythonforandroid/recipes/kivysdl2python3/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
from pythonforandroid.toolchain import CythonRecipe, shprint, current_directory, ArchAndroid
2+
from pythonforandroid.toolchain import CythonRecipe, shprint, current_directory, ArchARM
33
from os.path import exists, join
44
import sh
55
import glob
@@ -35,7 +35,7 @@ def get_recipe_env(self, arch):
3535
return env
3636

3737
# def build_armeabi(self):
38-
# env = ArchAndroid(self.ctx).get_env()
38+
# env = ArchARM(self.ctx).get_env()
3939

4040
# env['LDFLAGS'] = env['LDFLAGS'] + ' -L{}'.format(self.ctx.libs_dir)
4141
# env['LDSHARED'] = env['LIBLINK']

pythonforandroid/recipes/numpy/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ def prebuild_arch(self, arch):
2020
print('numpy already patched, skipping')
2121
return
2222

23-
self.apply_patch('patches/fix-numpy.patch')
24-
self.apply_patch('patches/prevent_libs_check.patch')
25-
self.apply_patch('patches/ar.patch')
26-
self.apply_patch('patches/lib.patch')
23+
self.apply_patch('patches/fix-numpy.patch', arch.arch)
24+
self.apply_patch('patches/prevent_libs_check.patch', arch.arch)
25+
self.apply_patch('patches/ar.patch', arch.arch)
26+
self.apply_patch('patches/lib.patch', arch.arch)
2727

2828
# AND: Fix this warning!
2929
warning('Numpy is built assuming the archiver name is '

pythonforandroid/recipes/openssl/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66

77
class OpenSSLRecipe(Recipe):
8-
version = '1.0.2d'
8+
version = '1.0.2e'
99
url = 'https://www.openssl.org/source/openssl-{version}.tar.gz'
1010

11-
def should_build(self):
12-
return not exists(join(self.get_build_dir('armeabi'), 'libssl.a'))
11+
def should_build(self, arch):
12+
return not exists(join(self.get_build_dir(arch.arch), 'libssl.a'))
1313

1414
def build_arch(self, arch):
1515
env = self.get_recipe_env(arch)

pythonforandroid/recipes/pycrypto/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def prebuild_arch(self, arch):
2222
if exists(join(build_dir, '.patched')):
2323
print('pycrypto already patched, skipping')
2424
return
25-
self.apply_patch('add_length.patch')
25+
self.apply_patch('add_length.patch', arch.arch)
2626
shprint(sh.touch, join(build_dir, '.patched'))
2727

2828
def get_recipe_env(self, arch):

0 commit comments

Comments
 (0)