Last active
November 2, 2025 14:12
-
-
Save mohd-akram/3b8b4a75cc8fafd59aef00e5e39a4488 to your computer and use it in GitHub Desktop.
Compare the dependencies listed by a MacPorts port with the output of otool
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| set -euo pipefail | |
| usage() { | |
| printf >&2 "usage: %s [-a] [portname]\n" "$(basename "$0")" | |
| } | |
| archive= | |
| verbose= | |
| while getopts :av opt; do | |
| case $opt in | |
| a) archive=1 ;; | |
| v) verbose=1 ;; | |
| ?) usage; exit 2 | |
| esac | |
| done | |
| shift $((OPTIND-1)) | |
| if ! [ "${1-}" ]; then | |
| name=$(basename "$PWD") | |
| else | |
| case $1 in | |
| subport=*) name=${1#subport=} ;; | |
| *) name=$1 | |
| esac | |
| fi | |
| variants=$(port info --line --variants "${1-}" | | |
| awk -vRS=, -vORS= '$1{print "-" $1}') | |
| if [ "$archive" ]; then | |
| base=https://packages.macports.org | |
| dir=$base/$name | |
| file=$(curl -fsSL "$dir/" | grep -o '"[^"]*\.tbz2"' | tr -d \" | | |
| sort -V | tail -n1) | |
| url=$dir/$file | |
| d=/tmp/mparchives/$(basename "$file" .tbz2) | |
| if ! [ -d "$d" ]; then | |
| mkdir -p "$d.tmp" | |
| curl -fsSL "$url" | tar -C "$d.tmp" -xf - | |
| mv "$d.tmp" "$d" | |
| fi | |
| contents=$(find "$d" -type f) | |
| variants=$variants$(printf '%s\n' "$file" | { grep -o '+[^.]*' || :; }) | |
| else | |
| contents=$(port -q contents "$name") | |
| variants=$variants$(port info --line --fullname active and "${1-}" | | |
| sed 's/^[^+]*//') | |
| fi | |
| get_libs() { | |
| while read -r f | |
| do if [ -x "$f" ] && ! [ -L "$f" ]; then printf "%s\n" "$f"; fi | |
| done | sed -e 's/"/"\\""/g' -e 's/.*/"&"/' | xargs -E '' otool -L | | |
| awk '/^[[:space:]]/{print $1}' | sort | uniq | |
| } | |
| libs=$(printf '%s\n' "$contents" | get_libs) | |
| { | |
| # portfile deps | |
| port info --line --depends_lib -- "${1-}" $variants | tr , \\n | |
| echo | |
| # actual deps | |
| printf '%s\n' "$libs" | | |
| sed -e 's/"/"\\""/g' -e 's/.*/"&"/' | xargs -E '' port -q provides | | |
| awk -v name="$name" '$1!=name{print $1}' | sort | uniq | |
| } | awk ' | |
| /^$/{ c = 1; next } | |
| { if(c) b[$1] = 1; else a[$1] = 1 } | |
| END { | |
| for (p in a) if (!b[p]) print "- " p | |
| for (p in b) if (!a[p]) print "+ " p | |
| } | |
| ' | sort -k2,2 || { | |
| printf '%s: failed to get diff\n' "$(basename "$0")" | |
| exit 1 | |
| } | |
| if [ "$verbose" ] && [ "$libs" ]; then | |
| printf >&2 '\nLibraries:\n%s\n' "$libs" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment