From 97bf18581534282d8135c5dad8a2542d476ad57b Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Tue, 8 Nov 2022 17:35:57 +0100 Subject: [PATCH] common: Extend liblto link fixup function We need to fix another symlink created by gcc-config, so extend the function that was doing it for some other links and rename it - it's not about only liblto any more. --- build_library/build_image_util.sh | 2 +- build_packages | 2 +- common.sh | 47 ++++++++++++++++++++----------- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/build_library/build_image_util.sh b/build_library/build_image_util.sh index 4f01bb6036..b6d92823bc 100755 --- a/build_library/build_image_util.sh +++ b/build_library/build_image_util.sh @@ -189,7 +189,7 @@ emerge_to_image() { # Make sure profile.env has been generated sudo -E ROOT="${root_fs_dir}" env-update --no-ldconfig - fixup_liblto_softlinks "$root_fs_dir" + fixup_gcc_config_softlinks "${root_fs_dir}" # TODO(marineam): just call ${BUILD_LIBRARY_DIR}/check_root directly once # all tests are fatal, for now let the old function skip soname errors. diff --git a/build_packages b/build_packages index 1ad8800f48..9614a20dfb 100755 --- a/build_packages +++ b/build_packages @@ -295,7 +295,7 @@ fi eclean-$BOARD -d packages -fixup_liblto_softlinks "${BOARD_ROOT}" +fixup_gcc_config_softlinks "${BOARD_ROOT}" info "Checking build root" test_image_content "${BOARD_ROOT}" diff --git a/common.sh b/common.sh index 01ccd3861b..2d7013ea7a 100644 --- a/common.sh +++ b/common.sh @@ -976,22 +976,37 @@ clean_qemu_static() { esac } -# Fix up liblto softlink created by gcc-config -fixup_liblto_softlinks() { - local root="$1" +# Fix up various softlinks created by gcc-config +fixup_gcc_config_softlinks() { + # root without trailing slashes, for / it will be empty + local root="${1%%*(/)}" - info "fixup_liblto_softlinks: Looking for broken softlinks in '${root}'" + info "fixup_gcc_config_softlinks: Looking for broken softlinks in '${root}/'" - local link - local target - # check both native (/usr/CHOST/) as well as cross compile (/usr/CHOST/CTARGET) paths - { ls -l "${root}/"usr/*/binutils-bin/lib/bfd-plugins/liblto_plugin.so 2>/dev/null || :; - ls -l "${root}/"usr/*/*/binutils-bin/lib/bfd-plugins/liblto_plugin.so 2>/dev/null || :; } \ - | sed 's:.* \([^[:space:]]\+\) -> \([^[:space:]]\+\):\1 \2:' \ - | while read link target; do - local newtarget=$(echo "$target" | sed "s:${root}:/:") - info " Fixing up broken $link -> $target" - info " sudo ln -sf $newtarget $link" - sudo ln -sf $newtarget $link - done + ( + shopt -s nullglob + local files=( + "${root}"/usr/*/binutils-bin/lib/bfd-plugins/liblto_plugin.so + "${root}"/usr/*/*/binutils-bin/lib/bfd-plugins/liblto_plugin.so + "${root}"/usr/bin/*-cc + ) + local file + local target + local new_target + for file in "${files[@]}"; do + if [[ ! -L "${file}" ]]; then + # not a symlink, ignore + continue + fi + target=$(readlink "${file}") + new_target=${target/#${root}} + if [[ "${target}" == "${new_target}" ]]; then + # nothing to fix, ignore + continue + fi + info " Fixing up broken symlink '${file}' -> '${target}'" + info " sudo ln -sf '${new_target}' '${file}'" + sudo ln -sf "${new_target}" "${file}" + done + ) }