Skip to content

Commit b2a3eaa

Browse files
committed
Adapt service_only's bootstrap to python's recipe and introduce gradle
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.
1 parent 3233518 commit b2a3eaa

40 files changed

+2862
-1725
lines changed

pythonforandroid/bootstraps/service_only/__init__.py

Lines changed: 12 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import glob
2-
from os import walk
3-
from os.path import join, exists, curdir, abspath
41
import sh
5-
from pythonforandroid.toolchain import Bootstrap, current_directory, info, info_main, shprint
2+
from os.path import join
3+
from pythonforandroid.toolchain import (
4+
Bootstrap, current_directory, info, info_main, shprint)
5+
from pythonforandroid.util import ensure_dir
66

77

88
class ServiceOnlyBootstrap(Bootstrap):
99

1010
name = 'service_only'
1111

12-
recipe_depends = ['genericndkbuild', ('python2', 'python3crystax')]
12+
recipe_depends = ['genericndkbuild', ('python2', 'python3', 'python3crystax')]
1313

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

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

34-
if not exists('private') and not self.ctx.python_recipe.from_crystax:
35-
shprint(sh.mkdir, 'private')
36-
if not exists('crystax_python') and self.ctx.python_recipe.from_crystax:
37-
shprint(sh.mkdir, 'crystax_python')
38-
shprint(sh.mkdir, 'crystax_python/crystax_python')
39-
if not exists('assets'):
40-
shprint(sh.mkdir, 'assets')
41-
42-
hostpython = sh.Command(self.ctx.hostpython)
43-
if not self.ctx.python_recipe.from_crystax:
44-
try:
45-
shprint(hostpython, '-OO', '-m', 'compileall',
46-
self.ctx.get_python_install_dir(),
47-
_tail=10, _filterout="^Listing")
48-
except sh.ErrorReturnCode:
49-
pass
50-
if not exists('python-install'):
51-
shprint(sh.cp, '-a', self.ctx.get_python_install_dir(), './python-install')
52-
5333
self.distribute_libs(arch, [self.ctx.get_libs_dir(arch.arch)])
5434
self.distribute_aars(arch)
5535
self.distribute_javaclasses(self.ctx.javaclass_dir)
5636

57-
if not self.ctx.python_recipe.from_crystax:
58-
info('Filling private directory')
59-
if not exists(join('private', 'lib')):
60-
info('private/lib does not exist, making')
61-
shprint(sh.cp, '-a', join('python-install', 'lib'), 'private')
62-
shprint(sh.mkdir, '-p', join('private', 'include', 'python2.7'))
63-
64-
if exists(join('libs', arch.arch, 'libpymodules.so')):
65-
shprint(sh.mv, join('libs', arch.arch, 'libpymodules.so'), 'private/')
66-
shprint(sh.cp, join('python-install', 'include', 'python2.7', 'pyconfig.h'), join('private', 'include', 'python2.7/'))
67-
68-
info('Removing some unwanted files')
69-
shprint(sh.rm, '-f', join('private', 'lib', 'libpython2.7.so'))
70-
shprint(sh.rm, '-rf', join('private', 'lib', 'pkgconfig'))
71-
72-
libdir = join(self.dist_dir, 'private', 'lib', 'python2.7')
73-
site_packages_dir = join(libdir, 'site-packages')
74-
with current_directory(libdir):
75-
# shprint(sh.xargs, 'rm', sh.grep('-E', '*\.(py|pyx|so\.o|so\.a|so\.libs)$', sh.find('.')))
76-
removes = []
77-
for dirname, something, filens in walk('.'):
78-
for filename in filens:
79-
for suffix in ('py', 'pyc', 'so.o', 'so.a', 'so.libs'):
80-
if filename.endswith(suffix):
81-
removes.append(filename)
82-
shprint(sh.rm, '-f', *removes)
83-
84-
info('Deleting some other stuff not used on android')
85-
# To quote the original distribute.sh, 'well...'
86-
# shprint(sh.rm, '-rf', 'ctypes')
87-
shprint(sh.rm, '-rf', 'lib2to3')
88-
shprint(sh.rm, '-rf', 'idlelib')
89-
for filename in glob.glob('config/libpython*.a'):
90-
shprint(sh.rm, '-f', filename)
91-
shprint(sh.rm, '-rf', 'config/python.o')
92-
# shprint(sh.rm, '-rf', 'lib-dynload/_ctypes_test.so')
93-
# shprint(sh.rm, '-rf', 'lib-dynload/_testcapi.so')
94-
95-
else: # Python *is* loaded from crystax
96-
ndk_dir = self.ctx.ndk_dir
97-
py_recipe = self.ctx.python_recipe
98-
python_dir = join(ndk_dir, 'sources', 'python', py_recipe.version,
99-
'libs', arch.arch)
100-
101-
shprint(sh.cp, '-r', join(python_dir, 'stdlib.zip'), 'crystax_python/crystax_python')
102-
shprint(sh.cp, '-r', join(python_dir, 'modules'), 'crystax_python/crystax_python')
103-
shprint(sh.cp, '-r', self.ctx.get_python_install_dir(), 'crystax_python/crystax_python/site-packages')
37+
python_bundle_dir = join('_python_bundle', '_python_bundle')
38+
ensure_dir(python_bundle_dir)
39+
site_packages_dir = self.ctx.python_recipe.create_python_bundle(
40+
join(self.dist_dir, python_bundle_dir), arch)
10441

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

11746
self.strip_libraries(arch)
11847
self.fry_eggs(site_packages_dir)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.gradle
2+
/build/
3+
4+
# Ignore Gradle GUI config
5+
gradle-app.setting
6+
7+
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
8+
!gradle-wrapper.jar
9+
10+
# Cache of project
11+
.gradletasknamecache
12+
13+
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
14+
# gradle/wrapper/gradle-wrapper.properties
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This file is used to override default values used by the Ant build system.
2+
#
3+
# This file must be checked into Version Control Systems, as it is
4+
# integral to the build system of your project.
5+
6+
# This file is only used by the Ant script.
7+
8+
# You can use this to override default values such as
9+
# 'source.dir' for the location of your java source folder and
10+
# 'out.dir' for the location of your output folder.
11+
12+
# You can also use it define how the release builds are signed by declaring
13+
# the following properties:
14+
# 'key.store' for the location of your keystore and
15+
# 'key.alias' for the name of the key to use.
16+
# The password will be asked during the build when you use the 'release' target.
17+
18+
source.absolute.dir = tmp-src
19+
20+
resource.absolute.dir = src/main/res
21+
22+
asset.absolute.dir = src/main/assets

pythonforandroid/bootstraps/service_only/build/build.gradle

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)