frabrooks
frabrooks

Reputation: 155

How does cabal work out what directory it is in and look for targets?

I'm getting a strange error in emacs haskell-mode on. When emacs calls the cabal process via:

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

the build fails as if cabal is in the wrong directory:

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.

but appending pwd or ls to the command i.e.:

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

shows it is in the correct directory:

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.

Changing the command to:

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

works fine and, bizarrely, so does:

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

This is on Windows 10 and happens no matter what I set as the default shell (cygwin, git bash, cmd etc.) in emacs (i.e. shell-file-name in the elisp expression above).

Meanwhile, if I load up each shell/terminal outside of emacs, or if I downgrade to cabal 2.4, it builds fine and the problem is gone.

Tried to replicate the problem on Ubuntu 20.04 (with cabal 2.4 and 3.2) and failed so my guess is this is specific to Windows and some new behaviour of cabal 3.2 compared to 2.4.

Can anyone explain this weird behaviour?


Set up: Windows 10, GHC 8.10.2, Cabal 3.2.0.0, emacs 27.1, haskell-mode 20201120.755

See previous (less specific) questions for more detail and everything I've tried:

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

Upvotes: 2

Views: 478

Answers (1)

sclv
sclv

Reputation: 38893

Since the answer was hidden by an overzealous mod, I'll repost: this problem was due to a bug in path handling in Cabal on Windows.

There is a PR in progress which resolves this: https://github.com/haskell/cabal/pull/7310

Upvotes: 2

Related Questions