-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge.sh
executable file
·54 lines (45 loc) · 1.32 KB
/
merge.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh
#set -e
stopAt=${1:-Main}
topomodules=$(graphmod --toposort --no-cabal Main.hs -isrc 2>/dev/null |
awk -e "/^${stopAt}\$/,/^Main\$/ { next }; { print }")
cat <<EOF
---
--- Merged modules: $(echo ${topomodules})
---
EOF
topoexcludes=$(echo '^\(import@*&\|[&]+\)\('$topomodules'\)\($\|&@*$\|(@*$\)' |
sed 's, ,\\|,g; s,\.,\\.,g; s,@,\.,g; s,&, ,g')
alllangpragmas=$(awk -e '/^[ ]*AllowAmbiguousTypes/,/^$$/ { print; }' holotype.cabal | tr -d , | xargs echo)
for p in ${alllangpragmas} TemplateHaskell
do echo "{-# LANGUAGE $p #-}"
done
for module in $topomodules
do
file=$(echo $module | sed 's,^,src/,; s,\.,/,g; s,$,\.hs,')
sed -e ':a' -e '/^import {-# SOURCE #-}$/N; s/\n//' $file |
grep --no-filename '^import ' |
grep -v '{-# \(SOURCE\)' |
grep -v "${topoexcludes}"
done | sort | uniq
for module in $topomodules
do
file=$(echo $module | sed 's,^,src/,; s,\.,/,g; s,$,\.hs,')
cat <<EOF
---
--- Module $module (from ${file})
---
EOF
sed -e '/^import {-# SOURCE #-}$/N; s/\n//' $file |
grep -v --no-filename '^import \|OPTIONS_GHC\|LANGUAGE' |
awk -e '
/^module /,/^[ )]*where$/ { next }
{ print }
'
done
cat <<EOF
---
---
---
main = undefined
EOF