Skip to content

Commit 02151be

Browse files
committed
Adapt pythonforandroid's core files to the new python2's build system
Cause we share the same build system for python2 and python3 recipes, we can safely remove some specific python2's code in favour of the python3's code, otherwise we will surely find troubles in our builds.
1 parent c7475ed commit 02151be

File tree

3 files changed

+28
-64
lines changed

3 files changed

+28
-64
lines changed

pythonforandroid/bootstrap.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,11 @@ def strip_libraries(self, arch):
243243
return
244244
strip = sh.Command(strip)
245245

246-
if self.ctx.python_recipe.name == 'python2':
247-
filens = shprint(sh.find, join(self.dist_dir, 'private'),
248-
join(self.dist_dir, 'libs'),
249-
'-iname', '*.so', _env=env).stdout.decode('utf-8')
250-
else:
251-
filens = shprint(sh.find, join(self.dist_dir, '_python_bundle', '_python_bundle', 'modules'),
252-
join(self.dist_dir, 'libs'),
253-
'-iname', '*.so', _env=env).stdout.decode('utf-8')
246+
filens = shprint(sh.find, join(self.dist_dir, '_python_bundle',
247+
'_python_bundle', 'modules'),
248+
join(self.dist_dir, 'libs'),
249+
'-iname', '*.so', _env=env).stdout.decode('utf-8')
250+
254251
logger.info('Stripping libraries in private dir')
255252
for filen in filens.split('\n'):
256253
try:

pythonforandroid/build.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -541,12 +541,6 @@ def get_site_packages_dir(self, arch=None):
541541
'''Returns the location of site-packages in the python-install build
542542
dir.
543543
'''
544-
if self.python_recipe.name == 'python2':
545-
return join(self.get_python_install_dir(),
546-
'lib', 'python2.7', 'site-packages')
547-
548-
# Only python2 is a special case, other python recipes use the
549-
# python install dir
550544
return self.get_python_install_dir()
551545

552546
def get_libs_dir(self, arch):

pythonforandroid/recipe.py

Lines changed: 23 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -690,17 +690,12 @@ def clean_build(self, arch=None):
690690

691691
@property
692692
def real_hostpython_location(self):
693-
if 'hostpython2' in self.ctx.recipe_build_order:
694-
return join(
695-
Recipe.get_recipe('hostpython2', self.ctx).get_build_dir(),
696-
'hostpython')
697-
elif 'hostpython3crystax' in self.ctx.recipe_build_order:
698-
return join(
699-
Recipe.get_recipe('hostpython3crystax', self.ctx).get_build_dir(),
700-
'hostpython')
701-
elif 'hostpython3' in self.ctx.recipe_build_order:
702-
return join(Recipe.get_recipe('hostpython3', self.ctx).get_build_dir(),
703-
'native-build', 'python')
693+
host_name = 'host{}'.format(self.ctx.python_recipe.name)
694+
host_build = Recipe.get_recipe(host_name, self.ctx).get_build_dir()
695+
if host_name in ['hostpython2', 'hostpython3']:
696+
return join(host_build, 'native-build', 'python')
697+
elif host_name == 'hostpython3crystax':
698+
return join(host_build, 'hostpython')
704699
else:
705700
python_recipe = self.ctx.python_recipe
706701
return 'python{}'.format(python_recipe.version)
@@ -726,14 +721,17 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True):
726721

727722
if not self.call_hostpython_via_targetpython:
728723
# sets python headers/linkages...depending on python's recipe
724+
python_name = self.ctx.python_recipe.name
729725
python_version = self.ctx.python_recipe.version
730726
python_short_version = '.'.join(python_version.split('.')[:2])
731-
if 'python2' in self.ctx.recipe_build_order:
732-
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
733-
env['CFLAGS'] += ' -I' + env[
734-
'PYTHON_ROOT'] + '/include/python2.7'
735-
env['LDFLAGS'] += (
736-
' -L' + env['PYTHON_ROOT'] + '/lib' + ' -lpython2.7')
727+
if python_name in ['python2', 'python3']:
728+
env['CFLAGS'] += ' -I{}'.format(
729+
self.ctx.python_recipe.include_root(arch.arch))
730+
env['LDFLAGS'] += ' -L{} -lpython{}'.format(
731+
self.ctx.python_recipe.link_root(arch.arch),
732+
self.ctx.python_recipe.major_minor_version_string)
733+
if python_name == 'python3':
734+
env['LDFLAGS'] += 'm'
737735
elif self.ctx.python_recipe.from_crystax:
738736
ndk_dir_python = join(self.ctx.ndk_dir, 'sources',
739737
'python', python_version)
@@ -743,11 +741,6 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True):
743741
env['LDFLAGS'] += ' -L{}'.format(
744742
join(ndk_dir_python, 'libs', arch.arch))
745743
env['LDFLAGS'] += ' -lpython{}m'.format(python_short_version)
746-
elif 'python3' in self.ctx.recipe_build_order:
747-
env['CFLAGS'] += ' -I{}'.format(self.ctx.python_recipe.include_root(arch.arch))
748-
env['LDFLAGS'] += ' -L{} -lpython{}m'.format(
749-
self.ctx.python_recipe.link_root(arch.arch),
750-
self.ctx.python_recipe.major_minor_version_string)
751744

752745
hppath = []
753746
hppath.append(join(dirname(self.hostpython_location), 'Lib'))
@@ -790,7 +783,7 @@ def install_python_package(self, arch, name=None, env=None, is_dir=True):
790783
hostpython = sh.Command(self.hostpython_location)
791784

792785
if (self.ctx.python_recipe.from_crystax or
793-
self.ctx.python_recipe.name == 'python3'):
786+
self.ctx.python_recipe.name in ['python2', 'python3']):
794787
hpenv = env.copy()
795788
shprint(hostpython, 'setup.py', 'install', '-O2',
796789
'--root={}'.format(self.ctx.get_python_install_dir()),
@@ -799,19 +792,6 @@ def install_python_package(self, arch, name=None, env=None, is_dir=True):
799792
elif self.call_hostpython_via_targetpython:
800793
shprint(hostpython, 'setup.py', 'install', '-O2', _env=env,
801794
*self.setup_extra_args)
802-
else:
803-
hppath = join(dirname(self.hostpython_location), 'Lib',
804-
'site-packages')
805-
hpenv = env.copy()
806-
if 'PYTHONPATH' in hpenv:
807-
hpenv['PYTHONPATH'] = ':'.join([hppath] +
808-
hpenv['PYTHONPATH'].split(':'))
809-
else:
810-
hpenv['PYTHONPATH'] = hppath
811-
shprint(hostpython, 'setup.py', 'install', '-O2',
812-
'--root={}'.format(self.ctx.get_python_install_dir()),
813-
'--install-lib=lib/python2.7/site-packages',
814-
_env=hpenv, *self.setup_extra_args)
815795

816796
# If asked, also install in the hostpython build dir
817797
if self.install_in_hostpython:
@@ -966,20 +946,13 @@ def build_cython_components(self, arch):
966946
info('First build appeared to complete correctly, skipping manual'
967947
'cythonising.')
968948

969-
if 'python2' in self.ctx.recipe_build_order:
970-
info('Stripping object files')
971-
build_lib = glob.glob('./build/lib*')
972-
shprint(sh.find, build_lib[0], '-name', '*.o', '-exec',
973-
env['STRIP'], '{}', ';', _env=env)
974-
975-
else: # python3crystax or python3
976-
info('Stripping object files')
977-
shprint(sh.find, '.', '-iname', '*.so', '-exec',
978-
'/usr/bin/echo', '{}', ';', _env=env)
979-
shprint(sh.find, '.', '-iname', '*.so', '-exec',
980-
env['STRIP'].split(' ')[0], '--strip-unneeded',
981-
# '/usr/bin/strip', '--strip-unneeded',
982-
'{}', ';', _env=env)
949+
info('Stripping object files')
950+
shprint(sh.find, '.', '-iname', '*.so', '-exec',
951+
'/usr/bin/echo', '{}', ';', _env=env)
952+
shprint(sh.find, '.', '-iname', '*.so', '-exec',
953+
env['STRIP'].split(' ')[0], '--strip-unneeded',
954+
# '/usr/bin/strip', '--strip-unneeded',
955+
'{}', ';', _env=env)
983956

984957
def cythonize_file(self, env, build_dir, filename):
985958
short_filename = filename

0 commit comments

Comments
 (0)