nix: Add a script to generate a graph of Haskell imports (#1751)

This commit is contained in:
Remo Rechkemmer
2021-02-07 22:15:44 +01:00
committed by GitHub
parent c93e8f9e0c
commit 0ddd676ef0
2 changed files with 38 additions and 0 deletions
+1
View File
@@ -21,3 +21,4 @@ __pycache__
*.tix
coverage
.hpc
imports.png
+37
View File
@@ -3,6 +3,7 @@
, checkedShellScript
, devCabalOptions
, entr
, graphviz
, silver-searcher
, style
, tests
@@ -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";
@@ -106,5 +142,6 @@ buildEnv {
run.bin
clean.bin
check.bin
importsgraph.bin
];
}