8000 Merge pull request #793 from opacam/fix-env-py2 · bb33bb/python-for-android@786bec8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 786bec8

Browse files
authored
Merge pull request kivy#793 from opacam/fix-env-py2
Fixes the include and link paths for python2
2 parents 8983db5 + cbe9e8e commit 786bec8

File tree

4 files changed

+52
-55
lines changed

4 files changed

+52
-55
lines changed

pythonforandroid/recipe.py

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,34 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True):
758758
env['PYTHONNOUSERSITE'] = '1'
759759

760760
if not self.call_hostpython_via_targetpython:
761+
# sets python headers/linkages...depending on python's recipe
762+
python_version = self.ctx.python_recipe.version
763+
python_short_version = '.'.join(python_version.split('.')[:2])
764+
if 'python2' in self.ctx.recipe_build_order:
765+
env['PYTHON_ROOT'] = self.c 8000 tx.get_python_install_dir()
766+
env['CFLAGS'] += ' -I' + env[
767+
'PYTHON_ROOT'] + '/include/python2.7'
768+
env['LDFLAGS'] += ' -L' + env['PYTHON_ROOT'] + '/lib' + \
769+
' -lpython2.7'
770+
elif self.ctx.python_recipe.from_crystax:
771+
ndk_dir_python = join(self.ctx.ndk_dir, 'sources',
772+
'python', python_version)
773+
env['CFLAGS'] += ' -I{} '.format(
774+
join(ndk_dir_python, 'include',
775+
'python'))
776+
env['LDFLAGS'] += ' -L{}'.format(
777+
join(ndk_dir_python, 'libs', arch.arch))
778+
env['LDFLAGS'] += ' -lpython{}m'.format(python_short_version)
779+
elif 'python3' in self.ctx.recipe_build_order:
780+
# This headers are unused cause python3 recipe was removed
781+
# TODO: should be reviewed when python3 recipe added
782+
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
783+
env['CFLAGS'] += ' -I' + env[
784+
'PYTHON_ROOT'] + '/include/python{}m'.format(
785+
python_short_version)
786+
env['LDFLAGS'] +=  8000 9; -L' + env['PYTHON_ROOT'] + '/lib' + \
787+
' -lpython{}m'.format(
788+
python_short_version)
761789
hppath = []
762790
hppath.append(join(dirname(self.hostpython_location), 'Lib'))
763791
hppath.append(join(hppath[0], 'site-packages'))
@@ -889,17 +917,14 @@ def get_recipe_env(self, arch):
889917
keys = dict(
890918
ctx=self.ctx,
891919
arch=arch,
892-
arch_noeabi=arch.arch.replace('eabi', ''),
893-
pyroot=self.ctx.get_python_install_dir()
920+
arch_noeabi=arch.arch.replace('eabi', '')
894921
)
895922
env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
896-
env['CFLAGS'] += " -I{pyroot}/include/python2.7 " \
897-
" -I{ctx.ndk_dir}/platforms/android-{ctx.android_api}/arch-{arch_noeabi}/usr/include" \
923+
env['CFLAGS'] += " -I{ctx.ndk_dir}/platforms/android-{ctx.android_api}/arch-{arch_noeabi}/usr/include" \
898924
" -I{ctx.ndk_dir}/sources/cxx-stl/gnu-libstdc++/{ctx.toolchain_version}/include" \
899925
" -I{ctx.ndk_dir}/sources/cxx-stl/gnu-libstdc++/{ctx.toolchain_version}/libs/{arch.arch}/include".format(**keys)
900926
env['CXXFLAGS'] = env['CFLAGS'] + ' -frtti -fexceptions'
901927
env['LDFLAGS'] += " -L{ctx.ndk_dir}/sources/cxx-stl/gnu-libstdc++/{ctx.toolchain_version}/libs/{arch.arch}" \
902-
" -lpython2.7" \
903928
" -lgnustl_shared".format(**keys)
904929

905930
return env
@@ -919,6 +944,7 @@ class CythonRecipe(PythonRecipe):
919944
pre_build_ext = False
920945
cythonize = True
921946
cython_args = []
947+
call_hostpython_via_targetpython = False
922948

923949
def __init__(self, *args, **kwargs):
924950
super(CythonRecipe, self).__init__(*args, **kwargs)
@@ -1042,21 +1068,6 @@ def get_recipe_env(self, arch, with_flags_in_cc=True):
10421068
env['LIBLINK_PATH'] = liblink_path
10431069
ensure_dir(liblink_path)
10441070

1045-
if self.ctx.python_recipe.from_crystax:
1046-
env['CFLAGS'] = '-I{} '.format(
1047-
join(self.ctx.ndk_dir, 'sources', 'python',
1048-
self.ctx.python_recipe.version, 'include',
1049-
'python')) + env['CFLAGS']
1050-
1051-
# Temporarily hardcode the -lpython3.x as this does not
1052-
# get applied automatically in some environments. This
1053-
# will need generalising, along with the other hardcoded
1054-
# py3.5 references, to support other python3 or crystax
1055-
# python versions.
1056-
python3_version = self.ctx.python_recipe.version
1057-
python3_version = '.'.join(python3_version.split('.')[:2])
1058-
env['LDFLAGS'] = env['LDFLAGS'] + ' -lpython{}m'.format(python3_version)
1059-
10601071
return env
10611072

10621073

pythonforandroid/recipes/cryptography/__init__.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from pythonforandroid.recipe import CompiledComponentsPythonRecipe
2-
from os.path import join
32

43

54
class CryptographyRecipe(CompiledComponentsPythonRecipe):
@@ -13,14 +12,9 @@ def get_recipe_env(self, arch):
1312
env = super(CryptographyRecipe, self).get_recipe_env(arch)
1413
r = self.get_recipe('openssl', self.ctx)
1514
openssl_dir = r.get_build_dir(arch.arch)
16-
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
17-
env['CFLAGS'] += ' -I' + env['PYTHON_ROOT'] + '/include/python2.7' + \
18-
' -I' + join(openssl_dir, 'include')
1915
# Set linker to use the correct gcc
2016
env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
21-
env['LDFLAGS'] += ' -L' + env['PYTHON_ROOT'] + '/lib' + \
22-
' -L' + openssl_dir + \
23-
' -lpython2.7' + \
17+
env['LDFLAGS'] += ' -L' + openssl_dir + \
2418
' -lssl' + r.version + \
2519
' -lcrypto' + r.version
2620
return env

pythonforandroid/recipes/m2crypto/__init__.py

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,42 @@
1-
from pythonforandroid.recipe import PythonRecipe
2-
from pythonforandroid.toolchain import current_directory, shprint
3-
from os.path import join
1+
from pythonforandroid.recipe import CompiledComponentsPythonRecipe
2+
from pythonforandroid.toolchain import current_directory
3+
from pythonforandroid.logger import shprint, info
4+
import glob
45
import sh
56

67

7-
class M2CryptoRecipe(PythonRecipe):
8+
class M2CryptoRecipe(CompiledComponentsPythonRecipe):
89
version = '0.24.0'
910
url = 'https://pypi.python.org/packages/source/M/M2Crypto/M2Crypto-{version}.tar.gz'
10-
#md5sum = '89557730e245294a6cab06de8ad4fb42'
11+
# md5sum = '89557730e245294a6cab06de8ad4fb42'
1112
depends = ['openssl', 'hostpython2', 'python2', 'setuptools']
1213
site_packages_name = 'M2Crypto'
1314
call_hostpython_via_targetpython = False
1415

15-
def build_arch(self, arch):
16+
def build_compiled_components(self, arch):
17+
info('Building compiled components in {}'.format(self.name))
18+
1619
env = self.get_recipe_env(arch)
1720
with current_directory(self.get_build_dir(arch.arch)):
1821
# Build M2Crypto
1922
hostpython = sh.Command(self.hostpython_location)
20-
r = self.get_recipe('openssl', self.ctx)
21-
openssl_dir = r.get_build_dir(arch.arch)
22-
shprint(hostpython,
23-
'setup.py',
24-
'build_ext',
23+
if self.install_in_hostpython:
24+
shprint(hostpython, 'setup.py', 'clean', '--all', _env=env)
25+
shprint(hostpython, 'setup.py', self.build_cmd,
2526
'-p' + arch.arch,
2627
'-c' + 'unix',
27-
'--openssl=' + openssl_dir, _env=env)
28-
# Install M2Crypto
29-
super(M2CryptoRecipe, self).build_arch(arch)
28+
'-o' + env['OPENSSL_BUILD_PATH'],
29+
'-L' + env['OPENSSL_BUILD_PATH'],
30+
_env=env, *self.setup_extra_args)
31+
build_dir = glob.glob('build/lib.*')[0]
32+
shprint(sh.find, build_dir, '-name', '"*.o"', '-exec',
33+
env['STRIP'], '{}', ';', _env=env)
3034

3135
def get_recipe_env(self, arch):
3236
env = super(M2CryptoRecipe, self).get_recipe_env(arch)
33-
r = self.get_recipe('openssl', self.ctx)
34-
openssl_dir = r.get_build_dir(arch.arch)
35-
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
36-
env['CFLAGS'] += ' -I' + env['PYTHON_ROOT'] + '/include/python2.7' + \
37-
' -I' + join(openssl_dir, 'include')
37+
env['OPENSSL_BUILD_PATH'] = self.get_recipe('openssl', self.ctx).get_build_dir(arch.arch)
3838
# Set linker to use the correct gcc
3939
env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
40-
env['LDFLAGS'] += ' -L' + env['PYTHON_ROOT'] + '/lib' + \
41-
' -L' + openssl_dir + \
42-
' -lpython2.7' + \
43-
' -lssl' + r.version + \
44-
' -lcrypto' + r.version
4540
return env
4641

4742

pythonforandroid/recipes/pyleveldb/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,9 @@ def get_recipe_env(self, arch):
2525
env = super(PyLevelDBRecipe, self).get_recipe_env(arch)
2626
# Copy environment from leveldb recipe
2727
env.update(self.get_recipe('leveldb', self.ctx).get_recipe_env(arch))
28-
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
29-
env['CFLAGS'] += ' -I' + env['PYTHON_ROOT'] + '/include/python2.7'
3028
# Set linker to use the correct gcc
3129
env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
32-
env['LDFLAGS'] += ' -lpython2.7' + \
33-
' -lleveldb'
30+
env['LDFLAGS'] += ' -lleveldb'
3431
return env
3532

3633

0 commit comments

Comments
 (0)
0