11from pythonforandroid .toolchain import (
22 Bootstrap , shprint , current_directory , info , info_main )
33from pythonforandroid .util import ensure_dir
4- from os .path import join , exists , curdir , abspath
5- from os import walk
6- import glob
4+ from os .path import join , exists
75import sh
86
97
10- EXCLUDE_EXTS = (".py" , ".pyc" , ".so.o" , ".so.a" , ".so.libs" , ".pyx" )
11-
12-
138class SDL2GradleBootstrap (Bootstrap ):
14- name = 'sdl2_gradle '
9+ name = 'sdl2 '
1510
16- recipe_depends = ['sdl2' , ('python2' , 'python3crystax' )]
11+ recipe_depends = ['sdl2' , ('python2' , 'python3' , ' python3crystax' )]
1712
1813 def run_distribute (self ):
1914 info_main ("# Creating Android project ({})" .format (self .name ))
2015
2116 arch = self .ctx .archs [0 ]
2217 python_install_dir = self .ctx .get_python_install_dir ()
2318 from_crystax = self .ctx .python_recipe .from_crystax
24- crystax_python_dir = join ("crystax_python" , "crystax_python" )
2519
2620 if len (self .ctx .archs ) > 1 :
2721 raise ValueError ("SDL2/gradle support only one arch" )
@@ -30,7 +24,7 @@ def run_distribute(self):
3024 shprint (sh .rm , "-rf" , self .dist_dir )
3125 shprint (sh .cp , "-r" , self .build_dir , self .dist_dir )
3226
33- # either the build use environemnt variable (ANDROID_HOME)
27+ # either the build use environment variable (ANDROID_HOME)
3428 # or the local.properties if exists
3529 with current_directory (self .dist_dir ):
3630 with open ('local.properties' , 'w' ) as fileh :
@@ -39,91 +33,31 @@ def run_distribute(self):
3933 with current_directory (self .dist_dir ):
4034 info ("Copying Python distribution" )
4135
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 )
46-
4736 hostpython = sh .Command (self .ctx .hostpython )
48- if not from_crystax :
37+ if self . ctx . python_recipe . name == 'python2' :
4938 try :
5039 shprint (hostpython , '-OO' , '-m' , 'compileall' ,
5140 python_install_dir ,
5241 _tail = 10 , _filterout = "^Listing" )
5342 except sh .ErrorReturnCode :
5443 pass
55- if not exists ('python-install' ):
44+ if 'python2' in self . ctx . recipe_build_order and not exists ('python-install' ):
5645 shprint (
5746 sh .cp , '-a' , python_install_dir , './python-install' )
5847
5948 self .distribute_libs (arch , [self .ctx .get_libs_dir (arch .arch )])
6049 self .distribute_javaclasses (self .ctx .javaclass_dir ,
6150 dest_dir = join ("src" , "main" , "java" ))
6251
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" ))
71-
72- libpymodules_fn = join ("libs" , arch .arch , "libpymodules.so" )
73- if exists (libpymodules_fn ):
74- shprint (sh .mv , libpymodules_fn , 'private/' )
75- shprint (sh .cp ,
76- join ('python-install' , 'include' ,
77- 'python2.7' , 'pyconfig.h' ),
78- join ('private' , 'include' , 'python2.7/' ))
79-
80- info ('Removing some unwanted files' )
81- shprint (sh .rm , '-f' , join ('private' , 'lib' , 'libpython2.7.so' ))
82- shprint (sh .rm , '-rf' , join ('private' , 'lib' , 'pkgconfig' ))
83-
84- libdir = join (self .dist_dir , 'private' , 'lib' , 'python2.7' )
85- site_packages_dir = join (libdir , 'site-packages' )
86- with current_directory (libdir ):
87- removes = []
88- for dirname , root , filenames in walk ("." ):
89- for filename in filenames :
90- for suffix in EXCLUDE_EXTS :
91- if filename .endswith (suffix ):
92- removes .append (filename )
93- shprint (sh .rm , '-f' , * removes )
94-
95- info ('Deleting some other stuff not used on android' )
96- # To quote the original distribute.sh, 'well...'
97- shprint (sh .rm , '-rf' , 'lib2to3' )
98- shprint (sh .rm , '-rf' , 'idlelib' )
99- for filename in glob .glob ('config/libpython*.a' ):
100- shprint (sh .rm , '-f' , filename )
101- shprint (sh .rm , '-rf' , 'config/python.o' )
102-
103- else : # Python *is* loaded from crystax
104- ndk_dir = self .ctx .ndk_dir
105- py_recipe = self .ctx .python_recipe
106- python_dir = join (ndk_dir , 'sources' , 'python' ,
107- py_recipe .version , 'libs' , arch .arch )
108- shprint (sh .cp , '-r' , join (python_dir ,
109- 'stdlib.zip' ), crystax_python_dir )
110- shprint (sh .cp , '-r' , join (python_dir ,
111- 'modules' ), crystax_python_dir )
112- shprint (sh .cp , '-r' , self .ctx .get_python_install_dir (),
113- join (crystax_python_dir , 'site-packages' ))
114-
115- info ('Renaming .so files to reflect cross-compile' )
116- site_packages_dir = join (crystax_python_dir , "site-packages" )
117- find_ret = shprint (
118- sh .find , site_packages_dir , '-iname' , '*.so' )
119- filenames = find_ret .stdout .decode ('utf-8' ).split ('\n ' )[:- 1 ]
120- for filename in filenames :
121- parts = filename .split ('.' )
122- if len (parts ) <= 2 :
123- continue
124- shprint (sh .mv , filename , filename .split ('.' )[0 ] + '.so' )
125- site_packages_dir = join (abspath (curdir ),
126- site_packages_dir )
52+ python_bundle_dir = join ('_python_bundle' , '_python_bundle' )
53+ if 'python2' in self .ctx .recipe_build_order :
54+ # Python 2 is a special case with its own packaging location
55+ python_bundle_dir = 'private'
56+ ensure_dir (python_bundle_dir )
57+
58+ site_packages_dir = self .ctx .python_recipe .create_python_bundle (
59+ join (self .dist_dir , python_bundle_dir ), arch )
60+
12761 if 'sqlite3' not in self .ctx .recipe_build_order :
12862 with open ('blacklist.txt' , 'a' ) as fileh :
12963 fileh .write ('\n sqlite3/*\n lib-dynload/_sqlite3.so\n ' )
0 commit comments