Cabal 如何确定它所在的目录并寻找目标?

问题描述

我在打开 emacs haskell 模式时遇到一个奇怪的错误。当 emacs 通过以下方式调用 cabal 进程时:

(call-process shell-file-name  nil output nil shell-command-switch "cabal build")

构建失败就好像 cabal 位于错误的目录中:

cabal.exe: No targets given and there is no package in the current directory. 
Use the target 'all' for all packages in the project or specify packages or 
components by name or location. See 'cabal build --help' for more details on 
target options.

但将 pwdls 附加到命令中,即:

(call-process shell-file-name  nil output nil shell-command-switch "pwd ; cabal build")

显示它在正确的目录中:

f/path/to/my-project 
cabal.exe: No targets given and there is no package in the current directory. 
Use the target 'all' for all packages in the project or specify packages or 
components by name or location. See 'cabal build --help' for more details on 
target options.

将命令更改为:

(call-process shell-file-name  nil output nil shell-command-switch "cabal build all")

工作正常,而且奇怪的是:

(call-process shell-file-name  nil output nil shell-command-switch "cd . ; cabal build")`

这是在 Windows 10 上,无论我在 emacs 中将什么设置为认 shell(cygwin、git bash、cmd 等)都会发生(即上面 elisp 表达式中的 shell-file-name)。

与此同时,如果我在 emacs 之外加载每个 shell/终端,或者如果我降级到 cabal 2.4,它构建良好并且问题消失了。

尝试在 Ubuntu 20.04(使用 cabal 2.4 和 3.2)上复制该问题但失败了,所以我猜测这是特定于 Windows 和 cabal 3.2 与 2.4 相比的一些新行为。

谁能解释这种奇怪的行为?


设置:Windows 10、GHC 8.10.2、Cabal 3.2.0.0、emacs 27.1、haskell-mode 20201120.755

有关更多详细信息以及我尝试过的所有内容,请参阅以前的(不太具体的)问题:

emacs haskell-mode with cabal project. "Unrecognised target syntax for ` --ghc-option=ferror-spans`."

https://emacs.stackexchange.com/questions/63078/bizarre-behaviour-using-call-process-cabal-fails-as-if-it-is-in-wrong-directo

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)