Skip to content

Commit e413cef

Browse files
misl6ShyamQt
authored andcommitted
Updates matplotlib, fixes an issue related to shared libc++ (kivy#2645)
* Updates matplotlib, fixes an issue related to shared libc++ * Cleanup
1 parent 91e1b63 commit e413cef

File tree

8 files changed

+41
-290
lines changed

8 files changed

+41
-290
lines changed

pythonforandroid/recipe.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ class Recipe(with_metaclass(RecipeMeta)):
123123
"""
124124

125125
need_stl_shared = False
126-
'''Some libraries or python packages may need to be linked with android's
127-
stl. We can automatically do this for any recipe if we set this property to
126+
'''Some libraries or python packages may need the c++_shared in APK.
127+
We can automatically do this for any recipe if we set this property to
128128
`True`'''
129129

130130
stl_lib_name = 'c++_shared'
@@ -492,20 +492,6 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True):
492492
if arch is None:
493493
arch = self.filtered_archs[0]
494494
env = arch.get_env(with_flags_in_cc=with_flags_in_cc)
495-
496-
if self.need_stl_shared:
497-
env['CPPFLAGS'] = env.get('CPPFLAGS', '')
498-
env['CPPFLAGS'] += ' -I{}'.format(self.ctx.ndk.libcxx_include_dir)
499-
500-
env['CXXFLAGS'] = env['CFLAGS'] + ' -frtti -fexceptions'
501-
502-
if with_flags_in_cc:
503-
env['CXX'] += ' -frtti -fexceptions'
504-
505-
env['LDFLAGS'] += ' -L{}'.format(arch.ndk_lib_dir)
506-
env['LIBS'] = env.get('LIBS', '') + " -l{}".format(
507-
self.stl_lib_name
508-
)
509495
return env
510496

511497
def prebuild_arch(self, arch):

pythonforandroid/recipes/cppy/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33

44
class CppyRecipe(PythonRecipe):
55
site_packages_name = 'cppy'
6-
7-
# Pin to commit: `Nucleic migration and project documentation`,
8-
# because the official releases are too old, at time of writing
9-
version = '4e0b956'
6+
version = '1.1.0'
107
url = 'https://github.com/nucleic/cppy/archive/{version}.zip'
118
call_hostpython_via_targetpython = False
129
# to be detected by the matplotlib install script

pythonforandroid/recipes/kiwisolver/__init__.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,9 @@
33

44
class KiwiSolverRecipe(CppCompiledComponentsPythonRecipe):
55
site_packages_name = 'kiwisolver'
6-
# Pin to commit `docs: attempt to fix doc building`, the latest one
7-
# at the time of writing, just to be sure that we have te most up to date
8-
# version, but it should be pinned to an official release once the c++
9-
# changes that we want to include are merged to master branch
10-
# Note: the commit we want to include is
11-
# `Cppy use update and c++11 compatibility` (4858730)
12-
version = '0846189'
6+
version = '1.3.2'
137
url = 'https://github.com/nucleic/kiwi/archive/{version}.zip'
148
depends = ['cppy']
159

16-
def get_recipe_env(self, arch=None, with_flags_in_cc=True):
17-
env = super().get_recipe_env(arch, with_flags_in_cc)
18-
if self.need_stl_shared:
19-
# kiwisolver compile flags does not honor the standard flags:
20-
# `CPPFLAGS` and `LDLIBS`, so we put in `CFLAGS` and `LDFLAGS` to
21-
# correctly link with the `c++_shared` library
22-
env['CFLAGS'] += f' -I{self.ctx.ndk.libcxx_include_dir}'
23-
env['CFLAGS'] += ' -frtti -fexceptions'
24-
25-
env['LDFLAGS'] += f' -L{arch.ndk_lib_dir}'
26-
env['LDFLAGS'] += f' -l{self.stl_lib_name}'
27-
return env
28-
2910

3011
recipe = KiwiSolverRecipe()

pythonforandroid/recipes/matplotlib/__init__.py

Lines changed: 11 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,18 @@
1-
2-
from pythonforandroid.logger import info_notify
31
from pythonforandroid.recipe import CppCompiledComponentsPythonRecipe
42
from pythonforandroid.util import ensure_dir
53

64
from os.path import join
5+
import shutil
76

87

98
class MatplotlibRecipe(CppCompiledComponentsPythonRecipe):
109

11-
version = '3.1.3'
10+
version = '3.5.2'
1211
url = 'https://github.com/matplotlib/matplotlib/archive/v{version}.zip'
1312

14-
depends = ['numpy', 'png', 'setuptools', 'freetype', 'kiwisolver']
15-
16-
python_depends = ['pyparsing', 'cycler', 'python-dateutil']
17-
18-
# We need to patch to:
19-
# - make mpl install work without importing numpy
20-
# - make mpl use shared libraries for freetype and png
21-
# - make mpl link to png16, to match p4a library name for png
22-
# - prevent mpl trying to build TkAgg, which wouldn't work
23-
# on Android anyway but has build issues
24-
patches = ['mpl_android_fixes.patch']
13+
depends = ['kiwisolver', 'numpy', 'pillow', 'setuptools', 'freetype']
2514

26-
call_hostpython_via_targetpython = False
15+
python_depends = ['cycler', 'fonttools', 'packaging', 'pyparsing', 'python-dateutil']
2716

2817
def generate_libraries_pc_files(self, arch):
2918
"""
@@ -42,10 +31,9 @@ def generate_libraries_pc_files(self, arch):
4231
# version for freetype, but we have our recipe named without
4332
# the version...so we add it in here for our pc file
4433
'freetype': 'freetype2.pc',
45-
'png': 'png.pc',
4634
}
4735

48-
for lib_name in {'freetype', 'png'}:
36+
for lib_name in {'freetype'}:
4937
pc_template_file = join(
5038
self.get_recipe_dir(),
5139
f'lib{lib_name}.pc.template'
@@ -67,83 +55,26 @@ def generate_libraries_pc_files(self, arch):
6755
with open(pc_dest_file, 'w') as pc_file:
6856
pc_file.write(text_buffer)
6957

70-
def download_web_backend_dependencies(self, arch):
71-
"""
72-
During building, host needs to download the jquery-ui package (in order
73-
to make it work the mpl web backend). This operation seems to fail
74-
in our CI tests, so we download this package at the expected location
75-
by the mpl install script which is defined by the environ variable
76-
`XDG_CACHE_HOME` (we modify that one in our `get_recipe_env` so it will
77-
be the same regardless of the host platform).
78-
"""
79-
80-
env = self.get_recipe_env(arch)
81-
82-
info_notify('Downloading jquery-ui for matplatlib web backend')
83-
# We use the same jquery-ui version than mpl's setup.py script,
84-
# inside function `_download_jquery_to`
85-
jquery_sha = (
86-
'f8233674366ab36b2c34c577ec77a3d70cac75d2e387d8587f3836345c0f624d'
87-
)
88-
url = "https://jqueryui.com/resources/download/jquery-ui-1.12.1.zip"
89-
target_file = join(env['XDG_CACHE_HOME'], 'matplotlib', jquery_sha)
90-
91-
info_notify(f'Will download into {env["XDG_CACHE_HOME"]}')
92-
ensure_dir(join(env['XDG_CACHE_HOME'], 'matplotlib'))
93-
self.download_file(url, target_file)
94-
9558
def prebuild_arch(self, arch):
96-
with open(join(self.get_recipe_dir(), 'setup.cfg.template')) as fileh:
97-
setup_cfg = fileh.read()
98-
99-
with open(join(self.get_build_dir(arch), 'setup.cfg'), 'w') as fileh:
100-
fileh.write(setup_cfg.format(
101-
ndk_sysroot_usr=join(self.ctx.ndk.sysroot, 'usr')))
102-
59+
shutil.copyfile(
60+
join(self.get_recipe_dir(), "setup.cfg.template"),
61+
join(self.get_build_dir(arch), "mplsetup.cfg"),
62+
)
10363
self.generate_libraries_pc_files(arch)
104-
self.download_web_backend_dependencies(arch)
10564

10665
def get_recipe_env(self, arch=None, with_flags_in_cc=True):
10766
env = super().get_recipe_env(arch, with_flags_in_cc)
108-
if self.need_stl_shared:
109-
# matplotlib compile flags does not honor the standard flags:
110-
# `CPPFLAGS` and `LDLIBS`, so we put in `CFLAGS` and `LDFLAGS` to
111-
# correctly link with the `c++_shared` library
112-
env['CFLAGS'] += ' -I{}'.format(self.ctx.ndk.libcxx_include_dir)
113-
env['CFLAGS'] += ' -frtti -fexceptions'
114-
115-
env['LDFLAGS'] += ' -L{}'.format(arch.ndk_lib_dir)
116-
env['LDFLAGS'] += ' -l{}'.format(self.stl_lib_name)
117-
118-
# we modify `XDG_CACHE_HOME` to download `jquery-ui` into that folder,
119-
# or mpl install will fail when trying to download/install it, but if
120-
# we have the proper package already downloaded, it will use the cached
121-
# package to successfully finish the installation.
122-
# Note: this may not be necessary for some local systems, but it is
123-
# for our CI provider: `gh-actions`, which will
124-
# fail trying to download the `jquery-ui` package
125-
env['XDG_CACHE_HOME'] = join(self.get_build_dir(arch), 'p4a_files')
67+
12668
# we make use of the same directory than `XDG_CACHE_HOME`, for our
12769
# custom library pc files, so we have all the install files that we
12870
# generate at the same place
71+
env['XDG_CACHE_HOME'] = join(self.get_build_dir(arch), 'p4a_files')
12972
env['PKG_CONFIG_PATH'] = env['XDG_CACHE_HOME']
13073

131-
# We set a new environ variable `NUMPY_INCLUDES` to be able to tell
132-
# the matplotlib script where to find our numpy without importing it
133-
# (which will fail, because numpy isn't installed in our hostpython)
134-
env['NUMPY_INCLUDES'] = join(
135-
self.ctx.get_site_packages_dir(arch),
136-
'numpy', 'core', 'include',
137-
)
138-
13974
# creating proper *.pc files for our libraries does not seem enough to
14075
# success with our build (without depending on system development
14176
# libraries), but if we tell the compiler where to find our libraries
14277
# and includes, then the install success :)
143-
png = self.get_recipe('png', self.ctx)
144-
env['CFLAGS'] += f' -I{png.get_build_dir(arch)}'
145-
env['LDFLAGS'] += f' -L{join(png.get_build_dir(arch.arch), ".libs")}'
146-
14778
freetype = self.get_recipe('freetype', self.ctx)
14879
free_lib_dir = join(freetype.get_build_dir(arch.arch), 'objs', '.libs')
14980
free_inc_dir = join(freetype.get_build_dir(arch.arch), 'include')

pythonforandroid/recipes/matplotlib/libpng.pc.template

Lines changed: 0 additions & 10 deletions
This file was deleted.

pythonforandroid/recipes/matplotlib/mpl_android_fixes.patch

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)