Skip to content

Commit

Permalink
cabal-doctest: Fix ghc-pkg discovery logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sol committed Jul 16, 2024
1 parent 5a4a8ef commit 332fcf8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
6 changes: 2 additions & 4 deletions doctest.cabal

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ library:
filepath:
process:
ghc-paths: ">= 0.1.0.9"
Cabal:
transformers:

flags:
Expand Down
25 changes: 13 additions & 12 deletions src/Cabal/Paths.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE LambdaCase #-}
module Cabal.Paths (
Paths(..)
, paths
Expand All @@ -6,7 +8,6 @@ module Cabal.Paths (
import Imports

import Data.Char
import qualified Data.List as List
import Data.Tuple
import Data.Version hiding (parseVersion)
import qualified Data.Version as Version
Expand All @@ -17,12 +18,6 @@ import System.IO
import System.Process
import Text.ParserCombinators.ReadP

import qualified Distribution.Simple.GHC as GHC
import Distribution.Verbosity
import Distribution.Simple.Program.Db
import Distribution.Simple.Program.Types
import Distribution.Simple.Compiler

data Paths = Paths {
ghc :: FilePath
, ghcPkg :: FilePath
Expand Down Expand Up @@ -50,17 +45,23 @@ paths cabal = do

ghc <- getPath "'ghc'" "compiler-path"

(compiler, _, programs) <- GHC.configure silent (Just ghc) Nothing emptyProgramDb
ghcVersion <- strip <$> readProcess ghc ["--numeric-version"] ""

let
ghcPkg :: FilePath
ghcPkg = takeDirectory ghc </> "ghc-pkg-" <> ghcVersion
#ifdef mingw32_HOST_OS
<.> "exe"
#endif

ghcPkg <- case programPath <$> List.find (programId >>> (== "ghc-pkg")) (configuredPrograms programs) of
Nothing -> die $ "Cannot determine the path to 'ghc-pkg' from '" <> ghc <> "'."
Just path -> return path
doesFileExist ghcPkg >>= \ case
True -> pass
False -> die $ "Cannot determine the path to 'ghc-pkg' from '" <> ghc <> "'. File '" <> ghcPkg <> "' does not exist."

abi <- strip <$> readProcess ghcPkg ["--no-user-package-db", "field", "base", "abi", "--simple-output"] ""

cache_home <- getPath "Cabal's cache directory" "cache-home"
let cache = cache_home </> "doctest" </> showCompilerId compiler <> "-" <> abi
let cache = cache_home </> "doctest" </> "ghc-" <> ghcVersion <> "-" <> abi

createDirectoryIfMissing True cache

Expand Down

0 comments on commit 332fcf8

Please sign in to comment.