haskell / haskell/cabal

pkg-config output parser doesn't implement shell quoting rules

Open
#5,519 16 comments 0 reactions 0 assignees View on GitHub
type: bug
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

Title is my main suspicion of the cause of the issue:

So, I've been trying to build the SDL2 package in Windows 10 and made [an issue](https://github.com/haskell-game/sdl2/issues/161) about the problem I've been having around a year ago or so. If you don't want to read it, it basically cannot find my pacman-installed SDL2 for some reason, even though the directories that include its lib and include files are there in the extra-lib-dirs and extra-include-dirs arguments respectively. Because my home directory has a space character in it, basically every single directory's absolute path is also going to have it, so I have no easy way to test the removal or addition of spaces. So, for example, like how we can see in the linked issue, the `configure` command is being passed `--extra-lib-dirs=C:\\Users\\Vitor Coimbra\\AppData\\Local\\Programs\\stack\\x86_64-windows\\msys2-20150512\\mingw64\\lib`, which is the directory that contains, among other things, my `libSDL2.a` file.

What I'm certain of is that it has something to do with the `pkgconfig-depends` field, because [another project](https://github.com/mrkkrp/htaglib) that uses foreign dependencies (namely, `taglib`) and does not use that particular field (instead, opting to use an `extra-libraries` one) builds correctly in my machine. If I change its Cabal file to use a `pkgconfig-depends: taglib` field instead, it stops building with the same kind of error seen in the SDL2's issue (but for `taglib`, obviously). To be more specific, I'm using the stack-installed MSYS2 program to manage system packages like `pkg-config`, `sdl2` and `taglib` with `pacman`.

Poking around Cabal's code, my first intuition was to find the place where the error message was being generated. There, one of the problems I thought might be happening are in these two places:

https://github.com/haskell/cabal/blob/fc9a60795bb5a655cc72dc1f493a29db7b05019f/Cabal/Distribution/Simple/Configure.hs#L1744-L1750

https://github.com/haskell/cabal/blob/fc9a60795bb5a655cc72dc1f493a29db7b05019f/Cabal/Distribution/Simple/Configure.hs#L1727-L1733

See, because of the way they create the -I and -L values, it seems to me they're not properly treating directories with characters such as space correctly. This might not be actually be the problem, though, because of the way processes are created, using a list of arguments instead of concatenating it all into one huge string, so this might not be a good lead. Plus, the fact that it works for htaglib shows that it's probably not here.

Contributor guide

Open the contributing guide

Research direction

Start in Cabal/Distribution/Simple/Configure.hs around the linked lines that construct -I and -L values, then trace the pkg-config output parser and its handling of shell quoting. Reproduce the Windows SDL2 or taglib case with paths containing spaces; done means quoted paths are parsed correctly and pkg-config-dependent builds no longer fail for that case.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.