Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Cabal/src/Distribution/Simple/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import Distribution.System (OS)
import Distribution.Types.MissingDependency (MissingDependency)
import Distribution.Types.VersionRange.Internal ()
import Distribution.Version
import System.FilePath (searchPathSeparator)
import Text.PrettyPrint

data FailedDependency
Expand Down Expand Up @@ -170,6 +171,7 @@ data CabalException
| SetupHooksException SetupHooksException
| MultiReplDoesNotSupportComplexReexportedModules PackageName ComponentName
| StandaloneBytecodeNotSupportedYet
| SearchPathSeparatorInSourceDir FilePath
deriving (Show)

data WhatToFind
Expand Down Expand Up @@ -320,6 +322,7 @@ exceptionCode e = case e of
setupHooksExceptionCode err
MultiReplDoesNotSupportComplexReexportedModules{} -> 9355
StandaloneBytecodeNotSupportedYet -> 9356
SearchPathSeparatorInSourceDir{} -> 9357

versionRequirement :: VersionRange -> String
versionRequirement range
Expand Down Expand Up @@ -810,3 +813,13 @@ exceptionMessage e = case e of
[ "The ecosystem doesn't support building packages with just bytecode libraries yet."
, "If you have run into this error, please comment on issue #<TODO>"
]
SearchPathSeparatorInSourceDir dir ->
"The directory "
++ dir
++ " contains '"
++ [searchPathSeparator]
++ "', 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 '"
++ [searchPathSeparator]
++ "'."
12 changes: 11 additions & 1 deletion Cabal/src/Distribution/Simple/Program/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ import Distribution.ModuleName
import Distribution.PackageDescription
import Distribution.Pretty
import Distribution.Simple.Compiler
import Distribution.Simple.Errors
import Distribution.Simple.Flag
import Distribution.Simple.GHC.ImplInfo
import Distribution.Simple.Program.Find (getExtraPathEnv)
import Distribution.Simple.Program.ResponseFile
import Distribution.Simple.Program.Run
import Distribution.Simple.Program.Types
import Distribution.Simple.Utils (TempFileOptions, infoNoWrap)
import Distribution.Simple.Utils (TempFileOptions, dieWithException, infoNoWrap)
import Distribution.System
import Distribution.Types.ComponentId
import Distribution.Types.ParStrat
Expand All @@ -58,6 +59,7 @@ import Data.Monoid (All (..), Any (..), Endo (..))
import qualified Data.Set as Set
import Data.Text (Text)
import qualified Data.Text as Text
import System.FilePath (searchPathSeparator)
import qualified System.Process as Process

normaliseGhcArgs :: Maybe Version -> PackageDescription -> [String] -> [String]
Expand Down Expand Up @@ -757,6 +759,14 @@ ghcInvocation
-> GhcOptions
-> IO ProgramInvocation
ghcInvocation verbosity ghcProg comp platform mbWorkDir opts = do
-- GHC splits every @-i@ flag on the search path separator, and there is no
-- way to escape it. So a source directory that contains the separator, like
-- the ones in a build directory given as @--builddir=foo:bar@, would be
-- split in two, and GHC would not find the modules in it (#12620).
for_ (fromNubListR (ghcOptSourcePath opts)) $ \dir ->
when (searchPathSeparator `elem` getSymbolicPath dir) $
dieWithException verbosity $
SearchPathSeparatorInSourceDir (getSymbolicPath dir)
-- NOTE: GHC is the only program whose path we modify with more values than
-- the standard @extra-prog-path@, namely the folders of the executables in
-- the components, see @componentGhcOptions@.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import System.FilePath (searchPathSeparator)
import Test.Cabal.Prelude

-- GHC splits its source directories on the search path separator, so it
-- cannot find the modules in a build directory whose path contains one, such as
-- Paths_pkg. Cabal reports that instead of leaving GHC to fail (#12620).
main = cabalTest $ recordMode DoNotRecord $ do
r <- fails $ cabal' "v2-build" ["--builddir=dist" ++ [searchPathSeparator] ++ "sep"]
assertOutputContains "Cabal-9357" r
11 changes: 11 additions & 0 deletions cabal-testsuite/PackageTests/BuildDirSearchPathSeparator/pkg.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cabal-version: 2.4
name: pkg
version: 0.1.0.0

library
exposed-modules: Lib
other-modules: Paths_pkg
autogen-modules: Paths_pkg
hs-source-dirs: src
build-depends: base
default-language: Haskell2010
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Lib (v) where

import Data.Version (Version)
import Paths_pkg (version)

v :: Version
v = version
12 changes: 12 additions & 0 deletions changelog.d/12620.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
synopsis: Report a source directory that contains the search path separator
packages: [Cabal]
issues: 12620
prs: 12697
---

GHC splits every source directory given with `-i` on the search path separator
(`:` on Unix and `;` on Windows), 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 there, such as `Paths_pkg`, and only said that they could not be
found. Cabal now stops with an error that names the directory and explains why.
Loading