1
- import glob
2
- from os import walk
3
- from os .path import join , exists , curdir , abspath
4
1
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
6
6
7
7
8
8
class ServiceOnlyBootstrap (Bootstrap ):
9
9
10
10
name = 'service_only'
11
11
12
- recipe_depends = ['genericndkbuild' , ('python2' , 'python3crystax' )]
12
+ recipe_depends = ['genericndkbuild' , ('python2' , 'python3' , ' python3crystax' )]
13
13
14
14
def run_distribute (self ):
15
15
info_main ('# Creating Android project from build and {} bootstrap' .format (
@@ -21,7 +21,6 @@ def run_distribute(self):
21
21
with current_directory (self .dist_dir ):
22
22
with open ('local.properties' , 'w' ) as fileh :
23
23
fileh .write ('sdk.dir={}' .format (self .ctx .sdk_dir ))
24
- fileh .write ('ndk.dir={}' .format (self .ctx .ndk_dir ))
25
24
26
25
arch = self .ctx .archs [0 ]
27
26
if len (self .ctx .archs ) > 1 :
@@ -31,88 +30,18 @@ def run_distribute(self):
31
30
with current_directory (self .dist_dir ):
32
31
info ('Copying python distribution' )
33
32
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
-
53
33
self .distribute_libs (arch , [self .ctx .get_libs_dir (arch .arch )])
54
34
self .distribute_aars (arch )
55
35
self .distribute_javaclasses (self .ctx .javaclass_dir )
56
36
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 )
104
41
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 ('\n sqlite3/*\n lib-dynload/_sqlite3.so\n ' )
116
45
117
46
self .strip_libraries (arch )
118
47
self .fry_eggs (site_packages_dir )
0 commit comments