|
1 | | -from pythonforandroid.recipe import PyProjectRecipe |
2 | | -from pythonforandroid.util import ensure_dir |
| 1 | +from pythonforandroid.recipe import MesonRecipe |
| 2 | +from pythonforandroid.logger import shprint |
3 | 3 |
|
4 | 4 | from os.path import join |
5 | | -import shutil |
| 5 | +import sh |
6 | 6 |
|
7 | 7 |
|
8 | | -class MatplotlibRecipe(PyProjectRecipe): |
9 | | - version = '3.8.4' |
| 8 | +class MatplotlibRecipe(MesonRecipe): |
| 9 | + version = '3.10.7' |
10 | 10 | url = 'https://github.com/matplotlib/matplotlib/archive/v{version}.zip' |
11 | | - patches = ["skip_macos.patch"] |
12 | | - depends = ['kiwisolver', 'numpy', 'pillow', 'setuptools', 'freetype'] |
| 11 | + depends = ['kiwisolver', 'numpy', 'pillow'] |
13 | 12 | python_depends = ['cycler', 'fonttools', 'packaging', 'pyparsing', 'python-dateutil'] |
| 13 | + hostpython_prerequisites = ["setuptools_scm>=7"] |
| 14 | + patches = ["meson.patch"] |
14 | 15 | need_stl_shared = True |
15 | 16 |
|
16 | | - def generate_libraries_pc_files(self, arch): |
17 | | - """ |
18 | | - Create *.pc files for libraries that `matplotib` depends on. |
19 | | -
|
20 | | - Because, for unix platforms, the mpl install script uses `pkg-config` |
21 | | - to detect libraries installed in non standard locations (our case... |
22 | | - well...we don't even install the libraries...so we must trick a little |
23 | | - the mlp install). |
24 | | - """ |
25 | | - pkg_config_path = self.get_recipe_env(arch)['PKG_CONFIG_PATH'] |
26 | | - ensure_dir(pkg_config_path) |
27 | | - |
28 | | - lib_to_pc_file = { |
29 | | - # `pkg-config` search for version freetype2.pc, our current |
30 | | - # version for freetype, but we have our recipe named without |
31 | | - # the version...so we add it in here for our pc file |
32 | | - 'freetype': 'freetype2.pc', |
33 | | - } |
34 | | - |
35 | | - for lib_name in {'freetype'}: |
36 | | - pc_template_file = join( |
37 | | - self.get_recipe_dir(), |
38 | | - f'lib{lib_name}.pc.template' |
39 | | - ) |
40 | | - # read template file into buffer |
41 | | - with open(pc_template_file) as template_file: |
42 | | - text_buffer = template_file.read() |
43 | | - # set the library absolute path and library version |
44 | | - lib_recipe = self.get_recipe(lib_name, self.ctx) |
45 | | - text_buffer = text_buffer.replace( |
46 | | - 'path_to_built', lib_recipe.get_build_dir(arch.arch), |
47 | | - ) |
48 | | - text_buffer = text_buffer.replace( |
49 | | - 'library_version', lib_recipe.version, |
50 | | - ) |
51 | | - |
52 | | - # write the library pc file into our defined dir `PKG_CONFIG_PATH` |
53 | | - pc_dest_file = join(pkg_config_path, lib_to_pc_file[lib_name]) |
54 | | - with open(pc_dest_file, 'w') as pc_file: |
55 | | - pc_file.write(text_buffer) |
56 | | - |
57 | | - def prebuild_arch(self, arch): |
58 | | - shutil.copyfile( |
59 | | - join(self.get_recipe_dir(), "setup.cfg.template"), |
60 | | - join(self.get_build_dir(arch), "mplsetup.cfg"), |
61 | | - ) |
62 | | - self.generate_libraries_pc_files(arch) |
63 | | - |
64 | 17 | def get_recipe_env(self, arch, **kwargs): |
65 | 18 | env = super().get_recipe_env(arch, **kwargs) |
66 | | - |
67 | | - # we make use of the same directory than `XDG_CACHE_HOME`, for our |
68 | | - # custom library pc files, so we have all the install files that we |
69 | | - # generate at the same place |
70 | | - env['XDG_CACHE_HOME'] = join(self.get_build_dir(arch), 'p4a_files') |
71 | | - env['PKG_CONFIG_PATH'] = env['XDG_CACHE_HOME'] |
72 | | - |
73 | | - # creating proper *.pc files for our libraries does not seem enough to |
74 | | - # success with our build (without depending on system development |
75 | | - # libraries), but if we tell the compiler where to find our libraries |
76 | | - # and includes, then the install success :) |
77 | | - freetype = self.get_recipe('freetype', self.ctx) |
78 | | - free_lib_dir = join(freetype.get_build_dir(arch.arch), 'objs', '.libs') |
79 | | - free_inc_dir = join(freetype.get_build_dir(arch.arch), 'include') |
80 | | - env['CFLAGS'] += f' -I{free_inc_dir}' |
81 | | - env['LDFLAGS'] += f' -L{free_lib_dir}' |
82 | | - |
83 | | - # `freetype` could be built with `harfbuzz` support, |
84 | | - # so we also include the necessary flags...just to be sure |
85 | | - if 'harfbuzz' in self.ctx.recipe_build_order: |
86 | | - harfbuzz = self.get_recipe('harfbuzz', self.ctx) |
87 | | - harf_build = harfbuzz.get_build_dir(arch.arch) |
88 | | - env['CFLAGS'] += f' -I{harf_build} -I{join(harf_build, "src")}' |
89 | | - env['LDFLAGS'] += f' -L{join(harf_build, "src", ".libs")}' |
| 19 | + env['CXXFLAGS'] += ' -Wno-c++11-narrowing' |
90 | 20 | return env |
91 | 21 |
|
| 22 | + def build_arch(self, arch): |
| 23 | + python_path = join(self.ctx.python_recipe.get_build_dir(arch), "android-build", "python3") |
| 24 | + self.extra_build_args += [f'-Csetup-args=-Dpython3_program={python_path}'] |
| 25 | + shprint(sh.cp, self.real_hostpython_location, python_path) |
| 26 | + super().build_arch(arch) |
| 27 | + |
92 | 28 |
|
93 | 29 | recipe = MatplotlibRecipe() |
0 commit comments