From d9db3995dba3879b94f61058627b4279706347f9 Mon Sep 17 00:00:00 2001 From: Jonas Thiem Date: Sat, 15 Sep 2018 14:39:48 +0200 Subject: [PATCH 1/2] Add a way to get the toolchain-specific include paths --- pythonforandroid/build.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pythonforandroid/build.py b/pythonforandroid/build.py index 8cba4553d4..c73465795e 100644 --- a/pythonforandroid/build.py +++ b/pythonforandroid/build.py @@ -37,6 +37,8 @@ class Context(object): cython = None # the cython interpreter name ndk_platform = None # the ndk platform directory + toolchain_path = None # toolchain with gcc bin and platform includes + toolchain_include_path = None # toolchain's platform-specific includes dist_name = None # should be deprecated in favour of self.dist.dist_name bootstrap = None @@ -408,8 +410,30 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir, toolchain_prefix)) ok = False + # Get toolchain-specific folders: self.toolchain_prefix = toolchain_prefix self.toolchain_version = toolchain_version + self.toolchain_path = None + self.toolchain_include_path = None + if self.ndk == "crystax": + self.toolchain_path = (self.ndk_dir + "/toolchains/" + + toolchain_prefix + "-" + toolchain_version + + "/prebuilt/" + py_platform + "-x86_64/") + + # Find exact include path for gcc-specific files: + self.toolchain_include_path = os.path.join( + self.toolchain_path, "lib", "gcc", + toolchain_prefix) + folder_pick = "" + for folder in os.listdir(self.toolchain_include_path): + if folder.startswith(toolchain_version) and \ + (folder_pick is None or folder > folder_pick) and \ + os.path.exists(os.path.join( + self.toolchain_include_path, folder, "include")): + folder_pick = folder + self.toolchain_include_path = os.path.join( + self.toolchain_include_path, folder_pick, "include") + # Modify the path so that sh finds modules appropriately environ['PATH'] = ( '{ndk_dir}/toolchains/{toolchain_prefix}-{toolchain_version}/' From 73a527320a569a59fada6ef9e231eb2c7345aa69 Mon Sep 17 00:00:00 2001 From: Jonas Thiem Date: Sat, 15 Sep 2018 14:40:05 +0200 Subject: [PATCH 2/2] Add python3crystax support to reportlab --- .../recipes/reportlab/__init__.py | 40 +++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/pythonforandroid/recipes/reportlab/__init__.py b/pythonforandroid/recipes/reportlab/__init__.py index 9b9bb49ad7..03355b2c83 100644 --- a/pythonforandroid/recipes/reportlab/__init__.py +++ b/pythonforandroid/recipes/reportlab/__init__.py @@ -1,4 +1,4 @@ -import os, sh +import os, sh, sys from pythonforandroid.recipe import CompiledComponentsPythonRecipe from pythonforandroid.util import (current_directory, ensure_dir) from pythonforandroid.logger import (info, shprint) @@ -7,7 +7,29 @@ class ReportLabRecipe(CompiledComponentsPythonRecipe): version = 'c088826211ca' url = 'https://bitbucket.org/rptlab/reportlab/get/{version}.tar.gz' - depends = ['python2', 'freetype'] + depends = [['python3crystax', 'python2'], 'freetype'] + + def get_recipe_env(self, arch=None): + env = super(ReportLabRecipe, self).get_recipe_env(arch) + + if self.ctx.ndk == "crystax": + # Prevent gcc from picking up host stdlib: + cflags = " -nostdinc " + + # Get toolchain dir and crystax ndk base dir: + ndk_platform_dir = self.ctx.ndk_platform + ndk_dir = self.ctx.ndk_dir + + # Add includes to ndk's /usr/include and toolchain include path + # (no idea why latter is necessary, but without it, things like + # stdarg.h are missing) + cflags += ( + " -I" + os.path.join(ndk_platform_dir, "usr", "include") + + " -I" + os.path.join(self.ctx.toolchain_include_path) + ) + if cflags not in env['CFLAGS']: + env['CFLAGS'] += cflags + return env def prebuild_arch(self, arch): if not self.is_patched(arch): @@ -33,8 +55,18 @@ def prebuild_arch(self, arch): sh.wget("http://www.reportlab.com/ftp/pfbfer-20070710.zip", "-O", pfbfile) sh.unzip("-u", "-d", os.path.join(recipe_dir, "src", "reportlab", "fonts"), pfbfile) if os.path.isfile("setup.py"): - with open('setup.py', 'rb') as f: - text = f.read().replace('_FT_LIB_', ft_lib_dir).replace('_FT_INC_', ft_inc_dir) + if sys.version_info[0] < 3: + with open('setup.py', 'rb') as f: + text = f.read().replace('_FT_LIB_', ft_lib_dir).replace('_FT_INC_', ft_inc_dir) + else: + with open('setup.py', 'rb') as f: + text = f.read().replace( + b'_FT_LIB_', + ft_lib_dir.encode("utf-8", "replace") + ).replace( + b'_FT_INC_', + ft_inc_dir.encode("utf-8", "replace") + ) with open('setup.py', 'wb') as f: f.write(text)