Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions pythonforandroid/patching.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from os import uname


def check_all(*callables):
def check(**kwargs):
return all(c(**kwargs) for c in callables)
return check


def check_any(*callables):
def check(**kwargs):
return any(c(**kwargs) for c in callables)
return check


def is_platform(platform):
def is_x(**kwargs):
return uname()[0] == platform
return is_x

is_linux = is_platform('Linux')
is_darwin = is_platform('Darwin')


def is_arch(xarch):
def is_x(arch, **kwargs):
return arch.arch == xarch
return is_x


def is_api_gt(apiver):
def is_x(recipe, **kwargs):
return recipe.ctx.android_api > apiver
return is_x


def is_api_gte(apiver):
def is_x(recipe, **kwargs):
return recipe.ctx.android_api >= apiver
return is_x


def is_api_lt(apiver):
def is_x(recipe, **kwargs):
return recipe.ctx.android_api < apiver
return is_x


def is_api_lte(apiver):
def is_x(recipe, **kwargs):
return recipe.ctx.android_api <= apiver
return is_x


def is_api(apiver):
def is_x(recipe, **kwargs):
return recipe.ctx.android_api == apiver
return is_x


def will_build(recipe_name):
def will(recipe, **kwargs):
return recipe_name in recipe.ctx.recipe_build_order
return will

10 changes: 1 addition & 9 deletions pythonforandroid/recipes/kivysdl2python3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,7 @@ class KivySDL2Recipe(CythonRecipe):
site_packages_name = 'kivy'

depends = ['sdl2', 'python2', 'pyjniussdl2']

def prebuild_arch(self, arch):
super(KivySDL2Recipe, self).prebuild_arch(arch)
build_dir = self.get_build_dir(arch.arch)
if exists(join(build_dir, '.patched')):
print('kivysdl2 already patched, skipping')
return
self.apply_patch('android_sdl2_compat.patch')
shprint(sh.touch, join(build_dir, '.patched'))
patches = ['android_sdl2_compat.patch']

def get_recipe_env(self, arch):
env = super(KivySDL2Recipe, self).get_recipe_env(arch)
Expand Down
21 changes: 6 additions & 15 deletions pythonforandroid/recipes/numpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@

from pythonforandroid.toolchain import CompiledComponentsPythonRecipe, shprint, current_directory, warning
from os.path import exists, join
import sh
import glob
from pythonforandroid.toolchain import CompiledComponentsPythonRecipe, warning


class NumpyRecipe(CompiledComponentsPythonRecipe):
Expand All @@ -13,23 +10,17 @@ class NumpyRecipe(CompiledComponentsPythonRecipe):

depends = ['python2']

patches = ['patches/fix-numpy.patch',
'patches/prevent_libs_check.patch',
'patches/ar.patch',
'patches/lib.patch']

def prebuild_arch(self, arch):
super(NumpyRecipe, self).prebuild_arch(arch)
build_dir = self.get_build_dir(arch.arch)
if exists(join(build_dir, '.patched')):
print('numpy already patched, skipping')
return

self.apply_patch('patches/fix-numpy.patch', arch.arch)
self.apply_patch('patches/prevent_libs_check.patch', arch.arch)
self.apply_patch('patches/ar.patch', arch.arch)
self.apply_patch('patches/lib.patch', arch.arch)

# AND: Fix this warning!
warning('Numpy is built assuming the archiver name is '
'arm-linux-androideabi-ar, which may not always be true!')

shprint(sh.touch, join(build_dir, '.patched'))


recipe = NumpyRecipe()
14 changes: 3 additions & 11 deletions pythonforandroid/recipes/pycrypto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,18 @@
info,
shprint,
)
from os.path import exists, join, realpath
from os.path import join
import sh
import glob


class PyCryptoRecipe(CompiledComponentsPythonRecipe):
version = '2.6.1'
url = 'https://pypi.python.org/packages/source/p/pycrypto/pycrypto-{version}.tar.gz'
depends = ['openssl', 'python2']

def prebuild_arch(self, arch):
super(PyCryptoRecipe, self).prebuild_arch(arch)
build_dir = self.get_build_dir(arch.arch)
if exists(join(build_dir, '.patched')):
print('pycrypto already patched, skipping')
return
self.apply_patch('add_length.patch', arch.arch)
shprint(sh.touch, join(build_dir, '.patched'))
patches = ['add_length.patch']

def get_recipe_env(self, arch):
def get_recipe_env(self, arch=None):
env = super(PyCryptoRecipe, self).get_recipe_env(arch)
openssl_build_dir = Recipe.get_recipe('openssl', self.ctx).get_build_dir(arch.arch)
env['CC'] = '%s -I%s' % (env['CC'], join(openssl_build_dir, 'include'))
Expand Down
13 changes: 6 additions & 7 deletions pythonforandroid/recipes/pygame/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ class PygameRecipe(Recipe):
depends = ['python2', 'sdl']
conflicts = ['sdl2']

def get_recipe_env(self, arch):
patches = ['fix-surface-access.patch',
'fix-array-surface.patch',
'fix-sdl-spam-log.patch']

def get_recipe_env(self, arch=None):
env = super(PygameRecipe, self).get_recipe_env(arch)
env['LDFLAGS'] = env['LDFLAGS'] + ' -L{}'.format(
self.ctx.get_libs_dir(arch.arch))
Expand All @@ -27,15 +31,10 @@ def get_recipe_env(self, arch):
return env

def prebuild_arch(self, arch):
if exists(join(self.get_build_container_dir(arch.arch), '.patched')):
info('Pygame already patched, skipping.')
if self.is_patched(arch):
return
shprint(sh.cp, join(self.get_recipe_dir(), 'Setup'),
join(self.get_build_dir(arch.arch), 'Setup'))
self.apply_patch(join('patches', 'fix-surface-access.patch'), arch.arch)
self.apply_patch(join('patches', 'fix-array-surface.patch'), arch.arch)
self.apply_patch(join('patches', 'fix-sdl-spam-log.patch'), arch.arch)
shprint(sh.touch, join(self.get_build_container_dir(arch.arch), '.patched'))

def build_arch(self, arch):
# AND: I'm going to ignore any extra pythonrecipe or cythonrecipe behaviour for now
Expand Down
19 changes: 6 additions & 13 deletions pythonforandroid/recipes/pyjnius/__init__.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@

from pythonforandroid.toolchain import CythonRecipe, shprint, ArchARM, current_directory, info
from pythonforandroid.toolchain import CythonRecipe, shprint, current_directory, info
from pythonforandroid.patching import will_build
import sh
import glob
from os.path import join, exists
from os.path import join


class PyjniusRecipe(CythonRecipe):
version = 'master'
version = 'master'
url = 'https://github.com/kivy/pyjnius/archive/{version}.zip'
name = 'pyjnius'
depends = ['python2', ('sdl2', 'sdl'), 'six']
site_packages_name = 'jnius'
def prebuild_arch(self, arch):
super(PyjniusRecipe, self).prebuild_arch(arch)
if 'sdl2' in self.ctx.recipe_build_order:
build_dir = self.get_build_dir(arch.arch)
if exists(join(build_dir, '.patched')):
print('pyjniussdl2 already pathed, skipping')
return
self.apply_patch('sdl2_jnienv_getter.patch', arch.arch)
shprint(sh.touch, join(build_dir, '.patched'))

patches = [('sdl2_jnienv_getter.patch', will_build('sdl2')]

def postbuild_arch(self, arch):
super(PyjniusRecipe, self).postbuild_arch(arch)
Expand Down
59 changes: 22 additions & 37 deletions pythonforandroid/recipes/python2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

from pythonforandroid.toolchain import Recipe, shprint, get_directory, current_directory, ArchARM, info
from pythonforandroid.toolchain import Recipe, shprint, current_directory, info
from pythonforandroid.patching import is_linux, is_darwin, is_api_gt
from os.path import exists, join, realpath
from os import uname
import glob
import sh


Expand All @@ -14,39 +13,25 @@ class Python2Recipe(Recipe):
depends = ['hostpython2']
conflicts = ['python3']
opt_depends = ['openssl']

def prebuild_arch(self, arch):
build_dir = self.get_build_container_dir(arch.arch)
if exists(join(build_dir, '.patched')):
info('Python2 already patched, skipping.')
return
self.apply_patch(join('patches', 'Python-{}-xcompile.patch'.format(self.version)),
arch.arch)
self.apply_patch(join('patches', 'Python-{}-ctypes-disable-wchar.patch'.format(self.version)),
arch.arch)
self.apply_patch(join('patches', 'disable-modules.patch'), arch.arch)
self.apply_patch(join('patches', 'fix-locale.patch'), arch.arch)
self.apply_patch(join('patches', 'fix-gethostbyaddr.patch'), arch.arch)
self.apply_patch(join('patches', 'fix-setup-flags.patch'), arch.arch)
self.apply_patch(join('patches', 'fix-filesystemdefaultencoding.patch'), arch.arch)
self.apply_patch(join('patches', 'fix-termios.patch'), arch.arch)
self.apply_patch(join('patches', 'custom-loader.patch'), arch.arch)
self.apply_patch(join('patches', 'verbose-compilation.patch'), arch.arch)
self.apply_patch(join('patches', 'fix-remove-corefoundation.patch'), arch.arch)
self.apply_patch(join('patches', 'fix-dynamic-lookup.patch'), arch.arch)
self.apply_patch(join('patches', 'fix-dlfcn.patch'), arch.arch)
self.apply_patch(join('patches', 'parsetuple.patch'), arch.arch)
# self.apply_patch(join('patches', 'ctypes-find-library.patch'), arch.arch)
self.apply_patch(join('patches', 'ctypes-find-library-updated.patch'), arch.arch)

if uname()[0] == 'Linux':
self.apply_patch(join('patches', 'fix-configure-darwin.patch'), arch.arch)
self.apply_patch(join('patches', 'fix-distutils-darwin.patch'), arch.arch)

if self.ctx.android_api > 19:
self.apply_patch(join('patches', 'fix-ftime-removal.patch'), arch.arch)

shprint(sh.touch, join(build_dir, '.patched'))

patches = ['patches/Python-{version}-xcompile.patch',
'patches/Python-{version}-ctypes-disable-wchar.patch',
'patches/disable-modules.patch',
'patches/fix-locale.patch',
'patches/fix-gethostbyaddr.patch',
'patches/fix-setup-flags.patch',
'patches/fix-filesystemdefaultencoding.patch',
'patches/fix-termios.patch',
'patches/custom-loader.patch',
'patches/verbose-compilation.patch',
'patches/fix-remove-corefoundation.patch',
'patches/fix-dynamic-lookup.patch',
'patches/fix-dlfcn.patch',
'patches/parsetuple.patch',
'patches/ctypes-find-library-updated.patch',
('patches/fix-configure-darwin.patch', is_linux),
('patches/fix-distutils-darwin.patch', is_linux),
('patches/fix-ftime-removal.patch', is_api_gt(19))]

def build_arch(self, arch):

Expand Down Expand Up @@ -151,7 +136,7 @@ def do_python_build(self, arch):
'INSTSONAME=libpython2.7.so',
_env=env)

if uname()[0] == 'Darwin':
if is_darwin():
shprint(sh.cp, join(self.get_recipe_dir(), 'patches', '_scproxy.py'),
join('python-install', 'Lib'))
shprint(sh.cp, join(self.get_recipe_dir(), 'patches', '_scproxy.py'),
Expand Down
9 changes: 1 addition & 8 deletions pythonforandroid/recipes/sdl2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,7 @@ class LibSDL2Recipe(NDKRecipe):
depends = ['python2', 'sdl2_image', 'sdl2_mixer', 'sdl2_ttf']
conflicts = ['sdl', 'pygame', 'pygame_bootstrap_components']

def prebuild_arch(self, arch):
super(LibSDL2Recipe, self).prebuild_arch(arch)
build_dir = self.get_build_dir(arch.arch)
if exists(join(build_dir, '.patched')):
info('SDL2 already patched, skipping')
return
self.apply_patch('add_nativeSetEnv.patch', arch.arch)
shprint(sh.touch, join(build_dir, '.patched'))
patches = ['add_nativeSetEnv.patch']

def build_arch(self, arch):
env = self.get_recipe_env(arch)
Expand Down
21 changes: 7 additions & 14 deletions pythonforandroid/recipes/sdl2_image/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
from pythonforandroid.toolchain import NDKRecipe, shprint, info
from os.path import exists, join
import sh
from pythonforandroid.toolchain import NDKRecipe
from pythonforandroid.patching import is_arch


class LibSDL2Image(NDKRecipe):
version = '2.0.0'
url = 'https://www.libsdl.org/projects/SDL_image/release/SDL2_image-{version}.tar.gz'
dir_name = 'SDL2_image'

def prebuild_arch(self, arch):
super(LibSDL2Image, self).prebuild_arch(arch)
build_dir = self.get_build_dir(arch.arch)
if exists(join(build_dir, '.patched')):
info('SDL2_image already patched, skipping')
return
self.apply_patch('disable_webp.patch', arch.arch)
if arch.arch == 'x86':
self.apply_patch('disable_jpg.patch', arch.arch)
shprint(sh.touch, join(build_dir, '.patched'))

patches = ['disable_webp.patch',
('disable_jpg.patch', is_arch('x86'))]


recipe = LibSDL2Image()
15 changes: 3 additions & 12 deletions pythonforandroid/recipes/sdl2_mixer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
from pythonforandroid.toolchain import NDKRecipe, shprint, info
from os.path import exists, join
import sh
from pythonforandroid.toolchain import NDKRecipe


class LibSDL2Mixer(NDKRecipe):
version = '2.0.0'
url = 'https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-{version}.tar.gz'
dir_name = 'SDL2_mixer'

def prebuild_arch(self, arch):
super(LibSDL2Mixer, self).prebuild_arch(arch)
build_dir = self.get_build_dir(arch.arch)
patches = ['disable_modplug_mikmod_smpeg.patch']

if exists(join(build_dir, '.patched')):
info('SDL2_mixer already patched, skipping')
return
self.apply_patch('disable_modplug_mikmod_smpeg.patch',
arch.arch)
shprint(sh.touch, join(build_dir, '.patched'))

recipe = LibSDL2Mixer()
13 changes: 2 additions & 11 deletions pythonforandroid/recipes/sdl2python3/__init__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
from pythonforandroid.toolchain import NDKRecipe, shprint, current_directory, info_main
from os.path import exists, join
from pythonforandroid.toolchain import NDKRecipe, shprint, current_directory
import sh



class LibSDL2Recipe(NDKRecipe):
version = "2.0.3"
url = "https://www.libsdl.org/release/SDL2-{version}.tar.gz"
depends = ['python3', 'sdl2_image', 'sdl2_mixer', 'sdl2_ttf']
# depends = ['python2']
dir_name = 'SDL'

def prebuild_arch(self, arch):
super(LibSDL2Recipe, self).prebuild_arch(arch)
build_dir = self.get_build_dir(arch.arch)
if exists(join(build_dir, '.patched')):
print('SDL2 already patched, skipping')
return
self.apply_patch('add_nativeSetEnv.patch', arch.arch)
shprint(sh.touch, join(build_dir, '.patched'))
patches = ['add_nativeSetEnv.patch']

def build_arch(self, arch):
env = self.get_recipe_env(arch)
Expand Down
Loading