Last active
April 16, 2018 15:04
-
-
Save bboozzoo/a363e591075cb4d4faae39b4066ac411 to your computer and use it in GitHub Desktop.
tool for listing Golang package sizes
This file contains 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/bash | |
set -e -o pipefail | |
tmpfile=$(mktemp -t gopkgsize.XXXXX) | |
sizesfile=$(mktemp -t gopktsize-output.XXXXX) | |
trap "rm -f $tmpfile" EXIT | |
go build -work -v -x "$@" 2>$tmpfile | |
# grab WORK= | |
fline=$(head -1 $tmpfile) | |
if [[ "$fline" != WORK=* ]]; then | |
echo "unexpected build log line: '$fline'" | |
exit 1 | |
fi | |
eval "$fline" | |
#linkfile=$tmpfile | |
linkfile=$WORK/b001/importcfg.link | |
for p in $(grep 'packagefile ' < $linkfile | sort -u | cut -f2 -d' '); do | |
pkg=$(cut -f1 -d'=' <<< "$p") | |
f=$(cut -f2 -d'=' <<< "$p") | |
fp=$(eval "echo $f") | |
sz=$(du -hxs $fp | awk '{print $1}') | |
echo $sz $pkg >> $sizesfile | |
done | |
sort -rh < $sizesfile | |
echo "consider removing workdir $WORK" >&2 | |
echo "package size report written to $sizesfile" >&2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment