修复 ghc-pkg check 发现的问题 [英] Fixing issues noted by ghc-pkg check

查看:19
本文介绍了修复 ghc-pkg check 发现的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ghc-pkg check 会列出损坏的软件包,以及它们损坏的原因,这真是太好了.但据我所知,没有自动化的方法来处理那些损坏的包裹.处理破损包裹的推荐方法是什么?(最好不要重装GHC)

It's rather nice that ghc-pkg check will list broken packages, and why they are broken. But as far as I know, there is no automated way to take care of those broken packages. What is the recommended way to deal with broken packages? (Preferably not reinstall GHC)

推荐答案

希望您足够明智,不会破坏全局包数据库中的任何内容.那里的破损很容易意味着需要重新安装 GHC.因此,让我们假设损坏仅限于用户包 db(可能除了用户包覆盖的全局中的一两个包).如果只有少数软件包损坏,您可以通过取消注册有问题的软件包来修复您的设置,

Hopefully, you have been wise enough to not break any in your global package database. Breakage there can easily mean a reinstallation of GHC is necessary. So, let us assume that the breakage is restricted to the user package db (except possibly a package or two in the global shadowed by user packages). If only few packages are broken, you can fix your setup by unregistering the offending packages,

$ ghc-pkg unregister --user borken

这经常会抱怨取消注册 borken 会破坏其他包.无论您是尝试先取消注册,还是立即使用 --force 取消注册 borken 并在之后处理新损坏的,这主要是一个选择问题.确保你只从用户 db 中注销包. 如果情况不是太糟糕,在注销少数包后,ghc-pkg check 将报告 no more broken包.
另一方面,如果大部分包被破坏,完全擦除用户数据库可能会更容易,$ rm -rf ~/.ghc/ghc-version/package.conf.d 或其他操作系统上的等效代码.

that will often complain that unregistering borken will break other packages. Whether you try to unregister those first or unregister borken immediately with --force and deal with the newly broken afterwards is mostly a matter of choice. Make sure that you only unregister packages from the user db. If things aren't too grim, after unregistering a handful of packages, ghc-pkg check will report no more broken packages.
If, on the other hand, a large proportion of packages is broken, it will probably be easier to completely wipe the user db, $ rm -rf ~/.ghc/ghc-version/package.conf.d or the equivalent on other OSs.

无论哪种方式,您都将丢失仍想使用的软件包,因此您将尝试重新安装它们而不重新破坏任何东西.运行

Either way, you will have lost packages you still want to use, so you will try to reinstall them without breaking anything anew. Run

$ cabal install world --dry-run

这将尝试为您使用 cabal-install 安装的所有软件包生成一致的安装计划.如果它没有这样做,它会打印出原因,然后您可以通过向世界文件 (~/.cabal/world) 中列出的包添加约束来解决问题 -例如,虽然我没有损坏的软件包(根据 ghc/ghc-pkg),cabal install world --dry-run 告诉我它无法配置 vector-algorithms-0.5.2,这取决于 vector >= 0.6 &&<0.8(我安装了 vector-0.7.1).原因是 hmatrix-0.12.0.1 需要 vector >= 0.8.将 hmatrix 上的 -any约束"替换为 world 文件中的<0.12"会产生干净的安装计划.
因此,在对 world 文件中的约束稍作摆弄之后,您将从 cabal 获得安装计划.检查这是否会重新安装您已经拥有的任何软件包(安装较新版本可能没问题,重新安装相同版本意味着麻烦).如果您对 cabal 的安装计划感到满意,cabal install world 并在 GHC 忙的时候冲泡一壶好茶.再次运行ghc-pkg check,验证一切正常.

that will try to produce a consistent install plan for all the packages you installed with cabal-install. If it fails to do so, it will print out the reasons, you may then be able to fix the issues by adding constraints to the packages listed in the world file (~/.cabal/world) - for example, although I have no broken packages (according to ghc/ghc-pkg), cabal install world --dry-run told me it could not configure vector-algorithms-0.5.2, which depends on vector >= 0.6 && < 0.8 (I have vector-0.7.1 installed). The reason is that hmatrix-0.12.0.1 requires vector >= 0.8. Replacing the -any "constraint" on hmatrix by a "< 0.12" in the world file produced a clean install-plan.
So, after a bit of fiddling with constraints in the world file, you will get an install plan from cabal. Check whether that would reinstall any packages you already have (installing a newer version is probably okay, reinstalling the same version means trouble). If you're happy with cabal's install-plan, cabal install world and brew a nice pot of tea while GHC is busy. Run ghc-pkg check once more, to verify all is in order.

一个普遍的好建议:如果您不知道安装软件包需要什么,总是先使用 --dry-run.

A piece of generally good advice: If you don't know what installing a package entails, always use --dry-run first.

如果您通过使用 cabal 进行全局安装破坏了您的全局包数据库,那么注销违规者的策略可能会奏效,但它也可能会不可撤销地破坏您的 ghc,这取决于以何种方式破坏了什么.如果您通过安装操作系统发行版中的软件包破坏了全局数据库,请安装新的 GHC,诅咒发行版打包程序,并尝试帮助他们防止进一步的此类事件.

If you broke your global package database by doing global installs with cabal, the strategy of unregistering offenders may work, but it may also irrevocably break your ghc, that depends on what is broken in which way. If you broke your global db by installing packages from your OS distro, install a fresh GHC, curse the distro-packagers, and try to help them prevent further such events.

cabal repair 命令会非常好,但目前,不幸的是,修复损坏的设置需要更多的工作.

A cabal repair command would be very nice, but for the time being, repairing a broken setup is unfortunately much more work.

这篇关于修复 ghc-pkg check 发现的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆