Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt reportlab recipe for python3crystax [WIP] [DONT MERGE!] #1357

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions pythonforandroid/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}/'
Expand Down
38 changes: 35 additions & 3 deletions pythonforandroid/recipes/reportlab/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -8,6 +8,28 @@ class ReportLabRecipe(CompiledComponentsPythonRecipe):
version = 'c088826211ca'
url = 'https://bitbucket.org/rptlab/reportlab/get/{version}.tar.gz'
depends = [('python2', 'python3crystax'), '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):
Expand All @@ -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)

Expand Down