Skip to content

Report a source directory that contains the search path separator - #12697

Open
swinilohani616-dot wants to merge 2 commits into
haskell:masterfrom
swinilohani616-dot:builddir-search-path-separator
Open

swinilohani616-dot wants to merge 2 commits into
haskell:masterfrom
swinilohani616-dot:builddir-search-path-separator

Conversation

@swinilohani616-dot

Copy link
Copy Markdown
Contributor

Fixes #12620.

If your build directory has a colon in it, like --builddir=foo:bar, the build fails with a confusing error:

module ‘Paths_pkg’ cannot be found locally

The cause is that GHC splits every -i flag on the search path separator (: on Unix, ; on Windows), so -ifoo:bar/build/.../autogen becomes two directories, and the modules Cabal generates there can't be found. Unfortunately Cabal can't work around this: GHC has no way to escape the separator, even in an absolute path, and passing the directories as separate -i flags doesn't help, because each one gets split the same way.

So rather than letting GHC fail with that message, Cabal now stops before running GHC and tells you which directory is the problem:

Error: [Cabal-9357]
The directory foo:bar/build/aarch64-osx/ghc-9.10.3/pkg-0.1.0.0/build contains ':', which GHC takes as a
separator between source directories, so it cannot find the modules in it. If this directory is in the
build directory, choose a build directory whose path has no ':'.

I put the check in ghcInvocation, since every GHC call goes through it, and it looks at ghcOptSourcePath. That way it catches the problem wherever the directory comes from: the build directory, hs-source-dirs, or a project path. It uses searchPathSeparator, so on Windows it checks for ; instead, and colons in drive letters aren't affected.

I added a cabal-testsuite test, BuildDirSearchPathSeparator: a small package that uses Paths_pkg, built with a build directory containing the separator. It passes with this change and fails without it.

GHC splits every -i flag on the search path separator, and there is no
way to escape it. So with a build directory like --builddir=foo:bar,
GHC could not find the modules that Cabal generates in it, such as
Paths_pkg. Stop before running GHC with an error that names the
directory instead.

Fixes haskell#12620.

@ffaf1 ffaf1 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@mergify mergify Bot added the 1️⃣ more approval needed Set by Mergify: has one of the two required approvals label Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1️⃣ more approval needed Set by Mergify: has one of the two required approvals

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cabal puts builddir on the PATH without escaping colons

2 participants