|
| 1 | +from os import makedirs, remove |
| 2 | +from os.path import exists, join |
| 3 | +import sh |
| 4 | + |
| 5 | +from pythonforandroid.recipe import Recipe |
| 6 | +from pythonforandroid.logger import shprint |
| 7 | + |
| 8 | + |
| 9 | +class LibPthread(Recipe): |
| 10 | + ''' |
| 11 | + This is a dumb recipe. We may need this because some recipes inserted some |
| 12 | + flags `-lpthread` without our control, case of: |
| 13 | +
|
| 14 | + - :class:`~pythonforandroid.recipes.uvloop.UvloopRecipe` |
| 15 | +
|
| 16 | + .. note:: the libpthread doesn't exist in android but it is integrated into |
| 17 | + libc, so we create a symbolic link which we will remove when our build |
| 18 | + finishes''' |
| 19 | + |
| 20 | + def build_arch(self, arch): |
| 21 | + libc_path = join(arch.ndk_lib_dir_versioned, 'libc') |
| 22 | + # Create a temporary folder to add to link path with a fake libpthread.so: |
| 23 | + fake_libpthread_temp_folder = join( |
| 24 | + self.get_build_dir(arch.arch), |
| 25 | + "p4a-libpthread-recipe-tempdir" |
| 26 | + ) |
| 27 | + if not exists(fake_libpthread_temp_folder): |
| 28 | + makedirs(fake_libpthread_temp_folder) |
| 29 | + |
| 30 | + # Set symlinks, and make sure to update them on every build run: |
| 31 | + if exists(join(fake_libpthread_temp_folder, "libpthread.so")): |
| 32 | + remove(join(fake_libpthread_temp_folder, "libpthread.so")) |
| 33 | + shprint(sh.ln, '-sf', |
| 34 | + libc_path + '.so', |
| 35 | + join(fake_libpthread_temp_folder, "libpthread.so"), |
| 36 | + ) |
| 37 | + if exists(join(fake_libpthread_temp_folder, "libpthread.a")): |
| 38 | + remove(join(fake_libpthread_temp_folder, "libpthread.a")) |
| 39 | + shprint(sh.ln, '-sf', |
| 40 | + libc_path + '.a', |
| 41 | + join(fake_libpthread_temp_folder, "libpthread.a"), |
| 42 | + ) |
| 43 | + |
| 44 | + # Add folder as -L link option for all recipes if not done yet: |
| 45 | + if fake_libpthread_temp_folder not in arch.extra_global_link_paths: |
| 46 | + arch.extra_global_link_paths.append( |
| 47 | + fake_libpthread_temp_folder |
| 48 | + ) |
| 49 | + |
| 50 | + |
| 51 | +recipe = LibPthread() |
0 commit comments