Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force `stack` to rebuild an installed package

I often install a package which depends on external libraries and manage to move those external libraries to other locations afterwards, so that compiled programs exit with a loader error.

In those cases I just want stack to rebuild an already installed package, but I don't see how that is possible. stack install --force-dirty doesn't seem to work, as it just tries to rebuild the project in the current working directory.


Recent example:

I'd liked to see whether regex-pcre requires a C library not present on Windows systems, so I hit stack install regex-pcre. That went fine, but then I realized I installed mingw-w64-x86_64-pcre via stacks pacman prior to this. I removed it again via pacman -R and tried to run stack install regex-pcre again, which did not rebuild it. Neither did adding --force-dirty work for the above reason.

like image 346
Sebastian Graf Avatar asked May 15 '16 10:05

Sebastian Graf


1 Answers

Update:

Based on @Michael Snoyman's comment just using this command should be enough to remove the package:

stack exec -- ghc-pkg unregister --force regex-pcre

Original Answer:

I don't know if it's the sanctioned way to do it, but it seems to work. Here is a synopsis:

  1. Locate the ghc-pkg program for the version of GHC you are using
  2. Locate the package-db directory for your resolver version
  3. Run $ghcpkg --package-db $pkgdb unregister --force <package>
  4. Also remove the package file from stack's precompiled directory

Suppose the package we want to remove is zlib-0.5.4.2.

Locating ghc-pkg

Under ~/.stack/programs find the ghc-pkg program appropriate for your compiler version, e.g. ~/.stack/programs/x86_64-osx/ghc-7.10.2/bin/ghc-pkg. Call this $ghcpkg

Locating the package db

Under ~/.stack/snapshots find the pkgdb directory for the resolver you are using, e.g. ~/.stack/snapshots/x86_64-osx/lts-3.1/7.10.2/pkgdb. Call this $pkgdb.

Unregister the package

Run:

$ghcpkg --package-db $pkgdb unregister --force zlib-0.5.4.2

Ignore any warnings about broken or breaking packages.

You can check to see if your package is registered or not with this command:

$ghcpkg --package-db $pkgdb list | grep zlib

Remove the package from the precompiled directory

Under ~/.stack/precompiled locate any directories named zlib-0.5.4.2 and remove the one for your the relevant version of GHC:

find ~/.stack/precompiled -name 'zlib-*'
/bin/rm -rf ...

Reinstall the package

stack --resolver=... install zlib

Stack should report that it is rebuilding the package.

like image 142
ErikR Avatar answered Sep 20 '22 09:09

ErikR