MyNixOS website logo
Description

Remove outdated cabal build artefacts from dist-newstyle.

Simple command line tool to remove cabal build artefacts from `dist-newstyle/build` that are superseded by newer versions of the built package or the Haskell compiler.

Hackage version cabal-clean on Stackage Nightly Stackage LTS version Cabal build

cabal-clean : Remove superseded artefacts of cabal v2-build

Removes compilation artefacts in dist-newstyle/build from older versions of the package or superseded minor versions of GHC.

For the impatient

Installation

cabal install cabal-clean

Run

cd $MY_PROJECT
cabal-clean

This lists the build artifacts under dist-newstyle/build.

---	191M	dist-newstyle/build/x86_64-osx/ghc-7.10.3/$MY_PROJECT-2.9.2
---	 72M	dist-newstyle/build/x86_64-osx/ghc-8.10.4/$MY_PROJECT-2.9.2
---	162M	dist-newstyle/build/x86_64-osx/ghc-9.0.1/$MY_PROJECT-2.9.2
+++	135M	dist-newstyle/build/x86_64-osx/ghc-7.10.3/$MY_PROJECT-2.9.3
---	 70M	dist-newstyle/build/x86_64-osx/ghc-8.10.4/$MY_PROJECT-2.9.3
+++	145M	dist-newstyle/build/x86_64-osx/ghc-8.10.7/$MY_PROJECT-2.9.3
---	159M	dist-newstyle/build/x86_64-osx/ghc-9.0.1/$MY_PROJECT-2.9.3

The superseded ones (assuming ghc-9.0.1 is not on the PATH), printed in red and prefixed by dashes (---), can then be removed by:

cabal-clean --delete

Rationale

v2-cabal (the nix-based cabal) maintains a directory structure for local builds of the form dist-newstyle/build/$ARCH/$HC/$PACKAGE-$VERSION (plus other stuff that does not take up much disk space). During active development with several $HC versions and $VERSION bumps for the $PACKAGE, lots of out-dated build artefacts accumulate over time.

A simple way to clean up is removing the whole dist-newstyle folder, but one might want to keep the build artefacts of the most recent package $VERSIONs of the most recent versions of the Haskell compiler ($HC).

Philosophy

  • Go for saving the most disk space with the simplest approach, rather than a complete clean-up. E.g., don't care about outdated contents in dist-newstyle/package-db as they take little space.

  • Keep only the most recent $VERSION of the package.

  • Keep only the most recent major versions of $HC.

  • Keep only versions build with a $HC which is still on the PATH (since version 0.2).

  • Assume a monopoly of GHC, ignoring other Haskell compilers, so only treat $HCs of the form ghc-$GHCVER.

  • Work autonomously, ignoring cabal files. This saves us parsing various home-grown cabal file formats. The latter could be easy using the Cabal package, but this package is not very stable, and we shy the maintenance effort of depending on Cabal.

  • Dry-run is the default, giving the user opportunity to review the clean-up plan.

Functionality

  • Read the contents of dist-newstyle/build, organizing them into a tree according to the pattern $ARCH/ghc-$GHCVER/$PACKAGE-$VERSION.

  • Display the outdated versions.

    Try to get the disk usage with du -h and display it. (I could not find a Haskell library that gets the disk usage OS-agnostically.)

  • With option --delete actually remove the respective folders.

Examples

List build artifacts of current project, marking superseded ones that can be deleted:

cabal-clean

Actually delete superseded builds:

cabal-clean --delete

Delete superseded builds without changing to directory:

cabal-clean --delete path/to/my/project/dist-newstyle

Delete superseded builds in many projects:

find . -name "dist-newstyle" -exec cabal-clean --delete {} \;

Get help:

cabal-clean --help

Related

cabal v2-clean (as of 2021-08-16)

  • Removes all build artefacts.
  • Does not have a --dry-run preview.
Metadata

Version

0.2.20230609

Executables (1)

  • bin/cabal-clean

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • 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