强制`stack`重建已安装的软件包 [英] Force `stack` to rebuild an installed package
问题描述
我经常安装一个依赖于外部库的软件包,然后设法将这些外部库移到其他位置,以便编译后的程序以一个加载程序错误退出。
在这些情况下,我只希望堆栈重新构建已安装的软件包,但我不明白这是如何实现的。 stack install --force-dirty
似乎不起作用,因为它只是试图在当前工作目录中重建项目。
最近的例子:
我很想看看 regex- pcre
需要在Windows系统上不存在的C库,所以我打了 stack install regex-pcre
。这很好,但后来我意识到我通过 stack
s <$ c $安装了 mingw-w64-x86_64-pcre
c> pacman 在此之前。我再次通过 pacman -R
删除它,并试图再次运行 stack install regex-pcre
,但没有重建它。由于上述原因,
基于@Michael Snoyman的评论,仅仅使用这个命令应该足以移除包:
stack exec - ghc-pkg unregister --force regex-pcre
原始答案:
我不知道这是否是受到认可的方式,但它似乎工作。这里是一个简介:
- 找到版本的
ghc-pkg
程序您正在使用的GHC - 找到您的解析器版本的package-db目录
- 运行
$ ghcpkg --package-db $ pkgdb unregister --force< package>
- 同时从堆栈的
预编译
目录中移除包文件
假设我们要移除的软件包是 zlib-0.5.4.2
。
查找ghc-pkg
在〜/ .stack /适合你的编译器版本的ghc-pkg程序,例如〜/ .STACK /方案/ x86_64的-OSX / GHC-7.10.2 / bin中/ GHC-PKG
。调用这个 $ ghcpkg
查找软件包db
在〜/ .stack / snapshots下为您正在使用的解析器找到 pkgdb
目录,例如〜/ .STACK /快照/ x86_64的-OSX / LTS-3.1 / 7.10.2 /了pkgdb
。调用这个 $ pkgdb
。 取消注册包
运行:
$ ghcpkg --package-db $ pkgdb unregister --force zlib-0.5 .4.2
忽略任何有关损坏或中断软件包的警告。
您可以使用以下命令检查您的软件包是否已注册:
$ ghcpkg --package -db $ pkgdb list | grep zlib
从预编译
目录
$ b 在
〜/ .stack / precompiled
下找到名为 zlib-0.5.4.2
,然后移除GHC的相关版本: find〜/ .stack / precompiled -name'zlib- *'
/ bin / rm -rf ...
重新安装软件包
stack --resolver = ... install zlib
Stack应该报告它正在重建软件包。
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 stack
s 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.
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:
- Locate the
ghc-pkg
program for the version of GHC you are using - Locate the package-db directory for your resolver version
- Run
$ghcpkg --package-db $pkgdb unregister --force <package>
- 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.
这篇关于强制`stack`重建已安装的软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!