Last active
December 19, 2015 23:59
-
-
Save alexanderkjeldaas/6037973 to your computer and use it in GitHub Desktop.
Safer cabal --upgrade-dependencies. Easy detection of non-optimal upper bounds. Unregister broken packages with ghc. Reset ghc pkg db.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# unregister broken GHC packages. Run this a few times to resolve | |
# dependency rot in installed packages. ghc-pkg-clean -f | |
# cabal/dev/packages*.conf also works. | |
function ghc-pkg-clean() { | |
for p in `ghc-pkg check $* 2>&1 | grep problems | awk '{print $6}' | sed -e 's/:$//'` | |
do | |
echo unregistering $p; ghc-pkg $* unregister $p | |
done | |
} | |
# remove all installed GHC/cabal packages, leaving ~/.cabal binaries | |
# and docs in place. When all else fails, use this to get out of | |
# dependency hell and start over. | |
function ghc-pkg-reset() { | |
read -p 'erasing all your user ghc and cabal packages - are you sure (y/n) ? ' ans | |
test x$ans == xy && ( \ | |
echo 'erasing directories under ~/.ghc'; rm -rf `find ~/.ghc -maxdepth 1 -type d`; \ | |
echo 'erasing ~/.cabal/lib'; rm -rf ~/.cabal/lib; \ | |
) | |
} | |
# Utility to constrain cabal from messing with global packages. If you install | |
# packages distributed with ghc as global packages and optionally the haskell | |
# platform as global packages, then the following command line will save you from | |
# messing up: | |
# $ cabal install `echo eval $(ghc-global-constraints)` | |
# or | |
# $ cabal install --upgrade-dependencies `echo eval $(ghc-global-constraints)` | |
function ghc-global-constraints() { | |
ghc-pkg list --global | tail -n+2 | head -n-1 | grep -v '(' | while read a; do | |
VER=${a##*-} | |
PKG=${a%-*} | |
echo -n "--constraint='$PKG==$VER' " | |
done | |
} | |
# Quick check to see which upper bounds are probably in need of an upgrade. Example usage: | |
# $ cabal-check-upper-bounds ./iproute.cabal | |
# Package Build-Depends:, upper bound base 5 | |
# | |
# Package doctest, upper bound >= 0.9.3 | |
# pkg: doctest 0.9.7 | |
# From that output we can see that doctest could potentially be upgraded to version 0.9.7 | |
function cabal-check-upper-bounds() { | |
grep '>=' $1 | | |
grep -v 'if ' | | |
grep -vi cabal-version | | |
perl -p -e 's,>=.*<,,;s/,//;' | while read a b; do | |
echo "Package $a, upper bound $b"; | |
BEST_PKG=$(egrep "pkg: $a " ~/.cabal/packages/hackage.haskell.org/00-index.cache | | |
sort -r| | |
head -n 1 | | |
cut -d ' ' -f1,2,3); | |
echo $BEST_PKG; | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment