-
Notifications
You must be signed in to change notification settings - Fork 154
/
repld
executable file
·98 lines (87 loc) · 3.6 KB
/
repld
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
# Auto-restarts ghcid sessions based on changes in dependencies. I.e.,
# while repling clash-lib, any changes in clash-prelude would trigger a
# reload.
#
# Usage:
#
# repld clash-prelude
#
# would start a ghcid session for clash-prelude. Any additional options
# passed to the script would be passed down to ghcid. For example:
#
# repld clash-prelude -T main
#
# would execute test 'main' if clash-prelude compiles successfully.
# Shortcuts exist for all supported libraries:
#
# * `p`, `prelude`, `clash-prelude`
# * `p:tests`, `prelude:tests`, `clash-prelude:tests`
# * `l`, `lib`, `clash-lib`
# * `l:tests`, `lib:tests`, `clash-lib:tests`
# * `c`, `cores`, `clash-cores`
# * `c:tests`, `cores:tests`, `clash-cores:tests`
# * `g`, `ghc`, `clash-ghc`
# * `dev`, `clash-dev`
#
# That means the following will start a repl-loop for clash-lib:
#
# repld l
set -e
GHC=${GHC:-ghc}
inotifywait --help | grep -e "^inotifywait"
ghcid --version
if [[ $1 == "p" || $1 == "prelude" || $1 == "clash-prelude" ]]; then
target="cabal v2-repl clash-prelude --repl-options=-fobject-code --repl-options=-fforce-recomp"
watch="clash-prelude/clash-prelude.cabal"
elif [[ $1 == "p:tests" || $1 == "prelude:tests" || $1 == "clash-prelude:tests" ]]; then
target="cabal v2-repl clash-prelude:unittests"
watch="clash-prelude/src clash-prelude/clash-prelude.cabal"
elif [[ $1 == "l" || $1 == "lib" || $1 == "clash-lib" ]]; then
target="cabal v2-repl clash-lib"
watch="clash-prelude clash-lib/clash-lib.cabal"
elif [[ $1 == "l:tests" || $1 == "lib:tests" || $1 == "clash-lib:tests" ]]; then
target="cabal v2-repl clash-lib:unittests"
watch="clash-prelude clash-lib/src clash-lib/clash-lib.cabal"
elif [[ $1 == "c" || $1 == "cores" || $1 == "clash-cores" ]]; then
target="cabal v2-repl clash-cores"
watch="clash-prelude clash-lib clash-cores/clash-cores.cabal"
elif [[ $1 == "c:tests" || $1 == "cores:tests" || $1 == "clash-cores:tests" ]]; then
target="cabal v2-repl clash-cores:unittests"
watch="clash-prelude clash-lib clash-cores/src clash-cores/clash-cores.cabal"
elif [[ $1 == "g" || $1 == "ghc" || $1 == "clash-ghc" ]]; then
target="cabal v2-repl clash-ghc --repl-options=-fobject-code --repl-options=-fforce-recomp"
watch="clash-prelude clash-lib clash-ghc/clash-ghc.cabal"
elif [[ $1 == "dev" || $1 == "clash-dev" ]]; then
target="./clash-dev"
watch="clash-prelude clash-lib/clash-lib.cabal clash-ghc/clash-ghc.cabal"
else
echo "Unrecognized target. Use one of:" > /dev/stderr
echo " p, prelude, clash-prelude" > /dev/stderr
echo " p:tests, prelude:tests, clash-prelude:tests" > /dev/stderr
echo " l, lib, clash-lib" > /dev/stderr
echo " l:tests, lib:tests, clash-lib:tests" > /dev/stderr
echo " g, ghc, clash-ghc" > /dev/stderr
echo " c, cores, clash-cores" > /dev/stderr
echo " c:tests, cores:tests, clash-cores:tests" > /dev/stderr
echo " dev, clash-dev" > /dev/stderr
exit 1;
fi
restart_cmd=""
for w in ${watch}; do
restart_cmd="${restart_cmd} --restart=${w}"
done
set -x
set +e
while true; do
if [[ ${target} == "./clash-dev" ]]; then
cabal v2-build clash-prelude --write-ghc-environment-files=always
sed -i '/clash-lib/d' .ghc.environment.x86_64-linux-*
sed -i '/clash-ghc/d' .ghc.environment.x86_64-linux-*
fi
ghcid -c "${target} -w ${GHC}" ${restart_cmd} "${@:2}"
inotifywait -e modify,create,delete -r ${watch}
if [[ $? == 130 ]]; then
exit 130
fi
done