The cabal-sort package
If you have a bunch of packages you may want to compile or recompile, then you need an order of compilation that meets the dependencies. Given a number of cabal package files, this program reads all those files and emits them topologically sorted according to their dependencies. This way you can compile many packages at once, say if a very low-level package has changed.
For compiling a couple of packages from their local darcs repositories in the right order, you may run something like
for dir in `find . -name "*.cabal" | fgrep -v _darcs | xargs cabal-sort --info=dir`; do (cd $dir && cabal install); done
For uploading a set of packages to Hackage in the right order you may run
for dir in `find . -name "*.cabal" | fgrep -v _darcs | xargs cabal-sort --info=dir`; do (cd $dir && rm dist/*.tar.gz && cabal sdist && cabal upload dist/*.tar.gz); done
Problem 1: Given packages A, B, C, where C depends on B and B depends on A, and you call
cabal-sort C.cabal A.cabal
then the emitted order of packages may be wrong, because cabal-sort does not get to know the dependency of C on B. Even if the order is correct, B.cabal is missing in the output and thus the list of cabal files cannot immediately be used for a sequence of cabal-install runs.
Problem 2: We ignore flags and merge all dependencies. This may lead to dependency cycles that cannot occur for any flag assignment.
There is a second program called ghc-pkg-dep that finds recursively all packages that a set of packages depends on. Duplicates are eliminated and the packages are given topologically sorted, such that you can use this for recompilation of the packages.
ghc-pkg-dep pkgA-0.1 pkgB-2.3 pkgC-0.1.2
Unfortunately ghc-pkg runs quite slowly. In order to not get bored you may run the program with --verbose=2 option. Maybe there is a way to query the complete GHC package database at once.
|Versions||0.0.1, 0.0.2, 0.0.2.1, 0.0.3, 0.0.3.1, 0.0.4, 0.0.4.1, 0.0.4.2, 0.0.5, 0.0.5.1, 0.0.5.2, 0.0.5.3|
|Dependencies||base (>=2 && <5), bytestring (>=0.9.1 && <0.10), Cabal (>=1.6 && <1.15), containers (>=0.2 && <0.5), directory (>=1 && <1.2), explicit-exception (>=0.1.6 && <0.2), fgl (>=5.4.2 && <5.5), filepath (>=1.1 && <1.4), process (>=1.0 && <1.2), transformers (==0.2.*), utility-ht (>=0.0.5 && <0.1) [details]|
|Author||Henning Thielemann <firstname.lastname@example.org>|
|Maintainer||Henning Thielemann <email@example.com>|
|Source repository||head: darcs get http://code.haskell.org/~thielema/cabal-sort/
this: darcs get http://code.haskell.org/~thielema/cabal-sort/ --tag 0.0.3.1
|Uploaded||Fri Feb 3 11:22:01 UTC 2012 by HenningThielemann|
|Distributions||LTSHaskell:0.0.5.3, NixOS:0.0.5.3, Stackage:0.0.5.3|
|Downloads||2127 total (46 in the last 30 days)|
|Status||Docs not available [build log]
All reported builds failed as of 2015-12-10 [all 6 reports]
For package maintainers and hackage trustees