1
- from pythonforandroid .toolchain import Bootstrap , shprint , current_directory , info , warning , ArchARM , info_main
1
+ from pythonforandroid .toolchain import (
2
+ Bootstrap , shprint , current_directory , info , info_main )
3
+ from pythonforandroid .util import ensure_dir
2
4
from os .path import join , exists , curdir , abspath
3
5
from os import walk
4
6
import glob
5
7
import sh
6
8
7
- class SDL2Bootstrap (Bootstrap ):
8
- name = 'sdl2'
9
+
10
+ EXCLUDE_EXTS = (".py" , ".pyc" , ".so.o" , ".so.a" , ".so.libs" , ".pyx" )
11
+
12
+
13
+ class SDL2GradleBootstrap (Bootstrap ):
14
+ name = 'sdl2_gradle'
9
15
10
16
recipe_depends = ['sdl2' , ('python2' , 'python3crystax' )]
11
17
12
18
def run_distribute (self ):
13
- info_main ('# Creating Android project from build and {} bootstrap' .format (
14
- self .name ))
19
+ info_main ("# Creating Android project ({})" .format (self .name ))
20
+
21
+ arch = self .ctx .archs [0 ]
22
+ python_install_dir = self .ctx .get_python_install_dir ()
23
+ from_crystax = self .ctx .python_recipe .from_crystax
24
+ crystax_python_dir = join ("crystax_python" , "crystax_python" )
25
+
26
+ if len (self .ctx .archs ) > 1 :
27
+ raise ValueError ("SDL2/gradle support only one arch" )
28
+
29
+ info ("Copying SDL2/gradle build for {}" .format (arch ))
30
+ shprint (sh .rm , "-rf" , self .dist_dir )
31
+ shprint (sh .cp , "-r" , self .build_dir , self .dist_dir )
15
32
16
- info ('This currently just copies the SDL2 build stuff straight from the build dir.' )
17
- shprint (sh .rm , '-rf' , self .dist_dir )
18
- shprint (sh .cp , '-r' , self .build_dir , self .dist_dir )
33
+ # either the build use environemnt variable (ANDROID_HOME)
34
+ # or the local.properties if exists
19
35
with current_directory (self .dist_dir ):
20
36
with open ('local.properties' , 'w' ) as fileh :
21
37
fileh .write ('sdk.dir={}' .format (self .ctx .sdk_dir ))
22
38
23
- arch = self .ctx .archs [0 ]
24
- if len (self .ctx .archs ) > 1 :
25
- raise ValueError ('built for more than one arch, but bootstrap cannot handle that yet' )
26
- info ('Bootstrap running with arch {}' .format (arch ))
27
-
28
39
with current_directory (self .dist_dir ):
29
- info (' Copying python distribution' )
40
+ info (" Copying Python distribution" )
30
41
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' )
42
+ if not exists ("private" ) and not from_crystax :
43
+ ensure_dir ("private" )
44
+ if not exists ("crystax_python" ) and from_crystax :
45
+ ensure_dir (crystax_python_dir )
38
46
39
47
hostpython = sh .Command (self .ctx .hostpython )
40
- if not self . ctx . python_recipe . from_crystax :
48
+ if not from_crystax :
41
49
try :
42
50
shprint (hostpython , '-OO' , '-m' , 'compileall' ,
43
- self . ctx . get_python_install_dir () ,
51
+ python_install_dir ,
44
52
_tail = 10 , _filterout = "^Listing" )
45
53
except sh .ErrorReturnCode :
46
54
pass
47
55
if not exists ('python-install' ):
48
- shprint (sh .cp , '-a' , self .ctx .get_python_install_dir (), './python-install' )
56
+ shprint (
57
+ sh .cp , '-a' , python_install_dir , './python-install' )
49
58
50
59
self .distribute_libs (arch , [self .ctx .get_libs_dir (arch .arch )])
51
- self .distribute_aars (arch )
52
- self .distribute_javaclasses (self .ctx .javaclass_dir )
53
-
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
+ self .distribute_javaclasses (self .ctx .javaclass_dir ,
61
+ dest_dir = join ("src" , "main" , "java" ))
62
+
63
+ if not from_crystax :
64
+ info ("Filling private directory" )
65
+ if not exists (join ("private" , "lib" )):
66
+ info ("private/lib does not exist, making" )
67
+ shprint (sh .cp , "-a" ,
68
+ join ("python-install" , "lib" ), "private" )
69
+ shprint (sh .mkdir , "-p" ,
70
+ join ("private" , "include" , "python2.7" ))
60
71
61
72
# AND: Copylibs stuff should go here
62
- if exists (join ('libs' , arch .arch , 'libpymodules.so' )):
63
- shprint (sh .mv , join ('libs' , arch .arch , 'libpymodules.so' ), 'private/' )
64
- shprint (sh .cp , join ('python-install' , 'include' , 'python2.7' , 'pyconfig.h' ), join ('private' , 'include' , 'python2.7/' ))
73
+ libpymodules_fn = join ("libs" , arch .arch , "libpymodules.so" )
74
+ if exists (libpymodules_fn ):
75
+ shprint (sh .mv , libpymodules_fn , 'private/' )
76
+ shprint (sh .cp ,
77
+ join ('python-install' , 'include' ,
78
+ 'python2.7' , 'pyconfig.h' ),
79
+ join ('private' , 'include' , 'python2.7/' ))
65
80
66
81
info ('Removing some unwanted files' )
67
82
shprint (sh .rm , '-f' , join ('private' , 'lib' , 'libpython2.7.so' ))
@@ -70,54 +85,53 @@ def run_distribute(self):
70
85
libdir = join (self .dist_dir , 'private' , 'lib' , 'python2.7' )
71
86
site_packages_dir = join (libdir , 'site-packages' )
72
87
with current_directory (libdir ):
73
- # shprint(sh.xargs, 'rm', sh.grep('-E', '*\.(py|pyx|so\.o|so\.a|so\.libs)$', sh.find('.')))
74
88
removes = []
75
- for dirname , something , filens in walk ('.' ):
76
- for filename in filens :
77
- for suffix in ( 'py' , 'pyc' , 'so.o' , 'so.a' , 'so.libs' ) :
89
+ for dirname , root , filenames in walk ("." ):
90
+ for filename in filenames :
91
+ for suffix in EXCLUDE_EXTS :
78
92
if filename .endswith (suffix ):
79
93
removes .append (filename )
80
94
shprint (sh .rm , '-f' , * removes )
81
95
82
96
info ('Deleting some other stuff not used on android' )
83
97
# To quote the original distribute.sh, 'well...'
84
- # shprint(sh.rm, '-rf', 'ctypes')
85
98
shprint (sh .rm , '-rf' , 'lib2to3' )
86
99
shprint (sh .rm , '-rf' , 'idlelib' )
87
100
for filename in glob .glob ('config/libpython*.a' ):
88
101
shprint (sh .rm , '-f' , filename )
89
102
shprint (sh .rm , '-rf' , 'config/python.o' )
90
- # shprint(sh.rm, '-rf', 'lib-dynload/_ctypes_test.so')
91
- # shprint(sh.rm, '-rf', 'lib-dynload/_testcapi.so')
92
103
93
104
else : # Python *is* loaded from crystax
94
105
ndk_dir = self .ctx .ndk_dir
95
F438
106
py_recipe = self .ctx .python_recipe
96
- python_dir = join (ndk_dir , 'sources' , 'python' , py_recipe .version ,
97
- 'libs' , arch .arch )
98
-
99
- shprint (sh .cp , '-r' , join (python_dir , 'stdlib.zip' ), 'crystax_python/crystax_python' )
100
- shprint (sh .cp , '-r' , join (python_dir , 'modules' ), 'crystax_python/crystax_python' )
101
- shprint (sh .cp , '-r' , self .ctx .get_python_install_dir (), 'crystax_python/crystax_python/site-packages' )
107
+ python_dir = join (ndk_dir , 'sources' , 'python' ,
108
+ py_recipe .version , 'libs' , arch .arch )
109
+ shprint (sh .cp , '-r' , join (python_dir ,
110
+ 'stdlib.zip' ), crystax_python_dir )
111
+ shprint (sh .cp , '-r' , join (python_dir ,
112
+ 'modules' ), crystax_python_dir )
113
+ shprint (sh .cp , '-r' , self .ctx .get_python_install_dir (),
114
+ join (crystax_python_dir , 'site-packages' ))
102
115
103
116
info ('Renaming .so files to reflect cross-compile' )
104
- site_packages_dir = 'crystax_python/crystax_python/site-packages'
105
- filens = shprint (sh .find , site_packages_dir , '-iname' , '*.so' ).stdout .decode (
106
- 'utf-8' ).split ('\n ' )[:- 1 ]
107
- for filen in filens :
108
- parts = filen .split ('.' )
117
+ site_packages_dir = join (crystax_python_dir , "site-packages" )
118
+ find_ret = shprint (
119
+ sh .find , site_packages_dir , '-iname' , '*.so' )
120
+ filenames = find_ret .stdout .decode ('utf-8' ).split ('\n ' )[:- 1 ]
121
+ for filename in filenames :
122
+ parts = filename .split ('.' )
109
123
if len (parts ) <= 2 :
110
124
continue
111
- shprint (sh .mv , filen , filen .split ('.' )[0 ] + '.so' )
125
+ shprint (sh .mv , filename , filename .split ('.' )[0 ] + '.so' )
112
126
site_packages_dir = join (abspath (curdir ),
113
127
site_packages_dir )
114
128
if 'sqlite3' not in self .ctx .recipe_build_order :
115
129
with open ('blacklist.txt' , 'a' ) as fileh :
116
130
fileh .write ('\n sqlite3/*\n lib-dynload/_sqlite3.so\n ' )
117
131
118
-
119
132
self .strip_libraries (arch )
120
133
self .fry_eggs (site_packages_dir )
121
- super (SDL2Bootstrap , self ).run_distribute ()
134
+ super (SDL2GradleBootstrap , self ).run_distribute ()
135
+
122
136
123
- bootstrap = SDL2Bootstrap ()
137
+ bootstrap = SDL2GradleBootstrap ()
0 commit comments