Force `stack` to rebuild an installed package

浪尽此生 提交于 2019-11-29 12:39:59

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/37236892/force-stack-to-rebuild-an-installed-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!