Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Cabal/src/Distribution/Simple/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2095,7 +2095,7 @@ getInstalledPackages verbosity comp mbWorkDir packageDBs progdb = do
-- do not check empty packagedbs (ghc-pkg would error out)
packageDBs' <- filterM packageDBExists packageDBs
case compilerFlavor comp of
GHC -> GHC.getInstalledPackages verbosity comp mbWorkDir packageDBs' progdb
GHC -> GHC.getInstalledPackages verbosity mbWorkDir packageDBs' progdb
GHCJS -> GHCJS.getInstalledPackages verbosity mbWorkDir packageDBs' progdb
UHC -> UHC.getInstalledPackages verbosity comp mbWorkDir packageDBs' progdb
flv ->
Expand Down
13 changes: 4 additions & 9 deletions Cabal/src/Distribution/Simple/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ data CabalException
| AmbiguousBuildTarget [(String, [(String, String)])]
| CheckBuildTargets String
| VersionMismatchGHC FilePath Version FilePath Version
| CheckPackageDbStackPost76
| CheckPackageDbStackPre76
| CheckPackageDbStack
| GlobalPackageDbSpecifiedFirst
| CantInstallForeignLib
| NoSupportForPreProcessingTest TestType
Expand Down Expand Up @@ -230,8 +229,8 @@ exceptionCode e = case e of
AmbiguousBuildTarget{} -> 7865
CheckBuildTargets{} -> 4733
VersionMismatchGHC{} -> 4000
CheckPackageDbStackPost76{} -> 3000
CheckPackageDbStackPre76{} -> 5640
CheckPackageDbStack{} -> 3000
-- Retired: CheckPackageDbStackPre76{} -> 5640
GlobalPackageDbSpecifiedFirst{} -> 2345
CantInstallForeignLib{} -> 8221
NoSupportForPreProcessingTest{} -> 3008
Expand Down Expand Up @@ -470,13 +469,9 @@ exceptionMessage e = case e of
++ ghcPkgProgPath
++ " is version "
++ prettyShow ghcPkgVersion
CheckPackageDbStackPost76 ->
CheckPackageDbStack ->
"If the global package db is specified, it must be "
++ "specified first and cannot be specified multiple times"
CheckPackageDbStackPre76 ->
"With current ghc versions the global package db is always used "
++ "and must be listed first. This ghc limitation is lifted in GHC 7.6,"
++ "see https://gitlab.haskell.org/ghc/ghc/-/issues/5977"
GlobalPackageDbSpecifiedFirst ->
"If the global package db is specified, it must be "
++ "specified first and cannot be specified multiple times"
Expand Down
34 changes: 8 additions & 26 deletions Cabal/src/Distribution/Simple/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -489,14 +489,13 @@ getPackageDBContents verbosity mbWorkDir packagedb progdb = do
-- | Given a package DB stack, return all installed packages.
getInstalledPackages
:: Verbosity
-> Compiler
-> Maybe (SymbolicPath CWD (Dir from))
-> PackageDBStackX (SymbolicPath from (Dir PkgDB))
-> ProgramDb
-> IO InstalledPackageIndex
getInstalledPackages verbosity comp mbWorkDir packagedbs progdb = do
getInstalledPackages verbosity mbWorkDir packagedbs progdb = do
checkPackageDbEnvVar verbosity
checkPackageDbStack verbosity comp packagedbs
checkPackageDbStack verbosity packagedbs
pkgss <- getInstalledPackages' verbosity mbWorkDir packagedbs progdb
index <- toPackageIndex verbosity pkgss progdb
return $! hackRtsPackage index
Expand Down Expand Up @@ -576,30 +575,13 @@ checkPackageDbEnvVar :: Verbosity -> IO ()
checkPackageDbEnvVar verbosity =
Internal.checkPackageDbEnvVar verbosity "GHC" "GHC_PACKAGE_PATH"

checkPackageDbStack :: Eq fp => Verbosity -> Compiler -> PackageDBStackX fp -> IO ()
checkPackageDbStack verbosity comp =
if flagPackageConf implInfo
then checkPackageDbStackPre76 verbosity
else checkPackageDbStackPost76 verbosity
where
implInfo = ghcVersionImplInfo (compilerVersion comp)

checkPackageDbStackPost76 :: Eq fp => Verbosity -> PackageDBStackX fp -> IO ()
checkPackageDbStackPost76 _ (GlobalPackageDB : rest)
checkPackageDbStack :: Eq fp => Verbosity -> PackageDBStackX fp -> IO ()
checkPackageDbStack _ (GlobalPackageDB : rest)
| GlobalPackageDB `notElem` rest = return ()
checkPackageDbStackPost76 verbosity rest
checkPackageDbStack verbosity rest
| GlobalPackageDB `elem` rest =
dieWithException verbosity CheckPackageDbStackPost76
checkPackageDbStackPost76 _ _ = return ()

checkPackageDbStackPre76 :: Eq fp => Verbosity -> PackageDBStackX fp -> IO ()
checkPackageDbStackPre76 _ (GlobalPackageDB : rest)
| GlobalPackageDB `notElem` rest = return ()
checkPackageDbStackPre76 verbosity rest
| GlobalPackageDB `notElem` rest =
dieWithException verbosity CheckPackageDbStackPre76
checkPackageDbStackPre76 verbosity _ =
dieWithException verbosity GlobalPackageDbSpecifiedFirst
dieWithException verbosity CheckPackageDbStack
checkPackageDbStack _ _ = return ()

-- GHC < 6.10 put "$topdir/include/mingw" in rts's installDirs. This
-- breaks when you want to use a different gcc, so we need to filter
Expand Down Expand Up @@ -710,7 +692,7 @@ startInterpreter verbosity progdb comp platform packageDBs = do
{ ghcOptMode = toFlag GhcModeInteractive
, ghcOptPackageDBs = packageDBs
}
checkPackageDbStack verbosity comp packageDBs
checkPackageDbStack verbosity packageDBs
(ghcProg, _) <- requireProgram verbosity ghcProgram progdb
-- This doesn't pass source file arguments to GHC, so we don't have to worry
-- about using a response file here.
Expand Down
17 changes: 0 additions & 17 deletions Cabal/src/Distribution/Simple/GHCJS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -750,23 +750,6 @@ buildOrReplLib mReplFlags verbosity numJobs _pkg_descr lbi lib clbi = do
let stubObjs = []
stubSharedObjs = []

{-
stubObjs <- catMaybes <$> sequenceA
[ findFileWithExtension [objExtension] [libTargetDir]
(ModuleName.toFilePath x ++"_stub")
| ghcVersion < mkVersion [7,2] -- ghc-7.2+ does not make _stub.o files
, x <- allLibModules lib clbi ]
stubProfObjs <- catMaybes <$> sequenceA
[ findFileWithExtension ["p_" ++ objExtension] [libTargetDir]
(ModuleName.toFilePath x ++"_stub")
| ghcVersion < mkVersion [7,2] -- ghc-7.2+ does not make _stub.o files
, x <- allLibModules lib clbi ]
stubSharedObjs <- catMaybes <$> sequenceA
[ findFileWithExtension ["dyn_" ++ objExtension] [libTargetDir]
(ModuleName.toFilePath x ++"_stub")
| ghcVersion < mkVersion [7,2] -- ghc-7.2+ does not make _stub.o files
, x <- allLibModules lib clbi ]
-}
hObjs <-
Internal.getHaskellObjects
implInfo
Expand Down
28 changes: 3 additions & 25 deletions Cabal/src/Distribution/Simple/Program/GHC.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
Expand Down Expand Up @@ -938,7 +939,7 @@ renderGhcOptions comp _platform@(Platform _arch os) opts
, ["-hide-all-packages" | flagBool ghcOptHideAllPackages]
, ["-Wmissing-home-modules" | flagBool ghcOptWarnMissingHomeModules]
, ["-no-auto-link-packages" | flagBool ghcOptNoAutoLinkPackages]
, packageDbArgs implInfo (interpretPackageDBStack Nothing (ghcOptPackageDBs opts))
, packageDbArgsDb (interpretPackageDBStack Nothing (ghcOptPackageDBs opts))
, concat $
let space "" = ""
space xs = ' ' : xs
Expand Down Expand Up @@ -999,27 +1000,9 @@ verbosityOpts verbosity
| verbosity >= Normal = []
| otherwise = ["-w", "-v0"]

-- | GHC <7.6 uses '-package-conf' instead of '-package-db'.
packageDbArgsConf :: PackageDBStackCWD -> [String]
packageDbArgsConf dbstack = case dbstack of
(GlobalPackageDB : UserPackageDB : dbs) -> concatMap specific dbs
(GlobalPackageDB : dbs) ->
("-no-user-package-conf")
: concatMap specific dbs
_ -> ierror
where
specific (SpecificPackageDB db) = ["-package-conf", db]
specific _ = ierror
ierror =
error $
"internal error: unexpected package db stack: "
++ show dbstack

-- | GHC >= 7.6 uses the '-package-db' flag. See
-- https://gitlab.haskell.org/ghc/ghc/-/issues/5977.
packageDbArgsDb :: PackageDBStackCWD -> [String]
-- special cases to make arguments prettier in common scenarios
packageDbArgsDb dbstack = case dbstack of
packageDbArgsDb = \case
(GlobalPackageDB : UserPackageDB : dbs)
| all isSpecific dbs -> concatMap single dbs
(GlobalPackageDB : dbs)
Expand All @@ -1036,11 +1019,6 @@ packageDbArgsDb dbstack = case dbstack of
isSpecific (SpecificPackageDB _) = True
isSpecific _ = False

packageDbArgs :: GhcImplInfo -> PackageDBStackCWD -> [String]
packageDbArgs implInfo
| flagPackageConf implInfo = packageDbArgsConf
| otherwise = packageDbArgsDb

-- | Split a list of command-line arguments into RTS arguments and non-RTS
-- arguments.
splitRTSArgs :: [String] -> ([String], [String])
Expand Down
25 changes: 9 additions & 16 deletions cabal-install/src/Distribution/Client/CmdRepl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ targetedRepl
-- into the multi-out directory.
replOpts'' <- case targetCtx of
ProjectContext -> return $ replOpts'{replOptionsFlagOutput = Flag dir}
_ -> usingGhciScript compiler projectRoot replOpts'
_ -> usingGhciScript projectRoot replOpts'

let buildCtx' = buildCtx & lElaboratedShared . lPkgConfigReplOptions .~ replOpts''
printPlan verbosity baseCtx'' buildCtx'
Expand Down Expand Up @@ -591,7 +591,7 @@ targetedRepl
-- single target repl
replOpts'' <- case targetCtx of
ProjectContext -> return replOpts'
_ -> usingGhciScript compiler projectRoot replOpts'
_ -> usingGhciScript projectRoot replOpts'

let buildCtx' = buildCtx & lElaboratedShared . lPkgConfigReplOptions .~ replOpts''
printPlan verbosity baseCtx'' buildCtx'
Expand Down Expand Up @@ -761,20 +761,13 @@ generateReplFlags includeTransitive elaboratedPlan OriginalComponentInfo{..} = f
-- so we need to tell ghci to change back to the correct directory.
--
-- The @-ghci-script@ flag is path to the ghci script responsible for changing to the
-- correct directory. Only works on GHC >= 7.6, though. 🙁
usingGhciScript :: Compiler -> FilePath -> ReplOptions -> IO ReplOptions
usingGhciScript compiler projectRoot replOpts
| compilerCompatVersion GHC compiler >= Just minGhciScriptVersion = do
let ghciScriptPath = projectRoot </> "setcwd.ghci"
cwd <- getCurrentDirectory
writeFile ghciScriptPath (":cd " ++ cwd)
return $ replOpts & lReplOptionsFlags %~ (("-ghci-script" ++ ghciScriptPath) :)
| otherwise = return replOpts

-- | First version of GHC where GHCi supported the flag we need.
-- https://downloads.haskell.org/~ghc/7.6.1/docs/html/users_guide/release-7-6-1.html
minGhciScriptVersion :: Version
minGhciScriptVersion = mkVersion [7, 6]
-- correct directory.
usingGhciScript :: FilePath -> ReplOptions -> IO ReplOptions
usingGhciScript projectRoot replOpts = do
let ghciScriptPath = projectRoot </> "setcwd.ghci"
cwd <- getCurrentDirectory
writeFile ghciScriptPath (":cd " ++ cwd)
return $ replOpts & lReplOptionsFlags %~ (("-ghci-script" ++ ghciScriptPath) :)

-- | This defines what a 'TargetSelector' means for the @repl@ command.
-- It selects the 'AvailableTarget's that the 'TargetSelector' refers to,
Expand Down
8 changes: 8 additions & 0 deletions changelog.d/11710.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
synopsis: "Remove legacy support for GHC < 7.6"
packages: [Cabal, cabal-install]
prs: 11710
---
Removed compatibility logic for GHC versions prior to 7.6. This simplifies
package database stack handling and unifies the flag generation logic in
`Distribution.Simple.GHC` and `Distribution.Simple.Program.GHC`.
Loading