Skip to content

Instantly share code, notes, and snippets.

@marineam
Created September 6, 2016 02:42
Show Gist options
  • Save marineam/ee97b96481135e1cc27e4869443fd60b to your computer and use it in GitHub Desktop.
Save marineam/ee97b96481135e1cc27e4869443fd60b to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
eval $(go env)
tmp=$(mktemp)
trap "rm -f '$tmp'" EXIT
find "$GOROOT/src" -name '*.go' -type f -printf '%h\n' \
| grep -v -e '/cmd/' -e '/internal/' -e '/testdata/' \
| sed -e "s%^$GOROOT/src/%^%" -e 's%$%$%' | sort -u > $tmp
if [[ $# -eq 0 ]]; then
set -- $(equery -q depends dev-lang/go)
fi
files=$(equery -q files --filter=obj "$@")
elfs=$(scanelf -qyRF '#s%F' --symbol 'runtime.text' $files)
pkgs=""
for f in $elfs; do
pkgs+=$(readelf -Ws "$f" \
| sed -e 's%.* %%' -e '/\.\./d' -e 's%\.[^/]*%%' \
| grep -f $tmp | sort -u)
done
sort <<<"$pkgs" | uniq -c | sort -n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment