Skip to content

Instantly share code, notes, and snippets.

@cstrahan
Last active August 29, 2015 13:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cstrahan/8984109 to your computer and use it in GitHub Desktop.
Save cstrahan/8984109 to your computer and use it in GitHub Desktop.
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