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
58 changes: 32 additions & 26 deletions Cabal/src/Distribution/Simple/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -282,25 +282,6 @@ compilerProgramDb
-- ^ user-specified @ghc-pkg@ path (optional)
-> IO ProgramDb
compilerProgramDb verbosity comp progdb1 hcPkgPath = do
let
ghcProg = fromJust $ lookupProgram ghcProgram progdb1
ghcVersion = compilerVersion comp

-- This is slightly tricky, we have to configure ghc first, then we use the
-- location of ghc to help find ghc-pkg in the case that the user did not
-- specify the location of ghc-pkg directly:
(ghcPkgProg, ghcPkgVersion, progdb2) <-
requireProgramVersion
verbosity
ghcPkgProgram
{ programFindLocation = guessGhcPkgFromGhcPath ghcProg
}
anyVersion
(userMaybeSpecifyPath "ghc-pkg" hcPkgPath progdb1)

when (ghcVersion /= ghcPkgVersion) $
dieWithException verbosity $
VersionMismatchGHC (programPath ghcProg) ghcVersion (programPath ghcPkgProg) ghcPkgVersion
-- Likewise we try to find the matching hsc2hs and haddock programs.
let hsc2hsProgram' =
hsc2hsProgram
Expand All @@ -318,20 +299,45 @@ compilerProgramDb verbosity comp progdb1 hcPkgPath = do
runghcProgram
{ programFindLocation = guessRunghcFromGhcPath ghcProg
}
progdb3 =
addKnownProgram haddockProgram' $
addKnownProgram hsc2hsProgram' $
addKnownProgram hpcProgram' $
addKnownProgram runghcProgram' progdb2
ghcPkgProgram' =
ghcPkgProgram
{ programFindLocation = guessGhcPkgFromGhcPath ghcProg
}
progdb2 =
userMaybeSpecifyPath "ghc-pkg" hcPkgPath $
addKnownProgram haddockProgram' $
addKnownProgram hsc2hsProgram' $
addKnownProgram hpcProgram' $
addKnownProgram runghcProgram' $
addKnownProgram ghcPkgProgram' $
progdb1

ghcProg = fromJust $ lookupProgram ghcProgram progdb1
ghcVersion = compilerVersion comp

-- configure gcc, ld, ar etc... based on the paths stored
-- in the GHC settings file
progdb4 =
progdb3 =
Internal.configureToolchain
(ghcVersionImplInfo ghcVersion)
ghcProg
(compilerProperties comp)
progdb3
progdb2

-- This is slightly tricky, we have to configure ghc first, then we use the
-- location of ghc to help find ghc-pkg in the case that the user did not
-- specify the location of ghc-pkg directly:
(ghcPkgProg, ghcPkgVersion, progdb4) <-
requireProgramVersion
verbosity
ghcPkgProgram'
anyVersion
progdb3

when (ghcVersion /= ghcPkgVersion) $
dieWithException verbosity $
VersionMismatchGHC (programPath ghcProg) ghcVersion (programPath ghcPkgProg) ghcPkgVersion

return progdb4

-- | Given something like /usr/local/bin/ghc-6.6.1(.exe) we try and find
Expand Down
4 changes: 4 additions & 0 deletions cabal-testsuite/PackageTests/WithGhcPkg/app/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Main (main) where

main :: IO ()
main = putStrLn "with-ghc-pkg test"
13 changes: 13 additions & 0 deletions cabal-testsuite/PackageTests/WithGhcPkg/cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# cabal v2-build
Warning: cannot determine version of <ROOT>/fake-ghc-pkg-bin/ghc-pkg :
""
Error: [Cabal-1008]
The program 'ghc-pkg' is required but the version of <ROOT>/fake-ghc-pkg-bin/ghc-pkg could not be determined.
# cabal v2-build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- with-ghc-pkg-0.1.0.0 (exe:with-ghc-pkg) (first run)
Configuring executable 'with-ghc-pkg' for with-ghc-pkg-0.1.0.0...
Preprocessing executable 'with-ghc-pkg' for with-ghc-pkg-0.1.0.0...
Building executable 'with-ghc-pkg' for with-ghc-pkg-0.1.0.0...
31 changes: 31 additions & 0 deletions cabal-testsuite/PackageTests/WithGhcPkg/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Test.Cabal.Prelude
import System.FilePath ((</>))
import System.Directory (createDirectoryIfMissing, getPermissions, setPermissions, Permissions(..))

main :: IO ()
main = do
skipIfWindows "relies on a POSIX shell script"
cabalTest $ do
env <- getTestEnv
let fakeDir = testTmpDir env </> "fake-ghc-pkg-bin"
liftIO $ createDirectoryIfMissing True fakeDir
let fakeGhcPkg = fakeDir </> "ghc-pkg"
fakeGhc = fakeDir </> "ghc"
realGhcPkg <- programPathM ghcPkgProgram
realGhc <- programPathM ghcProgram

liftIO $ do
writeFile fakeGhcPkg "#!/bin/sh\n\necho \"fake ghc-pkg\" >&2\nexit 1\n"
perms <- getPermissions fakeGhcPkg
setPermissions fakeGhcPkg perms { executable = True }
writeFile fakeGhc $ "#!/bin/sh\nexec \"" ++ realGhc ++ "\" \"$@\"\n"
ghcPerms <- getPermissions fakeGhc
setPermissions fakeGhc ghcPerms { executable = True }

-- Passing -w makes GHC look for ghc-pkg in the fake directory alongside the ghc wrapper.
-- The wrapper fails.
fails $ cabal "v2-build" ["-w", fakeGhc, "all"]

-- Adding --with-hc-pkg must override that lookup and use the real
-- tool even though the configured compiler still lives in fakeDir.
cabal "v2-build" ["-w", fakeGhc, "--with-hc-pkg", realGhcPkg, "all"]
10 changes: 10 additions & 0 deletions cabal-testsuite/PackageTests/WithGhcPkg/with-ghc-pkg.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cabal-version: 3.0
name: with-ghc-pkg
version: 0.1.0.0
build-type: Simple

executable with-ghc-pkg
main-is: Main.hs
hs-source-dirs: app
build-depends: base >=4.14 && <5
default-language: Haskell2010
9 changes: 9 additions & 0 deletions changelog.d/with-ghc-pkg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
synopsis: Honour `--with-ghc-pkg` when supplied by the user
packages: [cabal-install]
prs: [11450]
issues: [11373]
---

`cabal-install` now properly honours when a user supplies `--with-ghc-pkg`.

Loading