8000 Fixes the include and link paths for python2 by opacam · Pull Request #793 · kivy/python-for-android · GitHub
[go: up one dir, main page]

Skip to content

Fixes the include and link paths for python2 #793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 31 additions & 20 deletions pythonforandroid/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,34 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True):
env['PYTHONNOUSERSITE'] = '1'

if not self.call_hostpython_via_targetpython:
# sets python headers/linkages...depending on python's recipe
python_version = self.ctx.python_recipe.version
python_short_version = '.'.join(python_version.split('.')[:2])
if 'python2' in self.ctx.recipe_build_order:
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
env['CFLAGS'] += ' -I' + env[
'PYTHON_ROOT'] + '/include/python2.7'
env['LDFLAGS'] += ' -L' + env['PYTHON_ROOT'] + '/lib' + \
' -lpython2.7'
elif self.ctx.python_recipe.from_crystax:
ndk_dir_python = join(self.ctx.ndk_dir, 'sources',
'python', python_version)
env['CFLAGS'] += ' -I{} '.format(
join(ndk_dir_python, 'include',
'python'))
env['LDFLAGS'] += ' -L{}'.format(
join(ndk_dir_python, 'libs', arch.arch))
env['LDFLAGS'] += ' -lpython{}m'.format(python_short_version)
elif 'python3' in self.ctx.recipe_build_order:
# This headers are unused cause python3 recipe was removed
# TODO: should be reviewed when python3 recipe added
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
env['CFLAGS'] += ' -I' + env[
'PYTHON_ROOT'] + '/include/python{}m'.format(
python_short_version)
env['LDFLAGS'] += ' -L' + env['PYTHON_ROOT'] + '/lib' + \
' -lpython{}m'.format(
python_short_version)
hppath = []
hppath.append(join(dirname(self.hostpython_location), 'Lib'))
hppath.append(join(hppath[0], 'site-packages'))
Expand Down Expand Up @@ -889,17 +917,14 @@ def get_recipe_env(self, arch):
keys = dict(
ctx=self.ctx,
arch=arch,
arch_noeabi=arch.arch.replace('eabi', ''),
pyroot=self.ctx.get_python_install_dir()
arch_noeabi=arch.arch.replace('eabi', '')
)
env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
env['CFLAGS'] += " -I{pyroot}/include/python2.7 " \
" -I{ctx.ndk_dir}/platforms/android-{ctx.android_api}/arch-{arch_noeabi}/usr/include" \
env['CFLAGS'] += " -I{ctx.ndk_dir}/platforms/android-{ctx.android_api}/arch-{arch_noeabi}/usr/include" \
" -I{ctx.ndk_dir}/sources/cxx-stl/gnu-libstdc++/{ctx.toolchain_version}/include" \
" -I{ctx.ndk_dir}/sources/cxx-stl/gnu-libstdc++/{ctx.toolchain_version}/libs/{arch.arch}/include".format(**keys)
env['CXXFLAGS'] = env['CFLAGS'] + ' -frtti -fexceptions'
env['LDFLAGS'] += " -L{ctx.ndk_dir}/sources/cxx-stl/gnu-libstdc++/{ctx.toolchain_version}/libs/{arch.arch}" \
" -lpython2.7" \
" -lgnustl_shared".format(**keys)

return env
Expand All @@ -919,6 +944,7 @@ class CythonRecipe(PythonRecipe):
pre_build_ext = False
cythonize = True
cython_args = []
call_hostpython_via_targetpython = False

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

if self.ctx.python_recipe.from_crystax:
env['CFLAGS'] = '-I{} '.format(
join(self.ctx.ndk_dir, 'sources', 'python',
self.ctx.python_recipe.version, 'include',
'python')) + env['CFLAGS']

# Temporarily hardcode the -lpython3.x as this does not
# get applied automatically in some environments. This
# will need generalising, along with the other hardcoded
# py3.5 references, to support other python3 or crystax
# python versions.
python3_version = self.ctx.python_recipe.version
python3_version = '.'.join(python3_version.split('.')[:2])
env['LDFLAGS'] = env['LDFLAGS'] + ' -lpython{}m'.format(python3_version)

return env


Expand Down
8 changes: 1 addition & 7 deletions pythonforandroid/recipes/cryptography/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pythonforandroid.recipe import CompiledComponentsPythonRecipe
from os.path import join


class CryptographyRecipe(CompiledComponentsPythonRecipe):
Expand All @@ -13,14 +12,9 @@ def get_recipe_env(self, arch):
env = super(CryptographyRecipe, self).get_recipe_env(arch)
r = self.get_recipe('openssl', self.ctx)
openssl_dir = r.get_build_dir(arch.arch)
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
env['CFLAGS'] += ' -I' + env['PYTHON_ROOT'] + '/include/python2.7' + \
' -I' + join(openssl_dir, 'include')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating that pull request.
Please remove the join import since it's not used anymore Travis is complaining.
https://travis-ci.org/kivy/python-for-android/jobs/398189288
Also think about running tox so you don't have to wait for Travis to fail to fix the linter.

# Set linker to use the correct gcc
env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
env['LDFLAGS'] += ' -L' + env['PYTHON_ROOT'] + '/lib' + \
' -L' + openssl_dir + \
' -lpython2.7' + \
env['LDFLAGS'] += ' -L' + openssl_dir + \
' -lssl' + r.version + \
' -lcrypto' + r.version
return env
Expand Down
43 changes: 19 additions & 24 deletions pythonforandroid/recipes/m2crypto/__init__.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,42 @@
from pythonforandroid.recipe import PythonRecipe
from pythonforandroid.toolchain import current_directory, shprint
from os.path import join
from pythonforandroid.recipe import CompiledComponentsPythonRecipe
from pythonforandroid.toolchain import current_directory
from pythonforandroid.logger import shprint, info
import glob
import sh


class M2CryptoRecipe(PythonRecipe):
class M2CryptoRecipe(CompiledComponentsPythonRecipe):
version = '0.24.0'
url = 'https://pypi.python.org/packages/source/M/M2Crypto/M2Crypto-{version}.tar.gz'
#md5sum = '89557730e245294a6cab06de8ad4fb42'
# md5sum = '89557730e245294a6cab06de8ad4fb42'
depends = ['openssl', 'hostpython2', 'python2', 'setuptools']
site_packages_name = 'M2Crypto'
call_hostpython_via_targetpython = False

def build_arch(self, arch):
def build_compiled_components(self, arch):
info('Building compiled components in {}'.format(self.name))

env = self.get_recipe_env(arch)
with current_directory(self.get_build_dir(arch.arch)):
# Build M2Crypto
hostpython = sh.Command(self.hostpython_location)
r = self.get_recipe('openssl', self.ctx)
openssl_dir = r.get_build_dir(arch.arch)
shprint(hostpython,
'setup.py',
'build_ext',
if self.install_in_hostpython:
shprint(hostpython, 'setup.py', 'clean', '--all', _env=env)
shprint(hostpython, 'setup.py', self.build_cmd,
'-p' + arch.arch,
'-c' + 'unix',
'--openssl=' + openssl_dir, _env=env)
# Install M2Crypto
super(M2CryptoRecipe, self).build_arch(arch)
'-o' + env['OPENSSL_BUILD_PATH'],
'-L' + env['OPENSSL_BUILD_PATH'],
_env=env, *self.setup_extra_args)
build_dir = glob.glob('build/lib.*')[0]
shprint(sh.find, build_dir, '-name', '"*.o"', '-exec',
env['STRIP'], '{}', ';', _env=env)

def get_recipe_env(self, arch):
env = super(M2CryptoRecipe, self).get_recipe_env(arch)
r = self.get_recipe('openssl', self.ctx)
openssl_dir = r.get_build_dir(arch.arch)
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
env['CFLAGS'] += ' -I' + env['PYTHON_ROOT'] + '/include/python2.7' + \
' -I' + join(openssl_dir, 'include')
env['OPENSSL_BUILD_PATH'] = self.get_recipe('openssl', self.ctx).get_build_dir(arch.arch)
# Set linker to use the correct gcc
env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
env['LDFLAGS'] += ' -L' + env['PYTHON_ROOT'] + '/lib' + \
' -L' + openssl_dir + \
' -lpython2.7' + \
' -lssl' + r.version + \
' -lcrypto' + r.version
return env


Expand Down
5 changes: 1 addition & 4 deletions pythonforandroid/recipes/pyleveldb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ def get_recipe_env(self, arch):
env = super(PyLevelDBRecipe, self).get_recipe_env(arch)
# Copy environment from leveldb recipe
env.update(self.get_recipe('leveldb', self.ctx).get_recipe_env(arch))
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
env['CFLAGS'] += ' -I' + env['PYTHON_ROOT'] + '/include/python2.7'
# Set linker to use the correct gcc
env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
env['LDFLAGS'] += ' -lpython2.7' + \
' -lleveldb'
env['LDFLAGS'] += ' -lleveldb'
return env


Expand Down
0