From 0ddd676ef04a72d89c0fa734aeca0596841874e4 Mon Sep 17 00:00:00 2001 From: Remo Rechkemmer <59358383+monacoremo@users.noreply.github.com> Date: Sun, 7 Feb 2021 22:15:44 +0100 Subject: [PATCH] nix: Add a script to generate a graph of Haskell imports (#1751) --- .gitignore | 1 + nix/devtools.nix | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/.gitignore b/.gitignore index d00cdb788..d6f521cb7 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ __pycache__ *.tix coverage .hpc +imports.png diff --git a/nix/devtools.nix b/nix/devtools.nix index f272bfb24..b3a0bc6cb 100644 --- a/nix/devtools.nix +++ b/nix/devtools.nix @@ -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 < imports.png + digraph { + $imports + $labels + } + EOF + ''; in buildEnv { name = "postgrest-devtools"; @@ -106,5 +142,6 @@ buildEnv { run.bin clean.bin check.bin + importsgraph.bin ]; }