Skip to content

Commit 0e700c4

Browse files
committed
Adapt service_only's bootstrap to new python/gradle build system and enables some missing features
Note: Some files has been removed because we will use the generic ones of bootstraps/common
1 parent 024e0c9 commit 0e700c4

File tree

8 files changed

+264
-264
lines changed

8 files changed

+264
-264
lines changed

pythonforandroid/bootstraps/service_only/__init__.py

Lines changed: 11 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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):
@@ -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)

pythonforandroid/bootstraps/service_only/build/build.gradle

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

0 commit comments

Comments
 (0)