Instantly share code, notes, and snippets.

@cstrahan /ghcs.sh
Last active Aug 29, 2015

Embed
What would you like to do?
cabal sandbox aware ghc wrapper
# This is a cabal-sandbox aware wrapper for GHC.
#
# To see the Template Haskell expansions in my Yesod app,
# I tried running (unseccessfully):
#
# $ ghc -XTemplateHaskell -ddump-splices Foundation.hs
# Foundation.hs:21:8:
# Could not find module `Yesod.Core.Types'
# Use -v to see a list of the files searched for.
#
# The problem is that ghc will (by default) search for
# packages in the locations listed by `ghc-pkg list`.
# But, one can grab the package db from the cabal.sandbox.config
# and pass that path directly to ghc - which is exactly what
# this function does.
#
# Enjoy!
function ghcs {
local DIR=$PWD
local TARGET="cabal.sandbox.config"
while [ ! -e $DIR/$TARGET -a $DIR != "/" ]; do
DIR=$(dirname $DIR)
done
if test $DIR != "/"; then
local DB=$(sed -ne '/^package-db: */{s///p;q;}' "$DIR/$TARGET")
ghc -no-user-package-db -package-db="$DB" "$@"
else
ghc "$@"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment