Skip to content

Commit

Permalink
Adapt service_only's bootstrap to python's recipe and introduce gradle
Browse files Browse the repository at this point in the history
The service_only bootstrap was broken since the update of python recipe, plus it was using the ant's tool to build the apk and this was causing troubles while compiling with latest android ndk (kivy#1069)...so...here we move the apk build tool from ant to gradle (the same build system than the other bootstrap: sdl2 and webview). This changes will allow us to grant python3's compatibility for service_only's bootstrap in a near future.

Also with this update, some of the args disabled for this bootstrap has been enabled (e.g.: application's icon or  the aar dependency). The presplash was leaved out from those additions but maybe it should be included as well.

The gradle changes are based on previously work done by @inclement and @tito for sdl2 bootstrap while introducing gradle (kivy#1071) and on the recent changes applied to the webview's bootstrap.
  • Loading branch information
opacam committed Nov 25, 2018
1 parent 3233518 commit b2a3eaa
Show file tree
Hide file tree
Showing 40 changed files with 2,862 additions and 1,725 deletions.
95 changes: 12 additions & 83 deletions pythonforandroid/bootstraps/service_only/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import glob
from os import walk
from os.path import join, exists, curdir, abspath
import sh
from pythonforandroid.toolchain import Bootstrap, current_directory, info, info_main, shprint
from os.path import join
from pythonforandroid.toolchain import (
Bootstrap, current_directory, info, info_main, shprint)
from pythonforandroid.util import ensure_dir


class ServiceOnlyBootstrap(Bootstrap):

name = 'service_only'

recipe_depends = ['genericndkbuild', ('python2', 'python3crystax')]
recipe_depends = ['genericndkbuild', ('python2', 'python3', 'python3crystax')]

def run_distribute(self):
info_main('# Creating Android project from build and {} bootstrap'.format(
Expand All @@ -21,7 +21,6 @@ def run_distribute(self):
with current_directory(self.dist_dir):
with open('local.properties', 'w') as fileh:
fileh.write('sdk.dir={}'.format(self.ctx.sdk_dir))
fileh.write('ndk.dir={}'.format(self.ctx.ndk_dir))

arch = self.ctx.archs[0]
if len(self.ctx.archs) > 1:
Expand All @@ -31,88 +30,18 @@ def run_distribute(self):
with current_directory(self.dist_dir):
info('Copying python distribution')

if not exists('private') and not self.ctx.python_recipe.from_crystax:
shprint(sh.mkdir, 'private')
if not exists('crystax_python') and self.ctx.python_recipe.from_crystax:
shprint(sh.mkdir, 'crystax_python')
shprint(sh.mkdir, 'crystax_python/crystax_python')
if not exists('assets'):
shprint(sh.mkdir, 'assets')

hostpython = sh.Command(self.ctx.hostpython)
if not self.ctx.python_recipe.from_crystax:
try:
shprint(hostpython, '-OO', '-m', 'compileall',
self.ctx.get_python_install_dir(),
_tail=10, _filterout="^Listing")
except sh.ErrorReturnCode:
pass
if not exists('python-install'):
shprint(sh.cp, '-a', self.ctx.get_python_install_dir(), './python-install')

self.distribute_libs(arch, [self.ctx.get_libs_dir(arch.arch)])
self.distribute_aars(arch)
self.distribute_javaclasses(self.ctx.javaclass_dir)

if not self.ctx.python_recipe.from_crystax:
info('Filling private directory')
if not exists(join('private', 'lib')):
info('private/lib does not exist, making')
shprint(sh.cp, '-a', join('python-install', 'lib'), 'private')
shprint(sh.mkdir, '-p', join('private', 'include', 'python2.7'))

if exists(join('libs', arch.arch, 'libpymodules.so')):
shprint(sh.mv, join('libs', arch.arch, 'libpymodules.so'), 'private/')
shprint(sh.cp, join('python-install', 'include', 'python2.7', 'pyconfig.h'), join('private', 'include', 'python2.7/'))

info('Removing some unwanted files')
shprint(sh.rm, '-f', join('private', 'lib', 'libpython2.7.so'))
shprint(sh.rm, '-rf', join('private', 'lib', 'pkgconfig'))

libdir = join(self.dist_dir, 'private', 'lib', 'python2.7')
site_packages_dir = join(libdir, 'site-packages')
with current_directory(libdir):
# shprint(sh.xargs, 'rm', sh.grep('-E', '*\.(py|pyx|so\.o|so\.a|so\.libs)$', sh.find('.')))
removes = []
for dirname, something, filens in walk('.'):
for filename in filens:
for suffix in ('py', 'pyc', 'so.o', 'so.a', 'so.libs'):
if filename.endswith(suffix):
removes.append(filename)
shprint(sh.rm, '-f', *removes)

info('Deleting some other stuff not used on android')
# To quote the original distribute.sh, 'well...'
# shprint(sh.rm, '-rf', 'ctypes')
shprint(sh.rm, '-rf', 'lib2to3')
shprint(sh.rm, '-rf', 'idlelib')
for filename in glob.glob('config/libpython*.a'):
shprint(sh.rm, '-f', filename)
shprint(sh.rm, '-rf', 'config/python.o')
# shprint(sh.rm, '-rf', 'lib-dynload/_ctypes_test.so')
# shprint(sh.rm, '-rf', 'lib-dynload/_testcapi.so')

else: # Python *is* loaded from crystax
ndk_dir = self.ctx.ndk_dir
py_recipe = self.ctx.python_recipe
python_dir = join(ndk_dir, 'sources', 'python', py_recipe.version,
'libs', arch.arch)

shprint(sh.cp, '-r', join(python_dir, 'stdlib.zip'), 'crystax_python/crystax_python')
shprint(sh.cp, '-r', join(python_dir, 'modules'), 'crystax_python/crystax_python')
shprint(sh.cp, '-r', self.ctx.get_python_install_dir(), 'crystax_python/crystax_python/site-packages')
python_bundle_dir = join('_python_bundle', '_python_bundle')
ensure_dir(python_bundle_dir)
site_packages_dir = self.ctx.python_recipe.create_python_bundle(
join(self.dist_dir, python_bundle_dir), arch)

info('Renaming .so files to reflect cross-compile')
site_packages_dir = 'crystax_python/crystax_python/site-packages'
filens = shprint(sh.find, site_packages_dir, '-iname', '*.so').stdout.decode(
'utf-8').split('\n')[:-1]
for filen in filens:
parts = filen.split('.')
if len(parts) <= 2:
continue
shprint(sh.mv, filen, filen.split('.')[0] + '.so')
site_packages_dir = join(abspath(curdir),
site_packages_dir)
if 'sqlite3' not in self.ctx.recipe_build_order:
with open('blacklist.txt', 'a') as fileh:
fileh.write('\nsqlite3/*\nlib-dynload/_sqlite3.so\n')

self.strip_libraries(arch)
self.fry_eggs(site_packages_dir)
Expand Down
14 changes: 14 additions & 0 deletions pythonforandroid/bootstraps/service_only/build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.gradle
/build/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Cache of project
.gradletasknamecache

# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties
22 changes: 22 additions & 0 deletions pythonforandroid/bootstraps/service_only/build/ant.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This file is used to override default values used by the Ant build system.
#
# This file must be checked into Version Control Systems, as it is
# integral to the build system of your project.

# This file is only used by the Ant script.

# You can use this to override default values such as
# 'source.dir' for the location of your java source folder and
# 'out.dir' for the location of your output folder.

# You can also use it define how the release builds are signed by declaring
# the following properties:
# 'key.store' for the location of your keystore and
# 'key.alias' for the name of the key to use.
# The password will be asked during the build when you use the 'release' target.

source.absolute.dir = tmp-src

resource.absolute.dir = src/main/res

asset.absolute.dir = src/main/assets
21 changes: 0 additions & 21 deletions pythonforandroid/bootstraps/service_only/build/build.gradle

This file was deleted.

Loading

0 comments on commit b2a3eaa

Please sign in to comment.