diff --git a/pythonforandroid/recipes/Pillow/__init__.py b/pythonforandroid/recipes/Pillow/__init__.py index cd770526ff..ffac810a2b 100644 --- a/pythonforandroid/recipes/Pillow/__init__.py +++ b/pythonforandroid/recipes/Pillow/__init__.py @@ -1,9 +1,9 @@ from os.path import join -from pythonforandroid.recipe import CompiledComponentsPythonRecipe +from pythonforandroid.recipe import PyProjectRecipe -class PillowRecipe(CompiledComponentsPythonRecipe): +class PillowRecipe(PyProjectRecipe): """ A recipe for Pillow (previously known as Pil). @@ -23,67 +23,42 @@ class PillowRecipe(CompiledComponentsPythonRecipe): - libwebp: library to encode and decode images in WebP format. """ - version = '8.4.0' + version = '10.3.0' url = 'https://github.com/python-pillow/Pillow/archive/{version}.tar.gz' site_packages_name = 'PIL' + patches = ["setup.py.patch"] depends = ['png', 'jpeg', 'freetype', 'setuptools'] opt_depends = ['libwebp'] - patches = [join('patches', 'fix-setup.patch')] - call_hostpython_via_targetpython = False - - def get_recipe_env(self, arch=None, with_flags_in_cc=True): - env = super().get_recipe_env(arch, with_flags_in_cc) - - png = self.get_recipe('png', self.ctx) - png_lib_dir = join(png.get_build_dir(arch.arch), '.libs') - png_inc_dir = png.get_build_dir(arch) + def get_recipe_env(self, arch, **kwargs): + env = super().get_recipe_env(arch, **kwargs) jpeg = self.get_recipe('jpeg', self.ctx) jpeg_inc_dir = jpeg_lib_dir = jpeg.get_build_dir(arch.arch) + env["JPEG_ROOT"] = "{}:{}".format(jpeg_lib_dir, jpeg_inc_dir) freetype = self.get_recipe('freetype', self.ctx) free_lib_dir = join(freetype.get_build_dir(arch.arch), 'objs', '.libs') free_inc_dir = join(freetype.get_build_dir(arch.arch), 'include') + env["FREETYPE_ROOT"] = "{}:{}".format(free_lib_dir, free_inc_dir) # harfbuzz is a direct dependency of freetype and we need the proper # flags to successfully build the Pillow recipe, so we add them here. harfbuzz = self.get_recipe('harfbuzz', self.ctx) harf_lib_dir = join(harfbuzz.get_build_dir(arch.arch), 'src', '.libs') harf_inc_dir = harfbuzz.get_build_dir(arch.arch) + env["HARFBUZZ_ROOT"] = "{}:{}".format(harf_lib_dir, harf_inc_dir) + + env["ZLIB_ROOT"] = f"{arch.ndk_lib_dir_versioned}:{self.ctx.ndk.sysroot_include_dir}" # libwebp is an optional dependency, so we add the # flags if we have it in our `ctx.recipe_build_order` - build_with_webp_support = 'libwebp' in self.ctx.recipe_build_order - if build_with_webp_support: + if 'libwebp' in self.ctx.recipe_build_order: webp = self.get_recipe('libwebp', self.ctx) webp_install = join( webp.get_build_dir(arch.arch), 'installation' ) - - # Add libraries includes to CFLAGS - cflags = f' -I{png_inc_dir}' - cflags += f' -I{harf_inc_dir} -I{join(harf_inc_dir, "src")}' - cflags += f' -I{free_inc_dir}' - cflags += f' -I{jpeg_inc_dir}' - if build_with_webp_support: - cflags += f' -I{join(webp_install, "include")}' - cflags += f' -I{self.ctx.ndk.sysroot_include_dir}' - - # Link the basic Pillow libraries...no need to add webp's libraries - # since it seems that the linkage is properly made without it :) - env['LIBS'] = ' -lpng -lfreetype -lharfbuzz -ljpeg -lturbojpeg -lm' - - # Add libraries locations to LDFLAGS - env['LDFLAGS'] += f' -L{png_lib_dir}' - env['LDFLAGS'] += f' -L{free_lib_dir}' - env['LDFLAGS'] += f' -L{harf_lib_dir}' - env['LDFLAGS'] += f' -L{jpeg_lib_dir}' - if build_with_webp_support: - env['LDFLAGS'] += f' -L{join(webp_install, "lib")}' - env['LDFLAGS'] += f' -L{arch.ndk_lib_dir_versioned}' - if cflags not in env['CFLAGS']: - env['CFLAGS'] += cflags + " -lm" + env["WEBP_ROOT"] = f"{join(webp_install, 'lib')}:{join(webp_install, 'include')}" return env diff --git a/pythonforandroid/recipes/Pillow/patches/fix-setup.patch b/pythonforandroid/recipes/Pillow/patches/fix-setup.patch deleted file mode 100644 index 5c5a3d0536..0000000000 --- a/pythonforandroid/recipes/Pillow/patches/fix-setup.patch +++ /dev/null @@ -1,196 +0,0 @@ ---- Pillow.orig/setup.py 2021-11-01 14:50:48.000000000 +0100 -+++ Pillow/setup.py 2021-11-01 14:51:31.000000000 +0100 -@@ -125,7 +125,7 @@ - "codec_fd", - ) - --DEBUG = False -+DEBUG = True # So we can easely triage user issues. - - - class DependencyException(Exception): -@@ -411,46 +411,6 @@ - include_dirs = [] - - pkg_config = None -- if _cmd_exists(os.environ.get("PKG_CONFIG", "pkg-config")): -- pkg_config = _pkg_config -- -- # -- # add configured kits -- for root_name, lib_name in dict( -- JPEG_ROOT="libjpeg", -- JPEG2K_ROOT="libopenjp2", -- TIFF_ROOT=("libtiff-5", "libtiff-4"), -- ZLIB_ROOT="zlib", -- FREETYPE_ROOT="freetype2", -- HARFBUZZ_ROOT="harfbuzz", -- FRIBIDI_ROOT="fribidi", -- LCMS_ROOT="lcms2", -- IMAGEQUANT_ROOT="libimagequant", -- ).items(): -- root = globals()[root_name] -- -- if root is None and root_name in os.environ: -- prefix = os.environ[root_name] -- root = (os.path.join(prefix, "lib"), os.path.join(prefix, "include")) -- -- if root is None and pkg_config: -- if isinstance(lib_name, tuple): -- for lib_name2 in lib_name: -- _dbg(f"Looking for `{lib_name2}` using pkg-config.") -- root = pkg_config(lib_name2) -- if root: -- break -- else: -- _dbg(f"Looking for `{lib_name}` using pkg-config.") -- root = pkg_config(lib_name) -- -- if isinstance(root, tuple): -- lib_root, include_root = root -- else: -- lib_root = include_root = root -- -- _add_directory(library_dirs, lib_root) -- _add_directory(include_dirs, include_root) - - # respect CFLAGS/CPPFLAGS/LDFLAGS - for k in ("CFLAGS", "CPPFLAGS", "LDFLAGS"): -@@ -471,137 +431,6 @@ - for d in os.environ[k].split(os.path.pathsep): - _add_directory(library_dirs, d) - -- _add_directory(library_dirs, os.path.join(sys.prefix, "lib")) -- _add_directory(include_dirs, os.path.join(sys.prefix, "include")) -- -- # -- # add platform directories -- -- if self.disable_platform_guessing: -- pass -- -- elif sys.platform == "cygwin": -- # pythonX.Y.dll.a is in the /usr/lib/pythonX.Y/config directory -- _add_directory( -- library_dirs, -- os.path.join( -- "/usr/lib", "python{}.{}".format(*sys.version_info), "config" -- ), -- ) -- -- elif sys.platform == "darwin": -- # attempt to make sure we pick freetype2 over other versions -- _add_directory(include_dirs, "/sw/include/freetype2") -- _add_directory(include_dirs, "/sw/lib/freetype2/include") -- # fink installation directories -- _add_directory(library_dirs, "/sw/lib") -- _add_directory(include_dirs, "/sw/include") -- # darwin ports installation directories -- _add_directory(library_dirs, "/opt/local/lib") -- _add_directory(include_dirs, "/opt/local/include") -- -- # if Homebrew is installed, use its lib and include directories -- try: -- prefix = ( -- subprocess.check_output(["brew", "--prefix"]) -- .strip() -- .decode("latin1") -- ) -- except Exception: -- # Homebrew not installed -- prefix = None -- -- ft_prefix = None -- -- if prefix: -- # add Homebrew's include and lib directories -- _add_directory(library_dirs, os.path.join(prefix, "lib")) -- _add_directory(include_dirs, os.path.join(prefix, "include")) -- _add_directory( -- include_dirs, os.path.join(prefix, "opt", "zlib", "include") -- ) -- ft_prefix = os.path.join(prefix, "opt", "freetype") -- -- if ft_prefix and os.path.isdir(ft_prefix): -- # freetype might not be linked into Homebrew's prefix -- _add_directory(library_dirs, os.path.join(ft_prefix, "lib")) -- _add_directory(include_dirs, os.path.join(ft_prefix, "include")) -- else: -- # fall back to freetype from XQuartz if -- # Homebrew's freetype is missing -- _add_directory(library_dirs, "/usr/X11/lib") -- _add_directory(include_dirs, "/usr/X11/include") -- -- # SDK install path -- sdk_path = "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk" -- if not os.path.exists(sdk_path): -- try: -- sdk_path = ( -- subprocess.check_output(["xcrun", "--show-sdk-path"]) -- .strip() -- .decode("latin1") -- ) -- except Exception: -- sdk_path = None -- if sdk_path: -- _add_directory(library_dirs, os.path.join(sdk_path, "usr", "lib")) -- _add_directory(include_dirs, os.path.join(sdk_path, "usr", "include")) -- elif ( -- sys.platform.startswith("linux") -- or sys.platform.startswith("gnu") -- or sys.platform.startswith("freebsd") -- ): -- for dirname in _find_library_dirs_ldconfig(): -- _add_directory(library_dirs, dirname) -- if sys.platform.startswith("linux") and os.environ.get( -- "ANDROID_ROOT", None -- ): -- # termux support for android. -- # system libraries (zlib) are installed in /system/lib -- # headers are at $PREFIX/include -- # user libs are at $PREFIX/lib -- _add_directory( -- library_dirs, os.path.join(os.environ["ANDROID_ROOT"], "lib") -- ) -- -- elif sys.platform.startswith("netbsd"): -- _add_directory(library_dirs, "/usr/pkg/lib") -- _add_directory(include_dirs, "/usr/pkg/include") -- -- elif sys.platform.startswith("sunos5"): -- _add_directory(library_dirs, "/opt/local/lib") -- _add_directory(include_dirs, "/opt/local/include") -- -- # FIXME: check /opt/stuff directories here? -- -- # standard locations -- if not self.disable_platform_guessing: -- _add_directory(library_dirs, "/usr/local/lib") -- _add_directory(include_dirs, "/usr/local/include") -- -- _add_directory(library_dirs, "/usr/lib") -- _add_directory(include_dirs, "/usr/include") -- # alpine, at least -- _add_directory(library_dirs, "/lib") -- -- if sys.platform == "win32": -- # on Windows, look for the OpenJPEG libraries in the location that -- # the official installer puts them -- program_files = os.environ.get("ProgramFiles", "") -- best_version = (0, 0) -- best_path = None -- for name in os.listdir(program_files): -- if name.startswith("OpenJPEG "): -- version = tuple(int(x) for x in name[9:].strip().split(".")) -- if version > best_version: -- best_version = version -- best_path = os.path.join(program_files, name) -- -- if best_path: -- _dbg("Adding %s to search list", best_path) -- _add_directory(library_dirs, os.path.join(best_path, "lib")) -- _add_directory(include_dirs, os.path.join(best_path, "include")) -- - # - # insert new dirs *before* default libs, to avoid conflicts - # between Python PYD stub libs and real libraries \ No newline at end of file diff --git a/pythonforandroid/recipes/Pillow/setup.py.patch b/pythonforandroid/recipes/Pillow/setup.py.patch new file mode 100644 index 0000000000..2970e23670 --- /dev/null +++ b/pythonforandroid/recipes/Pillow/setup.py.patch @@ -0,0 +1,76 @@ +--- Pillow/setup.py 2024-05-24 19:35:08.270160608 +0530 ++++ Pillow.mod/setup.py 2024-05-24 22:07:52.741495666 +0530 +@@ -39,6 +39,7 @@ + LCMS_ROOT = None + TIFF_ROOT = None + ZLIB_ROOT = None ++WEBP_ROOT = None + FUZZING_BUILD = "LIB_FUZZING_ENGINE" in os.environ + + if sys.platform == "win32" and sys.version_info >= (3, 13): +@@ -150,6 +151,7 @@ + + + def _find_library_dirs_ldconfig(): ++ return [] + # Based on ctypes.util from Python 2 + + ldconfig = "ldconfig" if shutil.which("ldconfig") else "/sbin/ldconfig" +@@ -460,15 +462,16 @@ + "HARFBUZZ_ROOT": "harfbuzz", + "FRIBIDI_ROOT": "fribidi", + "LCMS_ROOT": "lcms2", ++ "WEBP_ROOT": "libwebp", + "IMAGEQUANT_ROOT": "libimagequant", + }.items(): + root = globals()[root_name] + + if root is None and root_name in os.environ: +- prefix = os.environ[root_name] +- root = (os.path.join(prefix, "lib"), os.path.join(prefix, "include")) ++ root = tuple(os.environ[root_name].split(":")) + + if root is None and pkg_config: ++ continue + if isinstance(lib_name, tuple): + for lib_name2 in lib_name: + _dbg(f"Looking for `{lib_name2}` using pkg-config.") +@@ -495,14 +498,6 @@ + for include_dir in include_root: + _add_directory(include_dirs, include_dir) + +- # respect CFLAGS/CPPFLAGS/LDFLAGS +- for k in ("CFLAGS", "CPPFLAGS", "LDFLAGS"): +- if k in os.environ: +- for match in re.finditer(r"-I([^\s]+)", os.environ[k]): +- _add_directory(include_dirs, match.group(1)) +- for match in re.finditer(r"-L([^\s]+)", os.environ[k]): +- _add_directory(library_dirs, match.group(1)) +- + # include, rpath, if set as environment variables: + for k in ("C_INCLUDE_PATH", "CPATH", "INCLUDE"): + if k in os.environ: +@@ -514,13 +509,10 @@ + for d in os.environ[k].split(os.path.pathsep): + _add_directory(library_dirs, d) + +- _add_directory(library_dirs, os.path.join(sys.prefix, "lib")) +- _add_directory(include_dirs, os.path.join(sys.prefix, "include")) +- + # + # add platform directories + +- if self.disable_platform_guessing: ++ if True: + pass + + elif sys.platform == "cygwin": +@@ -614,7 +606,7 @@ + # FIXME: check /opt/stuff directories here? + + # standard locations +- if not self.disable_platform_guessing: ++ if False: #not self.disable_platform_guessing: + _add_directory(library_dirs, "/usr/local/lib") + _add_directory(include_dirs, "/usr/local/include") +