Created
June 25, 2018 07:24
-
-
Save johnjcamilleri/e3fa55ba6293524f1477d617e82628b6 to your computer and use it in GitHub Desktop.
Produce dependencies graph for Haskell project
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 | |
# 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