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, if necessary.

Also use awk instead of "grep|awk" for some minor speedup.
This commit is contained in:
Érico Nogueira 2021-06-08 11:43:00 -03:00 committed by Érico Nogueira Rolim
parent e18333cb8f
commit 6303c2e6ce
1 changed files with 11 additions and 12 deletions

View File

@ -47,7 +47,7 @@ store_pkgdestdir_rundeps() {
} }
hook() { 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 # 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 # to be worried about because if there are broken shlibs this hook returns
@ -72,9 +72,9 @@ hook() {
msg_normal "Skipping dependency scan for ${lf}\n" msg_normal "Skipping dependency scan for ${lf}\n"
continue continue
fi fi
case "$(file -bi "$f")" in read -n4 elfmagic < "$f"
application/x-*executable*|application/x-sharedlib*) if [ "$elfmagic" = $'\177ELF' ]; then
for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do for nlib in $($OBJDUMP -p "$f"|awk '/NEEDED/{print $2}'); do
[ -z "$verify_deps" ] && verify_deps="$nlib" && continue [ -z "$verify_deps" ] && verify_deps="$nlib" && continue
found=0 found=0
for j in ${verify_deps}; do for j in ${verify_deps}; do
@ -82,8 +82,7 @@ hook() {
done done
[[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib" [[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib"
done done
;; fi
esac
done done
exec 0<&3 # restore stdin exec 0<&3 # restore stdin
rm -f $depsftmp rm -f $depsftmp