haskell / cabal

Official upstream development repository for Cabal and cabal-install
https://haskell.org/cabal
Other
1.61k stars 691 forks source link

`v2-build` fails when there are white spaces in path to `ghcup\bin\ghc-pkg.exe` #8314

Open Lev135 opened 2 years ago

Lev135 commented 2 years ago

Describe the bug cabal v2-build fails to build clean cabal-generated project with library and executable. According to warnings and error message it's seems it (or ghcup) doesn't work correctly with white space in file path. Without library everything works fine. v1-build also work.

To Reproduce

Expected behavior Executable will be successfuly built.

Log

Resolving dependencies...
Build profile: -w ghc-8.10.7 -O1
In order, the following will be built (use -v for more details):
 - test-cabal-0.1.0.0 (lib) (first run)
 - test-cabal-0.1.0.0 (exe:test-cabal) (first run)
Configuring library for test-cabal-0.1.0.0..
Warning: 'extra-lib-dirs: Files\ghcup\msys64\mingw64\lib' directory does not
exist.
Warning: 'extra-lib-dirs: Files\ghcup\msys64\mingw64\lib' directory does not
exist.
Warning: 'include-dirs: Files\ghcup\msys64\mingw64\include' directory does not
exist.
Warning: 'include-dirs: Files\ghcup\msys64\mingw64\include' directory does not
exist.
Preprocessing library for test-cabal-0.1.0.0..
Building library for test-cabal-0.1.0.0..
[1 of 1] Compiling MyLib            ( src\MyLib.hs, D:\dvorkin_lev\Haskell\test-cabal\dist-newstyle\build\x86_64-windows\ghc-8.10.7\test-cabal-0.1.0.0\build\MyLib.o 
)
cabal-3.6.2.0.exe: Failed to build test-cabal-0.1.0.0 (which is required by
exe:test-cabal from test-cabal-0.1.0.0). The failure occurred during the final
install step. The exception was:
dieVerbatim: user error (cabal-3.6.2.0.exe: 'C:\Program
Files\ghcup\bin\ghc-pkg.exe' exited with an
error:
test-cabal-0.1.0.0: Warning: library-dirs: C:\Program doesn't exist or isn't a
directory
test-cabal-0.1.0.0: Warning: dynamic-library-dirs: C:\Program doesn't exist or
isn't a directory
test-cabal-0.1.0.0: Warning: include-dirs: C:\Program doesn't exist or isn't a
directory
test-cabal-0.1.0.0: Warning: include-dirs:
D:\dvorkin_lev\Haskell\test-cabal\Files\ghcup\msys64\mingw64\include doesn't
exist or isn't a directory
test-cabal-0.1.0.0: Warning: include-dirs:
D:\dvorkin_lev\Haskell\test-cabal\dist-newstyle\build\x86_64-windows\ghc-8.10.7\test-cabal-0.1.0.0\build\Files\ghcup\msys64\mingw64\include
doesn't exist or isn't a directory
test-cabal-0.1.0.0: Warning: haddock-interfaces:
D:\dvorkin_lev\Haskell\test-cabal\dist-newstyle\build\x86_64-windows\ghc-8.10.7\test-cabal-0.1.0.0\doc\html\test-cabal\test-cabal.haddock
doesn't exist or isn't a file
test-cabal-0.1.0.0: Warning: haddock-html:
D:\dvorkin_lev\Haskell\test-cabal\dist-newstyle\build\x86_64-windows\ghc-8.10.7\test-cabal-0.1.0.0\doc\html\test-cabal
doesn't exist or isn't a directory
test-cabal-0.1.0.0: library-dirs: Files\ghcup\msys64\mingw64\lib is a relative
path which makes no sense (as there is nothing for it to be relative to). You
can make paths relative to the package database itself by using ${pkgroot}.
(use --force to override)
test-cabal-0.1.0.0: dynamic-library-dirs: Files\ghcup\msys64\mingw64\lib is a
relative path which makes no sense (as there is nothing for it to be relative
to). You can make paths relative to the package database itself by using
${pkgroot}. (use --force to override)
)

System information Operating system Windows 10

cabal-install version 3.6.2.0
compiled using version 3.6.2.0 of the Cabal library
Lev135 commented 2 years ago

Upd. v1-build fails when trying to add extra libraries with similar errors:

mintty-0.1.4-AFZfdEdKJet3r0mUOoGb3u failed during the final install step. The
exception was:
dieVerbatim: user error (cabal-3.6.2.0.exe: 'C:\Program
Files\ghcup\bin\ghc-pkg.exe' exited with an
error:
mintty-0.1.4: Warning: library-dirs: C:\Program doesn't exist or isn't a
directory
mintty-0.1.4: Warning: dynamic-library-dirs: C:\Program doesn't exist or isn't
a directory
mintty-0.1.4: Warning: include-dirs: C:\Program doesn't exist or isn't a
directory
mintty-0.1.4: Warning: haddock-interfaces: C:\Program
Files\cabal\doc\x86_64-windows-ghc-8.10.7\mintty-0.1.4\html\mintty.haddock
doesn't exist or isn't a file
mintty-0.1.4: Warning: haddock-html: C:\Program
Files\cabal\doc\x86_64-windows-ghc-8.10.7\mintty-0.1.4\html doesn't exist or
isn't a directory
mintty-0.1.4: library-dirs: Files\ghcup\msys64\mingw64\lib is a relative path
which makes no sense (as there is nothing for it to be relative to). You can
make paths relative to the package database itself by using ${pkgroot}. (use
--force to override)
mintty-0.1.4: dynamic-library-dirs: Files\ghcup\msys64\mingw64\lib is a
relative path which makes no sense (as there is nothing for it to be relative
to). You can make paths relative to the package database itself by using
${pkgroot}. (use --force to override)
)
Mikolaj commented 2 years ago

It seems at least some of the messages come from program ghc-pkg, but I couldn't find a ticket in the ghc bug tracker.

jneira commented 2 years ago

Thank you for the bug report Although the bug should be investigated, the immediate workaround is use a short, without spaces directory for installing ghcup (iirc the default in Windows is X:\ghcup, precisely to avoid these kind of issues)

Lev135 commented 2 years ago

Yes I've done so and all works for me now. Thank you

jasagredo commented 2 months ago

I seem to be able to reproduce with:

extra-lib-dirs: C:\Users\Javier\extra lib dirs

Which get passed to cabal as:

--extra-lib-dirs=C:\Users\Javier\extra --extra-lib-dirs=lib
--extra-lib-dirs=dirs

Does this also happen on Linux?

geekosaur commented 2 months ago

I believe you're supposed to use quotes? extra-lib-dirs: "C:\Users\Javier\extra lib dirs"

jasagredo commented 2 months ago

Nope, no double quotes nor single quotes make it work

ulysses4ever commented 2 months ago

It seems to work on Linux without quotes. I assume the parser starts with the first non-space and takes everything until the comma or next newline or something along these lines.

I didn't figure out how to check it most thoroughly, but what I did was:

  1. cabal init -nm
  2. add extra-lib-dirs: my sub dir in the library component in the cabal file.
  3. cabal build >out shows a warning:

    Warning: 'extra-lib-dirs: my sub dir' specifies a directory which does not exist.

  4. mkdir "my sub dir"
  5. cabal clean && cabal build >out is clean.

It is a little mind-boggling that this is platform-dependent, but maybe my imagination is too weak.