Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best workaround for not having "cabal upgrade"?

Tags:

haskell

cabal

I want to upgrade all packages, not just a specific one with cabal install --upgrade-dependencies.

like image 606
gatoatigrado Avatar asked Aug 01 '11 22:08

gatoatigrado


2 Answers

This bit of shell hackery works for me on OS X:

cabal list --simple-output --installed | awk '{print $1}' | uniq | xargs -I {} cabal install {} --reinstall

EDIT: Now forces a reinstall, and avoids installing a package more than once when more than one version is present. Thanks for the comments!

EDIT YEARS LATER: Now that Cabal sandboxes and Stack exist, I strongly recommend against trying to upgrade packages in place. You'll end up with far fewer headaches if you instead can just wipe out an existing sandbox and reinstall up-to-date dependencies.

like image 87
acfoltzer Avatar answered Nov 15 '22 08:11

acfoltzer


The .cabal/world file contains a list of every package you installed explicitly (listed in a cabal install command, as opposed to pulled through dependencies). Trim it to remove packages that are only useful as dependencies, packages that are deprecated, and version-locked packages that you'd rather upgrade.

Cabal doesn't know how to clean-up after itself, but you can remove almost everything. The next command will reinstall from .cabal/packages (a tarball cache):

cp -t bin .cabal/bin/cabal
rm -rf .cabal/{bin,lib,share} .ghc/*-*-*/
ghc-pkg check |&egrep -- '^[A-Za-z0-9-]+-[0-9]' |xargs -n1 --no-run-if-empty ghc-pkg unregister

Now reinstall everything that was manually installed:

cabal install world --upgrade-dependencies --force-reinstalls
like image 7
Tobu Avatar answered Nov 15 '22 09:11

Tobu