Skip to content
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

[WIP] Refactor python recipes and update python2's to version 2.7.15 #1460

Closed
wants to merge 52 commits into from
Closed
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
deaa7d3
Refactor hostpython3's recipe into a new base class HostPythonRecipe
opacam Dec 4, 2018
7db0c9b
Refactor python3's recipe into a new base class GuestPythonRecipe
opacam Dec 4, 2018
257f2ed
Move hostpython2 and python2 recipes to a new name hostpython2legacy …
opacam Dec 4, 2018
aebfb72
Add the new hostpython2/python2 recipes (v2.7.15)
opacam Dec 4, 2018
55ea69b
Adapt sdl2's stuff to the new python2's build system
opacam Dec 4, 2018
1a6069b
Adapt pythonforandroid's core files to the new python2's build system
opacam Dec 4, 2018
589350b
Adapt python2's test apps to the new python2's build system
opacam Dec 4, 2018
f7d8fda
Enable sqlite support for python recipes
opacam Dec 4, 2018
a159a8d
Add ability to compile recipes with clang
tito Nov 25, 2018
15fccab
Update OpenSSL to 1.1.1 (uses clang for compilation)
tito Nov 25, 2018
221ffe3
Enhance openssl recipe and remove lib_version
opacam Nov 25, 2018
b0196da
Enable openssl support for python recipes
opacam Dec 4, 2018
0d80161
Fix hardcoded python2 entry for Arch
opacam Nov 25, 2018
3060b49
Fix hardcoded python2 entries for BootstrapNDKRecipes
opacam Nov 25, 2018
31d2136
Fix numpy's recipe and adds python3's compatibility.
opacam Dec 4, 2018
df75852
Fix duplicated key in options for python2 test
opacam Nov 25, 2018
80ce54b
Add python3 test for sqlite and openssl and add python3's compatibili…
opacam Nov 25, 2018
10cc29e
Make that travis test python3 with sqlite3 and openssl
opacam Dec 4, 2018
24c8cfb
Update android ndk to r17c, add missing dependency and update documen…
opacam Nov 25, 2018
073edbb
Move gradle stuff from sdl2 to bootstraps/common
opacam Dec 4, 2018
74b48bd
Create service_only bootstrap's files structure to be gradle compatible
opacam Dec 4, 2018
d9dcdde
Adapt service_only's bootstrap c/java code to new python build system
opacam Dec 4, 2018
1b572fd
Adapt service_only's bootstrap to new python/gradle build system and …
opacam Dec 4, 2018
3879811
Add a test app for service_only's bootstrap
inclement Dec 4, 2018
25a9d88
Fix crash for service_only's bootstrap on create_python_bundle
opacam Dec 4, 2018
8d7505a
Create webview bootstrap's files structure to be gradle compatible
opacam Dec 4, 2018
7eb732f
Adapt webview's bootstrap c/java code to new python build system
opacam Dec 4, 2018
8ab14ca
Adapt webview's bootstrap to new python/gradle build system and enabl…
opacam Dec 4, 2018
b5d1cc7
Make it work webview and service_only bootstraps with the latest pyt…
opacam Dec 15, 2018
bd26208
Enable python3's compatibility to bootstraps webview and service_only
opacam Dec 15, 2018
6028ef3
Add travis test for bootstraps webview and service_only
opacam Dec 4, 2018
f495fb1
Improve the libraries loading mechanism when initializing the apk
opacam Dec 8, 2018
e72a7f8
Fix libtorrent+boost (update to latest versions and add python3 compa…
opacam Dec 8, 2018
cf2e137
Fix openssl dependant recipe: cryptography+cffi
opacam Dec 10, 2018
0a2d70a
Update cryptography recipe and grants python3 support
opacam Dec 10, 2018
8de3569
Fix openssl dependant recipe: pycrypto (and grants python3 compatibil…
opacam Dec 10, 2018
d63f746
Fix openssl dependant recipe: scrypt (and grants python3 compatibility)
opacam Dec 10, 2018
676ccd8
Add a testapp for cryptography recipes
opacam Dec 10, 2018
090763c
Remove hardcoded python2 flags for zbar recipe
opacam Dec 11, 2018
0c64a73
Add pyzbar recipe, remove duplicated flags for libzbar and make sure …
opacam Dec 11, 2018
a52d2ff
Remove unneeded flags and grants python3 compatibility for the apsw r…
opacam Dec 11, 2018
68469cb
Remove unneeded flags, update version and grants python3 compatibilit…
opacam Dec 11, 2018
d35b443
Remove hardcoded python2 flags, shorten ldflags and grants python3 co…
opacam Dec 11, 2018
c5c15eb
Update protobuf_cpp recipe and grant python3 compatibility
opacam Dec 11, 2018
bf75e7d
Update M2Crypto recipe and grant python3 compatibility
opacam Dec 15, 2018
fb491c9
Grant python3 compatibility for PyCryptoDome recipe
opacam Dec 15, 2018
c7ed855
Fix hardcoded/unneeded flags for pysha3 recipe and grant python3 comp…
opacam Dec 15, 2018
76b5200
Enhance the encryption test app with new tests
opacam Dec 15, 2018
f01c10d
Add ci tests for encryption recipes
opacam Dec 16, 2018
81ac357
Change docker image from ubuntu to debian stretch for the python3 bui…
opacam Dec 15, 2018
38f3632
Suppress almost all logs for ci builds (fix travis limit of 4mb of logs)
opacam Dec 16, 2018
c903542
Add ability to hide some log messages and hide the unpack logs
opacam Dec 16, 2018
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
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ env:
- ANDROID_SDK_HOME=/opt/android/android-sdk
- ANDROID_NDK_HOME=/opt/android/android-ndk
matrix:
- COMMAND='. venv/bin/activate && cd testapps/ && python setup_testapp_python3.py apk --sdk-dir $ANDROID_SDK_HOME --ndk-dir $ANDROID_NDK_HOME --requirements sdl2,pyjnius,kivy,python3'
- COMMAND='. venv/bin/activate && cd testapps/ && python setup_testapp_python3.py apk --sdk-dir $ANDROID_SDK_HOME --ndk-dir $ANDROID_NDK_HOME --requirements sdl2,pyjnius,kivy,python3,numpy'
# overrides requirements to skip `peewee` pure python module, see:
# https://github.com/kivy/python-for-android/issues/1263#issuecomment-390421054
- COMMAND='. venv/bin/activate && cd testapps/ && python setup_testapp_python3_sqlite_openssl.py apk --sdk-dir $ANDROID_SDK_HOME --ndk-dir $ANDROID_NDK_HOME --requirements libffi,sdl2,pyjnius,kivy,python3,openssl,requests,sqlite3,setuptools'
- COMMAND='. venv/bin/activate && cd testapps/ && python setup_testapp_python2_sqlite_openssl.py apk --sdk-dir $ANDROID_SDK_HOME --ndk-dir $ANDROID_NDK_HOME --requirements sdl2,pyjnius,kivy,python2,openssl,requests,sqlite3,setuptools'
- COMMAND='. venv/bin/activate && cd testapps/ && python setup_testapp_python2.py apk --sdk-dir $ANDROID_SDK_HOME --ndk-dir $ANDROID_NDK_HOME --bootstrap sdl2 --requirements python2,numpy'
# builds only the recipes that moved
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.py2
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ RUN apt -y update -qq \


ENV ANDROID_NDK_HOME="${ANDROID_HOME}/android-ndk"
ENV ANDROID_NDK_VERSION="16b"
ENV ANDROID_NDK_VERSION="17c"
ENV ANDROID_NDK_HOME_V="${ANDROID_NDK_HOME}-r${ANDROID_NDK_VERSION}"

# get the latest version from https://developer.android.com/ndk/downloads/index.html
Expand Down Expand Up @@ -104,7 +104,7 @@ RUN dpkg --add-architecture i386 \
# specific recipes dependencies (e.g. libffi requires autoreconf binary)
RUN apt -y update -qq \
&& apt -y install -qq --no-install-recommends \
autoconf automake cmake gettext libltdl-dev libtool pkg-config \
libffi-dev autoconf automake cmake gettext libltdl-dev libtool pkg-config \
&& apt -y autoremove \
&& apt -y clean

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.py3
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ RUN apt -y update -qq \


ENV ANDROID_NDK_HOME="${ANDROID_HOME}/android-ndk"
ENV ANDROID_NDK_VERSION="16b"
ENV ANDROID_NDK_VERSION="17c"
ENV ANDROID_NDK_HOME_V="${ANDROID_NDK_HOME}-r${ANDROID_NDK_VERSION}"

# get the latest version from https://developer.android.com/ndk/downloads/index.html
Expand Down Expand Up @@ -104,7 +104,7 @@ RUN dpkg --add-architecture i386 \
# specific recipes dependencies (e.g. libffi requires autoreconf binary)
RUN apt -y update -qq \
&& apt -y install -qq --no-install-recommends \
autoconf automake cmake gettext libltdl-dev libtool pkg-config \
libffi-dev autoconf automake cmake gettext libltdl-dev libtool pkg-config \
&& apt -y autoremove \
&& apt -y clean

Expand Down
31 changes: 27 additions & 4 deletions doc/source/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,34 @@ named ``tools``, and you will need to run extra commands to install
the SDK packages needed.

For Android NDK, note that modern releases will only work on a 64-bit
operating system. If you are using a 32-bit distribution (or hardware),
the latest useable NDK version is r10e, which can be downloaded here:
operating system. The minimal, and recommended, NDK version to use is r17c:

- `Linux (64-bits) <https://dl.google.com/android/repository/android-ndk-r17c-linux-x86_64.zip>`_
- `Macos X (64-bits) <https://dl.google.com/android/repository/android-ndk-r17c-darwin-x86_64.zip>`_
- Windows users should create a virtual machine with an GNU Linux os
installed, and then you can follow the described instructions from within
your virtual machine.

.. note::
Versions below r17 may cause troubles while compiling some recipes. Our
tests had been done against ndk versions r17b and r17c. Later versions of
the android ndk still are not proved to work with python-for-android, and
may work or not...so...better to stick to the recommended version (r17c).

If you are using a 32-bit distribution (or hardware),
the latest usable NDK version is r10e, which can be downloaded here:

- `Legacy 32-bit Linux NDK r10e <http://dl.google.com/android/ndk/android-ndk-r10e-linux-x86.bin>`_

.. warning::
**32-bit distributions**

Since the python2 recipe updated to version 2.7.15, the build system has
been changed and you should use an old release of python-for-android, which
contains the legacy python recipe (v2.7.2). The last python-for-android
release with the legacy version of python is version
`0.6.0 <https://github.com/kivy/python-for-android/archive/0.6.0.zip>`_.

First, install a platform to target (you can also replace ``27`` with
a different platform number, this will be used again later)::

Expand All @@ -113,8 +136,8 @@ Then, you can edit your ``~/.bashrc`` or other favorite shell to include new env

# Adjust the paths!
export ANDROIDSDK="$HOME/Documents/android-sdk-27"
export ANDROIDNDK="$HOME/Documents/android-ndk-r10e"
export ANDROIDAPI="27" # Target API version of your application
export ANDROIDNDK="$HOME/Documents/android-ndk-r17c"
export ANDROIDAPI="26" # Target API version of your application
export NDKAPI="19" # Minimum supported API version of your application
export ANDROIDNDKVER="r10e" # Version of the NDK you installed

Expand Down
77 changes: 50 additions & 27 deletions pythonforandroid/archs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,24 @@ def include_dirs(self):
d.format(arch=self))
for d in self.ctx.include_dirs]

def get_env(self, with_flags_in_cc=True):
def get_env(self, with_flags_in_cc=True, clang=False):
env = {}

env['CFLAGS'] = ' '.join([
'-DANDROID', '-mandroid', '-fomit-frame-pointer'
' -D__ANDROID_API__={}'.format(self.ctx.ndk_api),
])
cflags = [
'-DANDROID',
'-fomit-frame-pointer',
'-D__ANDROID_API__={}'.format(self.ctx.ndk_api)]
if not clang:
cflags += ['-mandroid']
else:
cflags += ['-target armv7-none-linux-androideabi']
android_host = 'arm-linux-androideabi'
platform_dir = join(self.ctx.ndk_dir, 'platforms', 'android-{}'.format(self.ctx.ndk_api), 'arch-arm')
toolchain = '{android_host}-4.9'.format(android_host=android_host)
toolchain = join(self.ctx.ndk_dir, 'toolchains', toolchain, 'prebuilt', 'linux-x86_64')
cflags += ['-gcc-toolchain {}'.format(toolchain)]

env['CFLAGS'] = ' '.join(cflags)
env['LDFLAGS'] = ' '

sysroot = join(self.ctx._ndk_dir, 'sysroot')
Expand Down Expand Up @@ -82,8 +93,19 @@ def get_env(self, with_flags_in_cc=True):
env['NDK_CCACHE'] = self.ctx.ccache
env.update({k: v for k, v in environ.items() if k.startswith('CCACHE_')})

cc = find_executable('{command_prefix}-gcc'.format(
command_prefix=command_prefix), path=environ['PATH'])
if clang:
clang_path = join(
self.ctx.ndk_dir, 'toolchains', 'llvm', 'prebuilt',
'linux-x86_64', 'bin')
environ['PATH'] = '{clang_path}:{path}'.format(
clang_path=clang_path, path=environ['PATH'])
exe = join(clang_path, 'clang')
execxx = join(clang_path, 'clang++')
else:
exe = '{command_prefix}-gcc'.format(command_prefix=command_prefix)
execxx = '{command_prefix}-g++'.format(command_prefix=command_prefix)

cc = find_executable(exe, path=environ['PATH'])
if cc is None:
print('Searching path are: {!r}'.format(environ['PATH']))
raise BuildInterruptingException(
Expand All @@ -93,20 +115,20 @@ def get_env(self, with_flags_in_cc=True):
'installed. Exiting.')

if with_flags_in_cc:
env['CC'] = '{ccache}{command_prefix}-gcc {cflags}'.format(
command_prefix=command_prefix,
env['CC'] = '{ccache}{exe} {cflags}'.format(
exe=exe,
ccache=ccache,
cflags=env['CFLAGS'])
env['CXX'] = '{ccache}{command_prefix}-g++ {cxxflags}'.format(
command_prefix=command_prefix,
env['CXX'] = '{ccache}{execxx} {cxxflags}'.format(
execxx=execxx,
ccache=ccache,
cxxflags=env['CXXFLAGS'])
else:
env['CC'] = '{ccache}{command_prefix}-gcc'.format(
command_prefix=command_prefix,
env['CC'] = '{ccache}{exe}'.format(
exe=exe,
ccache=ccache)
env['CXX'] = '{ccache}{command_prefix}-g++'.format(
command_prefix=command_prefix,
env['CXX'] = '{ccache}{execxx}'.format(
execxx=execxx,
ccache=ccache)

env['AR'] = '{}-ar'.format(command_prefix)
Expand All @@ -123,12 +145,13 @@ def get_env(self, with_flags_in_cc=True):
env['READELF'] = '{}-readelf'.format(command_prefix)
env['NM'] = '{}-nm'.format(command_prefix)

hostpython_recipe = Recipe.get_recipe('hostpython2', self.ctx)

# This hardcodes python version 2.7, needs fixing
hostpython_recipe = Recipe.get_recipe(
'host' + self.ctx.python_recipe.name, self.ctx)
env['BUILDLIB_PATH'] = join(
hostpython_recipe.get_build_dir(self.arch),
'build', 'lib.linux-{}-2.7'.format(uname()[-1]))
'build', 'lib.linux-{}-{}'.format(
uname()[-1], self.ctx.python_recipe.major_minor_version_string)
)

env['PATH'] = environ['PATH']

Expand All @@ -151,8 +174,8 @@ class ArchARM(Arch):
class ArchARMv7_a(ArchARM):
arch = 'armeabi-v7a'

def get_env(self, with_flags_in_cc=True):
env = super(ArchARMv7_a, self).get_env(with_flags_in_cc)
def get_env(self, with_flags_in_cc=True, clang=False):
env = super(ArchARMv7_a, self).get_env(with_flags_in_cc, clang=clang)
env['CFLAGS'] = (env['CFLAGS'] +
(' -march=armv7-a -mfloat-abi=softfp '
'-mfpu=vfp -mthumb'))
Expand All @@ -166,8 +189,8 @@ class Archx86(Arch):
command_prefix = 'i686-linux-android'
platform_dir = 'arch-x86'

def get_env(self, with_flags_in_cc=True):
env = super(Archx86, self).get_env(with_flags_in_cc)
def get_env(self, with_flags_in_cc=True, clang=False):
env = super(Archx86, self).get_env(with_flags_in_cc, clang=clang)
env['CFLAGS'] = (env['CFLAGS'] +
' -march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32')
env['CXXFLAGS'] = env['CFLAGS']
Expand All @@ -180,8 +203,8 @@ class Archx86_64(Arch):
command_prefix = 'x86_64-linux-android'
platform_dir = 'arch-x86_64'

def get_env(self, with_flags_in_cc=True):
env = super(Archx86_64, self).get_env(with_flags_in_cc)
def get_env(self, with_flags_in_cc=True, clang=False):
env = super(Archx86_64, self).get_env(with_flags_in_cc, clang=clang)
env['CFLAGS'] = (env['CFLAGS'] +
' -march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel')
env['CXXFLAGS'] = env['CFLAGS']
Expand All @@ -194,8 +217,8 @@ class ArchAarch_64(Arch):
command_prefix = 'aarch64-linux-android'
platform_dir = 'arch-arm64'

def get_env(self, with_flags_in_cc=True):
env = super(ArchAarch_64, self).get_env(with_flags_in_cc)
def get_env(self, with_flags_in_cc=True, clang=False):
env = super(ArchAarch_64, self).get_env(with_flags_in_cc, clang=clang)
incpath = ' -I' + join(dirname(__file__), 'includes', 'arm64-v8a')
env['EXTRA_CFLAGS'] = incpath
env['CFLAGS'] += incpath
Expand Down
13 changes: 5 additions & 8 deletions pythonforandroid/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,11 @@ def strip_libraries(self, arch):
return
strip = sh.Command(strip)

if self.ctx.python_recipe.name == 'python2':
filens = shprint(sh.find, join(self.dist_dir, 'private'),
join(self.dist_dir, 'libs'),
'-iname', '*.so', _env=env).stdout.decode('utf-8')
else:
filens = shprint(sh.find, join(self.dist_dir, '_python_bundle', '_python_bundle', 'modules'),
join(self.dist_dir, 'libs'),
'-iname', '*.so', _env=env).stdout.decode('utf-8')
filens = shprint(sh.find, join(self.dist_dir, '_python_bundle',
'_python_bundle', 'modules'),
join(self.dist_dir, 'libs'),
'-iname', '*.so', _env=env).stdout.decode('utf-8')

logger.info('Stripping libraries in private dir')
for filen in filens.split('\n'):
try:
Expand Down
4 changes: 2 additions & 2 deletions pythonforandroid/bootstraps/common/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def get_bootstrap_name():
# Try to find a host version of Python that matches our ARM version.
PYTHON = join(curdir, 'python-install', 'bin', 'python.host')
if not exists(PYTHON):
print('Could not find hostpython, will not compile to .pyo (this is normal with python3)')
print('Could not find hostpython, will not compile to .pyo '
'(this is normal with python2 and python3)')
PYTHON = None

BLACKLIST_PATTERNS = [
Expand Down Expand Up @@ -151,7 +152,6 @@ def make_python_zip():

if not exists('private'):
print('No compiled python is present to zip, skipping.')
print('this should only be the case if you are using the CrystaX python')
return

global python_files
Expand Down
Loading