update mac link script to 1.0

This version is roughly twice as fast.
This commit is contained in:
Rafael Kitover 2016-11-23 03:07:44 -08:00
parent cdae078e42
commit 790c9e13bd
1 changed files with 31 additions and 13 deletions

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
version=0.7 version=1.0
main() { main() {
# parse options # parse options
@ -68,7 +68,7 @@ main() {
mkdir -p "$frameworks" 2>/dev/null mkdir -p "$frameworks" 2>/dev/null
lib_scan "$@" | fully_resolve_links | sort -u | \ scan_libs "$@" | fully_resolve_links | sort -u | \
while read lib; do while read lib; do
if [ -n "$list" ]; then if [ -n "$list" ]; then
echo "$lib" echo "$lib"
@ -116,6 +116,15 @@ quit() {
exit ${1:-0} exit ${1:-0}
} }
scan_libs() {
scratch_dir="$tmp/lib_scan"
mkdir -p "$scratch_dir"
lib_scan "$@"
rm -rf "$scratch_dir"
}
lib_scan() { lib_scan() {
for bin in "$@"; do for bin in "$@"; do
case "$bin" in case "$bin" in
@ -126,12 +135,21 @@ lib_scan() {
;; ;;
esac esac
# if binary is already processed, continue
[ -d "$scratch_dir/$bin" ] && continue
# otherwise mark it processed
mkdir -p "$scratch_dir/$bin"
set -- set --
OLDIFS=$IFS OLDIFS=$IFS
IFS=' IFS='
' '
for lib in $(otool -L "$bin" 2>/dev/null | sed -n 's/^ \([^ ]*\).*/\1/p' | grep -v '^/System/' | grep -v '^/usr/lib/'); do for lib in $(otool -L "$bin" 2>/dev/null \
| awk '/^([^ \t]|([ \t]*\/(System|usr\/lib)\/))/ { next } \
{ sub("^[ \t]*", ""); sub("[ \t]*\\(.*\\)[ \t]*$", ""); print }'); do
[ "$lib" = "$bin" ] && continue [ "$lib" = "$bin" ] && continue
echo "$lib" echo "$lib"
@ -152,15 +170,13 @@ fully_resolve_links() {
file=${file#*/} file=${file#*/}
OLDIFS=$IFS OLDIFS=$IFS
IFS=' IFS='/'
' for part in $file; do
for part in $(echo "$file" | sed 's,^/*,,; s,/*$,,; s,//*,\ [ ! -z "$part" ] && path=$(resolve_link "$path/$part")
,g'); do
path=$(resolve_link "$path/$part")
done done
IFS=$OLDIFS IFS=$OLDIFS
# remove '..' path parts # remove 'foo/..' path parts
while :; do while :; do
case "$path" in case "$path" in
*/../*|*/..) */../*|*/..)
@ -173,18 +189,20 @@ fully_resolve_links() {
done done
# remove trailing /s # remove trailing /s
path=$(echo "$path" | sed 's,/*$,,') while [ "$path" != "${path%/}" ]; do
path=${path%/}
done
echo "$path" echo "$path"
done done
} }
resolve_link() { resolve_link() {
file="$1" file=$1
while [ -h "$file" ]; do while [ -h "$file" ]; do
ls0=`ls -ld "$file"` ls0=$(ls -ld "$file")
new_link=`expr "$ls0" : '.* -> \(.*\)$'` new_link=$(expr "$ls0" : '.* -> \(.*\)$')
if expr "$new_link" : '/.*' > /dev/null; then if expr "$new_link" : '/.*' > /dev/null; then
file="$new_link" file="$new_link"
else else