1
1
from pythonforandroid .toolchain import Bootstrap , current_directory , info , info_main , shprint
2
- from os .path import join , exists , curdir , abspath
3
- from os import walk
4
- import glob
2
+ from pythonforandroid .util import ensure_dir
3
+ from os .path import join
5
4
import sh
6
5
7
6
@@ -28,88 +27,18 @@ def run_distribute(self):
28
27
with current_directory (self .dist_dir ):
29
28
info ('Copying python distribution' )
30
29
31
- if not exists ('private' ) and not self .ctx .python_recipe .from_crystax :
32
- shprint (sh .mkdir , 'private' )
33
- if not exists ('crystax_python' ) and self .ctx .python_recipe .from_crystax :
34
- shprint (sh .mkdir , 'crystax_python' )
35
- shprint (sh .mkdir , 'crystax_python/crystax_python' )
36
- if not exists ('assets' ):
37
- shprint (sh .mkdir , 'assets' )
38
-
39
- hostpython = sh .Command (self .ctx .hostpython )
40
- if not self .ctx .python_recipe .from_crystax :
41
- try :
42
- shprint (hostpython , '-OO' , '-m' , 'compileall' ,
43
- self .ctx .get_python_install_dir (),
44
- _tail = 10 , _filterout = "^Listing" )
45
- except sh .ErrorReturnCode :
46
- pass
47
- if not exists ('python-install' ):
48
- shprint (sh .cp , '-a' , self .ctx .get_python_install_dir (), './python-install' )
49
-
50
30
self .distribute_libs (arch , [self .ctx .get_libs_dir (arch .arch )])
51
31
self .distribute_aars (arch )
52
32
self .distribute_javaclasses (self .ctx .javaclass_dir )
53
33
54
- if not self .ctx .python_recipe .from_crystax :
55
- info ('Filling private directory' )
56
- if not exists (join ('private' , 'lib' )):
57
- info ('private/lib does not exist, making' )
58
- shprint (sh .cp , '-a' , join ('python-install' , 'lib' ), 'private' )
59
- shprint (sh .mkdir , '-p' , join ('private' , 'include' , 'python2.7' ))
60
-
61
- if exists (join ('libs' , arch .arch , 'libpymodules.so' )):
62
- shprint (sh .mv , join ('libs' , arch .arch , 'libpymodules.so' ), 'private/' )
63
- shprint (sh .cp , join ('python-install' , 'include' , 'python2.7' , 'pyconfig.h' ), join ('private' , 'include' , 'python2.7/' ))
64
-
65
- info ('Removing some unwanted files' )
66
- shprint (sh .rm , '-f' , join ('private' , 'lib' , 'libpython2.7.so' ))
67
- shprint (sh .rm , '-rf' , join ('private' , 'lib' , 'pkgconfig' ))
68
-
69
- libdir = join (self .dist_dir , 'private' , 'lib' , 'python2.7' )
70
- site_packages_dir = join (libdir , 'site-packages' )
71
- with current_directory (libdir ):
72
- # shprint(sh.xargs, 'rm', sh.grep('-E', '*\.(py|pyx|so\.o|so\.a|so\.libs)$', sh.find('.')))
73
- removes = []
74
- for dirname , something , filens in walk ('.' ):
75
- for filename in filens :
76
- for suffix in ('py' , 'pyc' , 'so.o' , 'so.a' , 'so.libs' ):
77
- if filename .endswith (suffix ):
78
- removes .append (filename )
79
- shprint (sh .rm , '-f' , * removes )
80
-
81
- info ('Deleting some other stuff not used on android' )
82
- # To quote the original distribute.sh, 'well...'
83
- # shprint(sh.rm, '-rf', 'ctypes')
84
- shprint (sh .rm , '-rf' , 'lib2to3' )
85
- shprint (sh .rm , '-rf' , 'idlelib' )
86
- for filename in glob .glob ('config/libpython*.a' ):
87
- shprint (sh .rm , '-f' , filename )
88
- shprint (sh .rm , '-rf' , 'config/python.o' )
89
- # shprint(sh.rm, '-rf', 'lib-dynload/_ctypes_test.so')
90
- # shprint(sh.rm, '-rf', 'lib-dynload/_testcapi.so')
91
-
92
- else : # Python *is* loaded from crystax
93
- ndk_dir = self .ctx .ndk_dir
94
- py_recipe = self .ctx .python_recipe
95
- python_dir = join (ndk_dir , 'sources' , 'python' , py_recipe .version ,
96
- 'libs' , arch .arch )
97
-
98
- shprint (sh .cp , '-r' , join (python_dir , 'stdlib.zip' ), 'crystax_python/crystax_python' )
99
- shprint (sh .cp , '-r' , join (python_dir , 'modules' ), 'crystax_python/crystax_python' )
100
- shprint (sh .cp , '-r' , self .ctx .get_python_install_dir (), 'crystax_python/crystax_python/site-packages' )
34
+ python_bundle_dir = join ('_python_bundle' , '_python_bundle' )
35
+ ensure_dir (python_bundle_dir )
36
+ site_packages_dir = self .ctx .python_recipe .create_python_bundle (
37
+ join (self .dist_dir , python_bundle_dir ), arch )
101
38
102
- info ('Renaming .so files to reflect cross-compile' )
103
- site_packages_dir = 'crystax_python/crystax_python/site-packages'
104
- filens = shprint (sh .find , site_packages_dir , '-iname' , '*.so' ).stdout .decode (
105
- 'utf-8' ).split ('\n ' )[:- 1 ]
106
- for filen in filens :
107
- parts = filen .split ('.' )
108
- if len (parts ) <= 2 :
109
- continue
110
- shprint (sh .mv , filen , filen .split ('.' )[0 ] + '.so' )
111
- site_packages_dir = join (abspath (curdir ),
112
- site_packages_dir )
39
+ if 'sqlite3' not in self .ctx .recipe_build_order :
40
+ with open ('blacklist.txt' , 'a' ) as fileh :
41
+ fileh .write ('\n sqlite3/*\n lib-dynload/_sqlite3.so\n ' )
113
42
114
43
self .strip_libraries (arch )
115
44
self .fry_eggs (site_packages_dir )
0 commit comments