From 1d01005ba5036923aa1f5a4f3f64964903c1485f Mon Sep 17 00:00:00 2001 From: Richard Larkin Date: Fri, 27 Sep 2019 23:59:42 +0200 Subject: [PATCH] Python3 pillow recipe (#394) * Pillow 6.1.0 building for python 3 * Added tiff disabling * Removed prefix patch * Removed darwin patch * Removed standard locations patch * Removed patch file altogether * Removed easy_install, renamed to libpillow.a * Added back destdir prefix * Switched to python3 directory * Removed commented code * Remove pkgresources dependency * Adde pillow 6.1.0 to docs --- README.md | 1 + recipes/host_setuptools3/__init__.py | 35 +++++++++++ .../host_setuptools3/setuptools/README.rst | 1 + recipes/pillow/__init__.py | 60 +++++++++++++++++++ toolchain.py | 2 +- 5 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 recipes/host_setuptools3/__init__.py create mode 100644 recipes/host_setuptools3/setuptools/README.rst create mode 100644 recipes/pillow/__init__.py diff --git a/README.md b/README.md index 9fb4031..c3b6c3e 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ You can list the available recipes and their versions with: openssl 1.0.2k photolibrary master pil 2.8.2 + pillow 6.1.0 plyer master pycrypto 2.6.1 pykka 1.2.1 diff --git a/recipes/host_setuptools3/__init__.py b/recipes/host_setuptools3/__init__.py new file mode 100644 index 0000000..4825f34 --- /dev/null +++ b/recipes/host_setuptools3/__init__.py @@ -0,0 +1,35 @@ +from toolchain import Recipe, shprint +from os.path import join, exists +import sh +import os +import fnmatch +import shutil + + +class HostSetuptools3(Recipe): + depends = ["openssl", "hostpython3"] + archs = ["x86_64"] + url = "setuptools" + + def prebuild_arch(self, arch): + hostpython = sh.Command(self.ctx.hostpython) + sh.curl("-O", "https://bootstrap.pypa.io/ez_setup.py") + shprint(hostpython, "./ez_setup.py") + # Extract setuptools egg and remove .pth files. Otherwise subsequent + # python package installations using setuptools will raise exceptions. + # Setuptools version 28.3.0 + site_packages_path = join( + self.ctx.dist_dir, 'hostpython3', + 'lib', 'python3.7', 'site-packages') + os.chdir(site_packages_path) + with open('setuptools.pth', 'r') as f: + setuptools_egg_path = f.read().strip('./').strip('\n') + print("setuptools_egg_path=", setuptools_egg_path) + unzip = sh.Command('unzip') + shprint(unzip, "-o", setuptools_egg_path) + os.remove(setuptools_egg_path) + os.remove('setuptools.pth') + os.remove('easy-install.pth') + shutil.rmtree('EGG-INFO') + +recipe = HostSetuptools3() diff --git a/recipes/host_setuptools3/setuptools/README.rst b/recipes/host_setuptools3/setuptools/README.rst new file mode 100644 index 0000000..f244a47 --- /dev/null +++ b/recipes/host_setuptools3/setuptools/README.rst @@ -0,0 +1 @@ +Make toolchain happy diff --git a/recipes/pillow/__init__.py b/recipes/pillow/__init__.py new file mode 100644 index 0000000..48a1cc9 --- /dev/null +++ b/recipes/pillow/__init__.py @@ -0,0 +1,60 @@ +from toolchain import Recipe, shprint +from os.path import join +import sh +import os +import fnmatch + + +class PillowRecipe(Recipe): + version = "6.1.0" + url = "https://pypi.python.org/packages/source/P/Pillow/Pillow-{version}.tar.gz" + library = "libpillow.a" + depends = ["hostpython3", "host_setuptools3", "freetype", "libjpeg", "python3", "ios"] + pbx_libraries = ["libz", "libbz2"] + include_per_arch = True + + def get_pil_env(self, arch): + build_env = arch.get_env() + build_env["IOSROOT"] = self.ctx.root_dir + build_env["IOSSDKROOT"] = arch.sysroot + build_env["LDSHARED"] = join(self.ctx.root_dir, "tools", "liblink") + build_env["ARM_LD"] = build_env["LD"] + build_env["ARCH"] = arch.arch + build_env["C_INCLUDE_PATH"] = join(arch.sysroot, "usr", "include") + build_env["LIBRARY_PATH"] = join(arch.sysroot, "usr", "lib") + build_env["CFLAGS"] = " ".join([ + "-I{}".format(join(self.ctx.dist_dir, "include", arch.arch, "freetype")) + + " -I{}".format(join(self.ctx.dist_dir, "include", arch.arch, "libjpeg")) + + " -arch {}".format(arch.arch) + ]) + build_env['PATH'] = os.environ['PATH'] + return build_env + + def build_arch(self, arch): + build_env = self.get_pil_env(arch) + hostpython3 = sh.Command(self.ctx.hostpython) + shprint(hostpython3, "setup.py", "build_ext", "--disable-tiff", + "--disable-webp", "-g", _env=build_env) + self.biglink() + + def install(self): + arch = list(self.filtered_archs)[0] + build_dir = self.get_build_dir(arch.arch) + os.chdir(build_dir) + hostpython3 = sh.Command(self.ctx.hostpython) + build_env = self.get_pil_env(arch) + dest_dir = join(self.ctx.dist_dir, "root", "python3") + build_env['PYTHONPATH'] = join(dest_dir, 'lib', 'python3.7', 'site-packages') + shprint(hostpython3, "setup.py", "install", "--prefix", dest_dir, + _env=build_env) + + def biglink(self): + dirs = [] + for root, dirnames, filenames in os.walk(self.build_dir): + if fnmatch.filter(filenames, "*.so.libs"): + dirs.append(root) + cmd = sh.Command(join(self.ctx.root_dir, "tools", "biglink")) + shprint(cmd, join(self.build_dir, "libpillow.a"), *dirs) + +recipe = PillowRecipe() + diff --git a/toolchain.py b/toolchain.py index 18ade30..ab5b42e 100755 --- a/toolchain.py +++ b/toolchain.py @@ -714,7 +714,7 @@ class Recipe(object): def archive_root(self): key = "{}.archive_root".format(self.name) value = self.ctx.state.get(key) - if not value: + if not value and self.url != "": value = self.get_archive_rootdir(self.archive_fn) if value is not None: self.ctx.state[key] = value