tazpkg annotate modules/find-depends @ rev 898

Module 'get': fix temp dir; module 'find-depends': faster search, add debug messages
author Aleksej Bobylev <al.bobylev@gmail.com>
date Tue Dec 29 22:00:47 2015 +0200 (2015-12-29)
parents d6cbd0c5f273
children 50421cb50644
rev   line source
al@822 1 #!/bin/sh
al@828 2 # TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg
al@828 3 # find-depends - TazPkg module
al@828 4 # Functions that are common to tazpkg and tazpkg-convert, and sourced by them.
al@822 5
al@822 6
al@822 7 # search dependencies for files in $TMP_DIR/$file/fs
al@822 8
al@828 9 find_depends() {
al@828 10 DEFAULT_DEPENDS='glibc-base gcc-lib-base'
al@822 11
al@844 12 [ ! -f "$PKGS_DB/files.list.lzma" ] && tazpkg recharge >/dev/null
al@844 13
al@844 14 for i in "$PKGS_DB/files.list.lzma" \
al@844 15 "$PKGS_DB/undigest/"*"/files.list.lzma"; do
al@898 16 # Extract files.list.lzma to find dependencies
al@898 17 # only lines with .so libs produces much faster search
al@898 18 [ -f "$i" ] && lzma d "$i" -so | fgrep '.so' | fgrep '/lib/' >> "$TMP_DIR/files.list"
al@822 19 done
al@822 20
al@828 21 _ 'Find depends...' 1>&2
al@828 22 libs_found=''
al@844 23 find "$1" -type f | \
al@840 24 while read chkfile; do
al@844 25 [ "$(dd bs=1 skip=1 count=3 < "$chkfile" 2>/dev/null)" != 'ELF' ] && continue
al@844 26
al@822 27 case "$chkfile" in
al@828 28 *.o|*.ko|*.ko.gz|*.ko.xz) continue;;
al@822 29 esac
al@822 30
al@844 31 for lib in $(LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so "$chkfile" 2>/dev/null | sed '/=>/!d;s/ =>.*//'); do
al@898 32 debug "lib='$lib'"
al@822 33 case " $libs_found " in
al@844 34 *\ $lib\ *) continue;;
al@822 35 esac
al@822 36 libs_found="$libs_found $lib"
al@822 37 case "$lib" in
al@822 38 statically|linux-gate.so*|ld-*.so|*/ld-*.so) continue;;
al@822 39 esac
al@840 40 find "${1:-$TMP_DIR/$file/fs}" | grep -q /$lib$ && continue
al@822 41
al@828 42 _n 'for %s' "$lib" 1>&2
al@844 43 echo -ne ' \r' 1>&2
al@828 44
al@844 45 for dep in $(fgrep "$lib" "$TMP_DIR/files.list" | cut -d: -f1); do
al@898 46 debug " dep='$dep'"
al@822 47 case " $DEFAULT_DEPENDS " in
al@822 48 *\ $dep\ *) continue 2;;
al@822 49 esac
al@840 50 grep -qs "^$dep$" "$TMP_DIR/depends" && continue 2
al@822 51 done
al@822 52
al@822 53 if [ -n "$dep" ]; then
al@898 54 debug " add '$dep' to depends"
al@840 55 echo "$dep" >> "$TMP_DIR/depends"
al@822 56 else
al@898 57 debug " add '$lib' to unresolved"
al@840 58 grep -qs ^$lib$ "$TMP_DIR/unresolved" ||
al@840 59 echo "$lib" >> "$TMP_DIR/unresolved"
al@822 60 fi
al@822 61 done
al@822 62 done
al@822 63
al@828 64 spc=''
al@828 65 [ -s "$TMP_DIR/depends" ] &&
al@840 66 sort < "$TMP_DIR/depends" 2>/dev/null | uniq | \
al@822 67 while read file; do
al@822 68 echo -n "$spc$file"
al@828 69 spc=' '
al@822 70 done
al@822 71 }
al@822 72
al@822 73