Skip to content

Fix librt recipe requires that NDK folder is writable #1623

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

Merged
merged 1 commit into from Jan 30, 2019
Merged
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
19 changes: 16 additions & 3 deletions pythonforandroid/archs.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from os.path import (exists, join, dirname, split)
from distutils.spawn import find_executable
from os import environ, uname
from os.path import (exists, join, dirname, split)
from glob import glob
import shlex
import sys
from distutils.spawn import find_executable

from pythonforandroid.recipe import Recipe
from pythonforandroid.util import BuildInterruptingException, build_platform
Expand All @@ -20,6 +21,12 @@ def __init__(self, ctx):
super(Arch, self).__init__()
self.ctx = ctx

# Allows injecting additional linker paths used by any recipe.
# This can also be modified by recipes (like the librt recipe)
# to make sure that some sort of global resource is available &
# linked for all others.
self.extra_global_link_paths = []

def __str__(self):
return self.arch

Expand Down Expand Up @@ -56,7 +63,13 @@ def get_env(self, with_flags_in_cc=True, clang=False):
cflags.append('-gcc-toolchain {}'.format(toolchain))

env['CFLAGS'] = ' '.join(cflags)
env['LDFLAGS'] = ' '

# Link the extra global link paths first before anything else
# (such that overriding system libraries with them is possible)
env['LDFLAGS'] = ' ' + " ".join([
"-L" + shlex.quote(l)
for l in self.extra_global_link_paths
]) + ' '

sysroot = join(self.ctx._ndk_dir, 'sysroot')
if exists(sysroot):
Expand Down
41 changes: 30 additions & 11 deletions pythonforandroid/recipes/librt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from os import makedirs, remove
from os.path import exists, join
import sh
from os.path import join

from pythonforandroid.recipe import Recipe
from pythonforandroid.logger import shprint

Expand All @@ -20,17 +22,34 @@ class LibRt(Recipe):
def libc_path(self):
return join(self.ctx.ndk_platform, 'usr', 'lib', 'libc')

@property
def librt_path(self):
return join(self.ctx.ndk_platform, 'usr', 'lib', 'librt')

def build_arch(self, arch):
shprint(sh.ln, '-sf', self.libc_path + '.so', self.librt_path + '.so')
shprint(sh.ln, '-sf', self.libc_path + '.a', self.librt_path + '.a')

def postbuild_arch(self, arch):
shprint(sh.rm, self.librt_path + '.so')
shprint(sh.rm, self.librt_path + '.a')
# Create a temporary folder to add to link path with a fake librt.so:
fake_librt_temp_folder = join(
self.get_build_dir(arch.arch),
"p4a-librt-recipe-tempdir"
)
if not exists(fake_librt_temp_folder):
makedirs(fake_librt_temp_folder)

# Set symlinks, and make sure to update them on every build run:
if exists(join(fake_librt_temp_folder, "librt.so")):
remove(join(fake_librt_temp_folder, "librt.so"))
shprint(sh.ln, '-sf',
self.libc_path + '.so',
join(fake_librt_temp_folder, "librt.so"),
)
if exists(join(fake_librt_temp_folder, "librt.a")):
remove(join(fake_librt_temp_folder, "librt.a"))
shprint(sh.ln, '-sf',
self.libc_path + '.a',
join(fake_librt_temp_folder, "librt.a"),
)

# Add folder as -L link option for all recipes if not done yet:
if fake_librt_temp_folder not in arch.extra_global_link_paths:
arch.extra_global_link_paths.append(
fake_librt_temp_folder
)


recipe = LibRt()