Skip to content

Commit fad5dd2

Browse files
authored
Merge pull request #1623 from JonasT/fix_librt
Fix librt recipe requires that NDK folder is writable
2 parents 29f3494 + 1b38735 commit fad5dd2

File tree

2 files changed

+46
-14
lines changed

2 files changed

+46
-14
lines changed

pythonforandroid/archs.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from os.path import (exists, join, dirname, split)
1+
from distutils.spawn import find_executable
22
from os import environ, uname
3+
from os.path import (exists, join, dirname, split)
34
from glob import glob
5+
import shlex
46
import sys
5-
from distutils.spawn import find_executable
67

78
from pythonforandroid.recipe import Recipe
89
from pythonforandroid.util import BuildInterruptingException, build_platform
@@ -20,6 +21,12 @@ def __init__(self, ctx):
2021
super(Arch, self).__init__()
2122
self.ctx = ctx
2223

24+
# Allows injecting additional linker paths used by any recipe.
25+
# This can also be modified by recipes (like the librt recipe)
26+
# to make sure that some sort of global resource is available &
27+
# linked for all others.
28+
self.extra_global_link_paths = []
29+
2330
def __str__(self):
2431
return self.arch
2532

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

5865
env['CFLAGS'] = ' '.join(cflags)
59-
env['LDFLAGS'] = ' '
66+
67+
# Link the extra global link paths first before anything else
68+
# (such that overriding system libraries with them is possible)
69+
env['LDFLAGS'] = ' ' + " ".join([
70+
"-L" + shlex.quote(l)
71+
for l in self.extra_global_link_paths
72+
]) + ' '
6073

6174
sysroot = join(self.ctx._ndk_dir, 'sysroot')
6275
if exists(sysroot):

pythonforandroid/recipes/librt/__init__.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from os import makedirs, remove
2+
from os.path import exists, join
13
import sh
2-
from os.path import join
4+
35
from pythonforandroid.recipe import Recipe
46
from pythonforandroid.logger import shprint
57

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

23-
@property
24-
def librt_path(self):
25-
return join(self.ctx.ndk_platform, 'usr', 'lib', 'librt')
26-
2725
def build_arch(self, arch):
28-
shprint(sh.ln, '-sf', self.libc_path + '.so', self.librt_path + '.so')
29-
shprint(sh.ln, '-sf', self.libc_path + '.a', self.librt_path + '.a')
30-
31-
def postbuild_arch(self, arch):
32-
shprint(sh.rm, self.librt_path + '.so')
33-
shprint(sh.rm, self.librt_path + '.a')
26+
# Create a temporary folder to add to link path with a fake librt.so:
27+
fake_librt_temp_folder = join(
28+
self.get_build_dir(arch.arch),
29+
"p4a-librt-recipe-tempdir"
30+
)
31+
if not exists(fake_librt_temp_folder):
32+
makedirs(fake_librt_temp_folder)
33+
34+
# Set symlinks, and make sure to update them on every build run:
35+
if exists(join(fake_librt_temp_folder, "librt.so")):
36+
remove(join(fake_librt_temp_folder, "librt.so"))
37+
shprint(sh.ln, '-sf',
38+
self.libc_path + '.so',
39+
join(fake_librt_temp_folder, "librt.so"),
40+
)
41+
if exists(join(fake_librt_temp_folder, "librt.a")):
42+
remove(join(fake_librt_temp_folder, "librt.a"))
43+
shprint(sh.ln, '-sf',
44+
self.libc_path + '.a',
45+
join(fake_librt_temp_folder, "librt.a"),
46+
)
47+
48+
# Add folder as -L link option for all recipes if not done yet:
49+
if fake_librt_temp_folder not in arch.extra_global_link_paths:
50+
arch.extra_global_link_paths.append(
51+
fake_librt_temp_folder
52+
)
3453

3554

3655
recipe = LibRt()

0 commit comments

Comments
 (0)