如何让`cabal install`命令忽略本地的.cabal配置文件
版本信息
%cabal --version cabal-install version 3.6.2.0 compiled using version 3.6.2.0 of the Cabal library %ghc --version The Glorious Glasgow Haskell Compilation System, version 8.10.7
问题描述
我需要安装weeder。如果当前目录不存在*.cabal文件,运行cabal install weeder可以成功执行。但如果本地存在.cabal文件,且其中包含与weeder的依赖要求冲突的配置时,该命令就会执行失败。
例如,若.cabal文件的build-depends配置项包含text < 1.2.3.0,执行cabal install weeder会返回如下错误:
%cabal install weeder cabal: Could not resolve dependencies: [__0] trying: foobarbaz-0.1.0.0 (user goal) [__1] next goal: text (dependency of foobarbaz) [__1] rejecting: text-1.2.4.1/installed-1.2.4.1 (conflict: foobarbaz => text<1.2.3.0) [__1] skipping: text-1.2.5.0, text-1.2.4.1, text-1.2.4.0, text-1.2.3.2, text-1.2.3.1, text-1.2.3.0 (has the same characteristics that caused the previous version to fail: excluded by constraint '<1.2.3.0' from 'foobarbaz') [__1] trying: text-1.2.2.2 [__2] next goal: deepseq (dependency of text) [__2] rejecting: deepseq-1.4.4.0/installed-1.4.4.0 (conflict: text => base>=4.2 && <4.11, deepseq => base==4.14.3.0/installed-4.14.3.0) [__2] trying: deepseq-1.4.5.0 [__3] next goal: array (dependency of text) [__3] rejecting: array-0.5.4.0/installed-0.5.4.0 (conflict: text => base>=4.2 && <4.11, array => base==4.14.3.0/installed-4.14.3.0) [__3] trying: array-0.5.4.0 [__4] next goal: base (dependency of foobarbaz) [__4] rejecting: base-4.14.3.0/installed-4.14.3.0 (conflict: text => base>=4.2 && <4.11) [__4] skipping: base-4.16.0.0, base-4.15.0.0, base-4.14.3.0, base-4.14.2.0, base-4.14.1.0, base-4.14.0.0, base-4.13.0.0, base-4.12.0.0, base-4.11.1.0, base-4.11.0.0 (has the same characteristics that caused the previous version to fail: excluded by constraint '>=4.2 && <4.11' from 'text') [__4] rejecting: base-4.10.1.0, base-4.10.0.0, base-4.9.1.0, base-4.9.0.0, base-4.8.2.0, base-4.8.1.0, base-4.8.0.0, base-4.7.0.2, base-4.7.0.1, base-4.7.0.0, base-4.6.0.1, base-4.6.0.0, base-4.5.1.0, base-4.5.0.0, base-4.4.1.0, base-4.4.0.0, base-4.3.1.0, base-4.3.0.0, base-4.2.0.2, base-4.2.0.1, base-4.2.0.0, base-4.1.0.0, base-4.0.0.0, base-3.0.3.2, base-3.0.3.1 (constraint from non-upgradeable package requires installed instance) [__4] fail (backjumping, conflict set: base, foobarbaz, text) After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: base, text, deepseq, array, foobarbaz Try running with --minimize-conflict-set to improve the error message.
我目前可以通过两种方式规避这个问题:一是执行安装命令前将foobarbaz.cabal重命名为foobarbaz.cabal.bk,安装完成后再改回原名;二是切换到其他目录执行安装命令。请问是否存在可以直接忽略本地.cabal文件的命令选项?
解决方案
直接使用--ignore-project参数即可,该参数会让cabal完全忽略当前目录下的所有项目配置(包括.cabal文件、cabal.project等),不受本地项目的依赖约束影响,直接进行全局安装:
cabal install weeder --ignore-project
该特性在cabal 3.0及以上版本均支持,你使用的3.6.2.0版本完全兼容该参数。
内容的提问来源于stack exchange,提问作者toku-sa-n
相关产品推荐
相关产品推荐

