Skip to content

Instantly share code, notes, and snippets.

@johnjcamilleri
Created June 25, 2018 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnjcamilleri/e3fa55ba6293524f1477d617e82628b6 to your computer and use it in GitHub Desktop.
Save johnjcamilleri/e3fa55ba6293524f1477d617e82628b6 to your computer and use it in GitHub Desktop.
Produce dependencies graph for Haskell project
#!/bin/sh
# Produce PNG of module dependencies (requires GraphViz `dot` command)
# John J. Camilleri, 2018
# Configurable options
dotfile="_deps.dot"
imgfile="_deps.png"
searchin="src"
# Start
modules=`find ${searchin} -name "*.hs"`
modnames=""
for file in $modules ; do
modname=`ack "^module (\\S+)" "$file" --output="\\$1"`
modnames="${modname} ${modnames}"
done
echo "digraph {" > "$dotfile"
echo "rankdir=\"BT\";" >> "$dotfile"
for file in $modules ; do
modname=`ack "^module (\\S+)" "$file" --output="\\$1"`
imports=`ack "^import( qualified)? (\\S+)" "$file" --output="\\$2"`
for imp in $imports ; do
if [[ $modnames = *"$imp"* ]]; then
echo "\"${modname}\" -> \"${imp}\";" >> "$dotfile"
fi
done
done
echo "}" >> "$dotfile"
dot "$dotfile" -Tpng > "$imgfile"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment