MyNixOS website logo
Description

Topologically sort cabal packages.

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

Note that cabal-install does this automatically since version 0.10 when you call it will multiple directory names as arguments. However, when the constraint solver in cabal-install fails you may still use cabal-sort for an automated build.

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

Sometimes you have to inspect a number of packages manually, e.g. in order to adapt your packages to a new GHC version. In this case I found it useful to run

for dir in `find . -name "*.cabal" | fgrep -v _darcs | xargs cabal-sort --info=dir`; do (cd $dir; bash); done

This way you start a local shell for every package. Then you can easily access commands in the shell history that you already run for previous packages, e.g. editor *.cabal. After you finished a package, you switch to the next package simply by leaving the shell by calling exit.

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.

You also have options --parallel and --makefile that support parallel compilation. The first option is for manual parallelization and the second one allows you to compile parallelly using make's -j/--jobs option.

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. The packages must already be registered with ghc-pkg.

ghc-pkg-dep pkgA-0.1 pkgB-2.3 pkgC-0.1.2

On GHC versions before 7.0 ghc-pkg runs quite slowly. In order to not get bored you may run the program with --verbose=2 option.

Related packages: rpmbuild-order

Metadata

Version

0.1.2

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows