From cc10261f60551f7149dc7693dcbcfc411fa9ecd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89rico=20Nogueira?= Date: Tue, 8 Jun 2021 11:43:00 -0300 Subject: [PATCH] common/hooks: speed up generate-runtime-deps. Instead of using file(1) to check for ELF files, just read bytes directly from the file and check if they are the ELF magic bytes. Should probably be factored out into a common function that can be used in other places. --- .../hooks/pre-pkg/04-generate-runtime-deps.sh | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/common/hooks/pre-pkg/04-generate-runtime-deps.sh b/common/hooks/pre-pkg/04-generate-runtime-deps.sh index 8ffd3a71d8eb..0b1a6d0a6025 100644 --- a/common/hooks/pre-pkg/04-generate-runtime-deps.sh +++ b/common/hooks/pre-pkg/04-generate-runtime-deps.sh @@ -47,7 +47,7 @@ store_pkgdestdir_rundeps() { } hook() { - local depsftmp f lf j mapshlibs sorequires _curdep + local depsftmp f lf j mapshlibs sorequires _curdep elfmagic # Disable trap on ERR, xbps-uhelper cmd might return error... but not something # to be worried about because if there are broken shlibs this hook returns @@ -72,18 +72,17 @@ hook() { msg_normal "Skipping dependency scan for ${lf}\n" continue fi - case "$(file -bi "$f")" in - application/x-*executable*|application/x-sharedlib*) - for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do - [ -z "$verify_deps" ] && verify_deps="$nlib" && continue - found=0 - for j in ${verify_deps}; do - [[ $j == $nlib ]] && found=1 && break - done - [[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib" + read -n4 elfmagic < "$f" + if [ "$elfmagic" = $'\177ELF' ]; then + for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do + [ -z "$verify_deps" ] && verify_deps="$nlib" && continue + found=0 + for j in ${verify_deps}; do + [[ $j == $nlib ]] && found=1 && break done - ;; - esac + [[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib" + done + fi done exec 0<&3 # restore stdin rm -f $depsftmp