Skip to content

Commit

Permalink
nix: Add a script to generate a graph of Haskell imports (#1751)
Browse files Browse the repository at this point in the history
  • Loading branch information
monacoremo authored Feb 7, 2021
1 parent c93e8f9 commit 0ddd676
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ __pycache__
*.tix
coverage
.hpc
imports.png
37 changes: 37 additions & 0 deletions nix/devtools.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
, checkedShellScript
, devCabalOptions
, entr
, graphviz
, silver-searcher
, style
, tests
Expand Down Expand Up @@ -96,6 +97,41 @@ let
${style}/bin/postgrest-lint
${style}/bin/postgrest-style-check
'';

importsgraph =
checkedShellScript
{
name = "postgrest-importsgraph";
docs =
''
Render the imports between PostgREST modules as a graph.
Output is written to 'imports.png' in the root directory of the project.
'';
inRootDir = true;
}
''
imports=$(
grep -rE 'import .*PostgREST\.' src main \
| sed -E \
-e 's|/|\.|g' \
-e 's/(src|main)\.(.*)\.hs:import .*(PostgREST\.\S+)( .*)?/"\2" -> "\3"/'
)
labels=$(
grep -rE '^(--)?\s*Description\s*:' src main \
| sed -E \
-e 's|/|\.|g' \
-e 's/^(src|main)\.(.*)\.hs:(--)?\s*Description\s*:\s*(.*)$/"\2" [label="\2\\n\4"]/'
)
cat <<EOF | ${graphviz}/bin/dot -Tpng > imports.png
digraph {
$imports
$labels
}
EOF
'';
in
buildEnv {
name = "postgrest-devtools";
Expand All @@ -106,5 +142,6 @@ buildEnv {
run.bin
clean.bin
check.bin
importsgraph.bin
];
}

0 comments on commit 0ddd676

Please sign in to comment.