11
2- from pythonforandroid .toolchain import Recipe , shprint , get_directory , current_directory , ArchAndroid
3- from os .path import exists , join
2+ from pythonforandroid .toolchain import Recipe , shprint , get_directory , current_directory , ArchAndroid , info
3+ from os .path import exists , join , realpath
44from os import uname
55import glob
66import sh
77
8+
89class Python2Recipe (Recipe ):
910 version = "2.7.2"
1011 url = 'http://python.org/ftp/python/{version}/Python-{version}.tar.bz2'
@@ -40,6 +41,35 @@ def prebuild_armeabi(self):
4041 shprint (sh .touch , join (build_dir , '.patched' ))
4142
4243 def build_armeabi (self ):
44+
45+ if not exists (join (self .get_build_dir ('armeabi' ), 'libpython2.7.so' )):
46+ self .do_python_build ()
47+
48+ if not exists (self .ctx .get_python_install_dir ()):
49+ shprint (sh .cp , '-a' , join (self .get_build_dir ('armeabi' ), 'python-install' ),
50+ self .ctx .get_python_install_dir ())
51+
52+ # This should be safe to run every time
53+ info ('Copying hostpython binary to targetpython folder' )
54+ shprint (sh .cp , self .ctx .hostpython ,
55+ join (self .ctx .get_python_install_dir (), 'bin' , 'python.host' ))
56+ self .ctx .hostpython = join (self .ctx .get_python_install_dir (), 'bin' , 'python.host' )
57+
58+ if not exists (join (self .ctx .get_libs_dir ('armeabi' ), 'libpython2.7.so' )):
59+ shprint (sh .cp , join (self .get_build_dir ('armeabi' ), 'libpython2.7.so' ), self .ctx .get_libs_dir ('armeabi' ))
60+
61+
62+ # # if exists(join(self.get_build_dir('armeabi'), 'libpython2.7.so')):
63+ # if exists(join(self.ctx.libs_dir, 'libpython2.7.so')):
64+ # info('libpython2.7.so already exists, skipping python build.')
65+ # if not exists(join(self.ctx.get_python_install_dir(), 'libpython2.7.so')):
66+ # info('Copying python-install to dist-dependent location')
67+ # shprint(sh.cp, '-a', 'python-install', self.ctx.get_python_install_dir())
68+ # self.ctx.hostpython = join(self.ctx.get_python_install_dir(), 'bin', 'python.host')
69+
70+ # return
71+
72+ def do_python_build (self ):
4373 if 'sqlite' in self .ctx .recipe_build_order or 'openssl' in self .ctx .recipe_build_order :
4474 print ('sqlite or openssl support not yet enabled in python recipe' )
4575 exit (1 )
@@ -50,15 +80,6 @@ def build_armeabi(self):
5080 hostpython = join (self .get_build_dir ('armeabi' ), 'hostpython' )
5181 hostpgen = join (self .get_build_dir ('armeabi' ), 'hostpython' )
5282
53- # ctypes: Need to set buildarch?
54-
55- if exists (join (self .get_build_dir ('armeabi' ), 'libpython2.7.so' )):
56- print ('libpython2.7.so already exists, skipping python build.' )
57- self .ctx .hostpython = join (self .ctx .build_dir , 'python-install' ,
58- 'bin' , 'python.host' )
59-
60- return
61-
6283 with current_directory (self .get_build_dir ('armeabi' )):
6384
6485
@@ -80,10 +101,10 @@ def build_armeabi(self):
80101 '--host={}' .format (env ['HOSTARCH' ]),
81102 '--build={}' .format (env ['BUILDARCH' ]),
82103 # 'OPT={}'.format(env['OFLAG']),
83- '--prefix={}' .format (join ( self . ctx . build_dir , ' python-install' )),
104+ '--prefix={}' .format (realpath ( './ python-install' )),
84105 '--enable-shared' ,
85106 '--disable-toolbox-glue' ,
86- '--disable-framefork ' ,
107+ '--disable-framework ' ,
87108 _env = env )
88109
89110 # AND: tito left this comment in the original source. It's still true!
@@ -115,32 +136,30 @@ def build_armeabi(self):
115136
116137 if uname ()[0 ] == 'Darwin' :
117138 shprint (sh .cp , join (self .get_recipe_dir (), 'patches' , '_scproxy.py' ),
118- join (self . get_build_dir () , 'Lib' ))
139+ join ('python-install' , 'Lib' ))
119140 shprint (sh .cp , join (self .get_recipe_dir (), 'patches' , '_scproxy.py' ),
120- join (self .ctx .build_dir , 'python-install' , 'lib' , 'python2.7' ))
121-
122- print ('Ready to copy .so for python arm' )
123- shprint (sh .cp , 'libpython2.7.so' , self .ctx .libs_dir )
124- # for filen in glob.glob('build/lib.*-2.7/_ctypes*.so'):
125- # shprint(sh.cp, '-a', filen, self.ctx.libs_dir)
126-
127- print ('Copying hostpython binary to targetpython folder' )
128- shprint (sh .cp , self .ctx .hostpython ,
129- join (self .ctx .build_dir , 'python-install' , 'bin' ,
130- 'python.host' ))
131- self .ctx .hostpython = join (self .ctx .build_dir , 'python-install' ,
132- 'bin' , 'python.host' )
133-
141+ join ('python-install' , 'lib' , 'python2.7' ))
134142
135- # reduce python?
143+ # reduce python
136144 for dir_name in ('test' , join ('json' , 'tests' ), 'lib-tk' ,
137145 join ('sqlite3' , 'test' ), join ('unittest, test' ),
138146 join ('lib2to3' , 'tests' ), join ('bsddb' , 'tests' ),
139147 join ('distutils' , 'tests' ), join ('email' , 'test' ),
140148 'curses' ):
141- shprint (sh .rm , '-rf' , join (self . ctx . build_dir , 'python-install' ,
149+ shprint (sh .rm , '-rf' , join ('python-install' ,
142150 'lib' , 'python2.7' , dir_name ))
143151
152+
153+ # info('Copying python-install to dist-dependent location')
154+ # shprint(sh.cp, '-a', 'python-install', self.ctx.get_python_install_dir())
155+
156+ # print('Copying hostpython binary to targetpython folder')
157+ # shprint(sh.cp, self.ctx.hostpython,
158+ # join(self.ctx.get_python_install_dir(), 'bin', 'python.host'))
159+ # self.ctx.hostpython = join(self.ctx.get_python_install_dir(), 'bin', 'python.host')
160+
161+
162+
144163 # print('python2 build done, exiting for debug')
145164 # exit(1)
146165
0 commit comments