Skip to content
Closed
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
34 changes: 33 additions & 1 deletion pythonforandroid/bootstraps/pygame/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from pythonforandroid.toolchain import Bootstrap, shprint, current_directory, info, warning, ArchAndroid, logger, info_main, which
from os.path import join, exists
from os.path import join, exists, basename, splitext
from os import walk
import glob
import sh
from tempfile import mkdtemp
from shutil import rmtree


class PygameBootstrap(Bootstrap):
Expand Down Expand Up @@ -44,6 +46,36 @@ def run_distribute(self):
if not exists('python-install'):
shprint(sh.cp, '-a', self.ctx.get_python_install_dir(), './python-install')

info('Unpacking aars')
for aar in glob.glob(join(self.ctx.aars_dir, '*.aar')):
temp_dir = mkdtemp()
name = splitext(basename(aar))[0]
jar_name = name + '.jar'
info("unpack {} jar".format(name))
info(" from {}".format(aar))
info(" to {}".format(temp_dir))
shprint(sh.unzip, '-o', aar, '-d', temp_dir)

jar_src = join(temp_dir, 'classes.jar')
jar_tgt = join('libs', jar_name)
info("cp {} jar".format(name))
info(" from {}".format(jar_src))
info(" to {}".format(jar_tgt))
shprint(sh.mkdir, '-p', 'libs')
shprint(sh.cp, '-a',jar_src, jar_tgt)

so_src_dir = join(temp_dir, 'jni', 'armeabi')
so_tgt_dir = join('libs', 'armeabi')
info("cp {} .so".format(name))
info(" from {}".format(so_src_dir))
info(" to {}".format(so_tgt_dir))
shprint(sh.mkdir, '-p', so_tgt_dir)
so_files = glob.glob(join(so_src_dir, '*.so'))
for f in so_files:
shprint(sh.cp, '-a', f, so_tgt_dir)

rmtree(temp_dir)

info('Copying libs')
# AND: Hardcoding armeabi - naughty!
shprint(sh.mkdir, '-p', join('libs', 'armeabi'))
Expand Down
32 changes: 32 additions & 0 deletions pythonforandroid/bootstraps/sdl2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from os import walk
import glob
import sh
from tempfile import mkdtemp
from shutil import rmtree

class SDL2Bootstrap(Bootstrap):
name = 'sdl2'
Expand Down Expand Up @@ -35,6 +37,36 @@ def run_distribute(self):
if not exists('python-install'):
shprint(sh.cp, '-a', self.ctx.get_python_install_dir(), './python-install')

info('Unpacking aars')
for aar in glob.glob(join(self.ctx.aars_dir, '*.aar')):
temp_dir = mkdtemp()
name = splitext(basename(aar))[0]
jar_name = name + '.jar'
info("unpack {} jar".format(name))
info(" from {}".format(aar))
info(" to {}".format(temp_dir))
shprint(sh.unzip, '-o', aar, '-d', temp_dir)

jar_src = join(temp_dir, 'classes.jar')
jar_tgt = join('libs', jar_name)
info("cp {} jar".format(name))
info(" from {}".format(jar_src))
info(" to {}".format(jar_tgt))
shprint(sh.mkdir, '-p', 'libs')
shprint(sh.cp, '-a',jar_src, jar_tgt)

so_src_dir = join(temp_dir, 'jni', 'armeabi')
so_tgt_dir = join('libs', 'armeabi')
info("cp {} .so".format(name))
info(" from {}".format(so_src_dir))
info(" to {}".format(so_tgt_dir))
shprint(sh.mkdir, '-p', so_tgt_dir)
so_files = glob.glob(join(so_src_dir, '*.so'))
for f in so_files:
shprint(sh.cp, '-a', f, so_tgt_dir)

rmtree(temp_dir)

info('Copying libs')
# AND: Hardcoding armeabi - naughty!
shprint(sh.mkdir, '-p', join('libs', 'armeabi'))
Expand Down
32 changes: 32 additions & 0 deletions pythonforandroid/bootstraps/sdl2python3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from os import walk
import glob
import sh
from tempfile import mkdtemp
from shutil import rmtree

class SDL2Bootstrap(Bootstrap):
name = 'sdl2python3'
Expand Down Expand Up @@ -37,6 +39,36 @@ def run_distribute(self):
if not exists('python-install'):
shprint(sh.cp, '-a', join(self.ctx.build_dir, 'python-install'), '.')

info('Unpacking aars')
for aar in glob.glob(join(self.ctx.aars_dir, '*.aar')):
temp_dir = mkdtemp()
name = splitext(basename(aar))[0]
jar_name = name + '.jar'
info("unpack {} jar".format(name))
info(" from {}".format(aar))
info(" to {}".format(temp_dir))
shprint(sh.unzip, '-o', aar, '-d', temp_dir)

jar_src = join(temp_dir, 'classes.jar')
jar_tgt = join('libs', jar_name)
info("cp {} jar".format(name))
info(" from {}".format(jar_src))
info(" to {}".format(jar_tgt))
shprint(sh.mkdir, '-p', 'libs')
shprint(sh.cp, '-a',jar_src, jar_tgt)

so_src_dir = join(temp_dir, 'jni', 'armeabi')
so_tgt_dir = join('libs', 'armeabi')
info("cp {} .so".format(name))
info(" from {}".format(so_src_dir))
info(" to {}".format(so_tgt_dir))
shprint(sh.mkdir, '-p', so_tgt_dir)
so_files = glob.glob(join(so_src_dir, '*.so'))
for f in so_files:
shprint(sh.cp, '-a', f, so_tgt_dir)

rmtree(temp_dir)

info('Copying libs')
# AND: Hardcoding armeabi - naughty!
shprint(sh.mkdir, '-p', join('libs', 'armeabi'))
Expand Down
1 change: 1 addition & 0 deletions pythonforandroid/recipes/pygame/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def prebuild_armeabi(self):
join(self.get_build_dir('armeabi'), 'Setup'))
self.apply_patch(join('patches', 'fix-surface-access.patch'))
self.apply_patch(join('patches', 'fix-array-surface.patch'))
self.apply_patch(join('patches', 'fix-sdl-spam-log.patch'))
shprint(sh.touch, join(self.get_build_container_dir('armeabi'), '.patched'))

def build_armeabi(self):
Expand Down
47 changes: 47 additions & 0 deletions pythonforandroid/recipes/pygame/patches/fix-sdl-spam-log.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
--- pygame-1.9.1release/src/joystick.c.orig
+++ pygame-1.9.1release/src/joystick.c
@@ -201,7 +201,7 @@ joy_get_axis (PyObject* self, PyObject* args)
}

value = SDL_JoystickGetAxis (joy, axis);
- printf("SDL_JoystickGetAxis value:%d:\n", value);
+/* printf("SDL_JoystickGetAxis value:%d:\n", value); */


return PyFloat_FromDouble (value / 32768.0);
@@ -241,7 +241,7 @@ joy_get_button (PyObject* self, PyObject* args)
}

value = SDL_JoystickGetButton (joy, _index);
- printf("SDL_JoystickGetButton value:%d:\n", value);
+/* printf("SDL_JoystickGetButton value:%d:\n", value); */

return PyInt_FromLong (value);
}
@@ -277,7 +277,7 @@ joy_get_ball (PyObject* self, PyObject* args)
return RAISE (PyExc_SDLError, "Joystick not initialized");
}
value = SDL_JoystickNumBalls (joy);
- printf("SDL_JoystickNumBalls value:%d:\n", value);
+/* printf("SDL_JoystickNumBalls value:%d:\n", value); */

if (_index < 0 || _index >= value) {
return RAISE (PyExc_SDLError, "Invalid joystick trackball");
@@ -300,7 +300,7 @@ joy_get_numhats (PyObject* self)
}

value = SDL_JoystickNumHats (joy);
- printf("SDL_JoystickNumHats value:%d:\n", value);
+/* printf("SDL_JoystickNumHats value:%d:\n", value); */

return PyInt_FromLong (value);
}
@@ -327,7 +327,7 @@ joy_get_hat (PyObject* self, PyObject* args)

px = py = 0;
value = SDL_JoystickGetHat (joy, _index);
- printf("SDL_JoystickGetHat value:%d:\n", value);
+/* printf("SDL_JoystickGetHat value:%d:\n", value); */

if (value & SDL_HAT_UP) {
py = 1;
61 changes: 61 additions & 0 deletions pythonforandroid/recipes/vlc/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from pythonforandroid.toolchain import Recipe, shprint, current_directory, info, warning
from os.path import exists, join, expanduser, basename
from os import environ
import sh
import glob

class VlcRecipe(Recipe):
version = '3.0.0'
url = None
name = 'vlc'

depends = ['pyjnius', 'android', 'kivy']

port_git = 'http://git.videolan.org/git/vlc-ports/android.git'
vlc_git = 'http://git.videolan.org/git/vlc.git'

def prebuild_arch(self, arch):
super(VlcRecipe, self).prebuild_arch(arch)
build_dir = self.get_build_dir(arch.arch)
port_dir = join(build_dir, 'vlc-port-android')
aar_path = join(port_dir, 'libvlc', 'build', 'outputs', 'aar')
aar = environ.get('LIBVLC_AAR',
join(aar_path, 'libvlc-{}.aar'.format(self.version)))
jar = join(build_dir, 'libvlc.jar')
if not exists(aar):
if not environ.has_key('LIBVLC_AAR'):
warning("set path to ready libvlc-<ver>.aar bundle in LIBVLC_AAR environment!")
info("libvlc-<ver>.aar for android not found!")
info("should build sources at {}".format(port_dir))
if not exists(join(port_dir, 'compile.sh')):
info("clone vlc port for android sources from {}".format(self.port_git))
shprint(sh.git, 'clone', self.port_git, port_dir)
vlc_dir = join(port_dir, 'vlc')
if not exists(join(vlc_dir, 'Makefile.am')):
info("clone vlc sources from {}".format(self.vlc_git))
shprint(sh.git, 'clone', self.vlc_git, vlc_dir)

def build_arch(self, arch):
super(VlcRecipe, self).build_arch(arch)
build_dir = self.get_build_dir(arch.arch)
port_dir = join(build_dir, 'vlc-port-android')
aar_path = join(port_dir, 'libvlc', 'build', 'outputs', 'aar')
aar = environ.get('LIBVLC_AAR',
join(aar_path, 'libvlc-{}.aar'.format(self.version)))
jar = join(build_dir, 'libvlc.jar')
if not exists(aar):
with current_directory(port_dir):
env = dict(environ)
env.update({
'ANDROID_ABI': arch.arch,
'ANDROID_NDK': self.ctx.ndk_dir,
'ANDROID_SDK': self.ctx.sdk_dir,
})
info("compile vlc from sources")
info("environment: {}".format(env))
if not exists(join(port_dir, 'bin', 'VLC-debug.apk')):
shprint(sh.Command('./compile.sh'), _env=env)
shprint(sh.Command('./compile-libvlc.sh'), _env=env)
shprint(sh.cp, '-a', aar, self.ctx.aars_dir)

recipe = VlcRecipe()
7 changes: 7 additions & 0 deletions pythonforandroid/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ class Context(object):
dist_dir = None # the Android project folder where everything ends up
libs_dir = None # where Android libs are cached after build but
# before being placed in dists
aars_dir = None
javaclass_dir = None
ccache = None # whether to use ccache
cython = None # the cython interpreter name
Expand Down Expand Up @@ -566,6 +567,12 @@ def javaclass_dir(self):
ensure_dir(dir)
return dir

@property
def aars_dir(self):
dir = join(self.build_dir, 'aars', self.bootstrap.distribution.name)
ensure_dir(dir)
return dir

@property
def python_installs_dir(self):
dir = join(self.build_dir, 'python-installs')
Expand Down