-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunPlugin.sh
executable file
·40 lines (32 loc) · 1.05 KB
/
runPlugin.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
#!/usr/bin/env bash
# Runs AstPlugin.
#
# This script makes the following assumptions:
# - The current working directory contains a Cabal project
# - All of the project's dependencies are in the database of ghc-pkg
# - AstPlugin is also in the database of ghc-pkg
# All of these requirements can be satisfied by running in nix-shell
set -e
function pkgName {
# FIXME: Duplicated in dump-package.sh
for CABAL in *.cabal
do
grep -i "name[ ]*:" < "$CABAL" | grep -o ":.*" | grep -o "[^: ].*"
return
done
}
function getAsts {
PKG=$(pkgName)
RESULT=$(build)
echo "$RESULT" | grep "^{" | jq -c ". + {package: \"$PKG\"}"
echo "$RESULT" | grep -v "^{" > /dev/stderr
}
function build {
# Override pkg db to get project's dependencies and AstPlugin
GHC_PKG=$(ghc-pkg list | head -n 1 | tr -d ':')
OPTIONS="-package-db=$GHC_PKG -package AstPlugin -fplugin=AstPlugin.Plugin"
# NOTE: GHC plugins write to stderr!
cabal --ghc-options="$OPTIONS" build 2>&1 1>/dev/null
}
cabal configure
getAsts | jq -s '.'