diff --git a/Cabal-syntax/Cabal-syntax.cabal b/Cabal-syntax/Cabal-syntax.cabal index bb5a13ffc75..6f87ba7e7b3 100644 --- a/Cabal-syntax/Cabal-syntax.cabal +++ b/Cabal-syntax/Cabal-syntax.cabal @@ -52,9 +52,8 @@ library -Wincomplete-uni-patterns -Wincomplete-record-updates -Wno-unticked-promoted-constructors - - if impl(ghc >= 8.0) - ghc-options: -Wcompat -Wnoncanonical-monad-instances + -Wcompat + -Wnoncanonical-monad-instances if impl(ghc >= 8.0) && impl(ghc < 8.8) ghc-options: -Wnoncanonical-monadfail-instances diff --git a/Cabal/src/Distribution/Simple/Build.hs b/Cabal/src/Distribution/Simple/Build.hs index 3e32d2ccfe5..17ffd35618b 100644 --- a/Cabal/src/Distribution/Simple/Build.hs +++ b/Cabal/src/Distribution/Simple/Build.hs @@ -920,7 +920,7 @@ createInternalPackageDB createInternalPackageDB verbosity lbi distPref = do existsAlready <- doesPackageDBExist dbPath when existsAlready $ deletePackageDB dbPath - createPackageDB verbosity (compiler lbi) (withPrograms lbi) False dbPath + createPackageDB verbosity (compiler lbi) (withPrograms lbi) dbPath return (SpecificPackageDB dbRelPath) where dbRelPath = internalPackageDBPath lbi distPref @@ -1188,7 +1188,7 @@ builtinAutogenFiles pkg lbi clbi = pathsFile = AutogenModule (autogenPathsModuleName pkg) (Suffix "hs") pathsContents = toUTF8LBS $ generatePathsModule pkg lbi clbi packageInfoFile = AutogenModule (autogenPackageInfoModuleName pkg) (Suffix "hs") - packageInfoContents = toUTF8LBS $ generatePackageInfoModule pkg lbi + packageInfoContents = toUTF8LBS $ generatePackageInfoModule pkg cppHeaderFile = AutogenFile $ toShortText cppHeaderName cppHeaderContents = toUTF8LBS $ generateCabalMacrosHeader pkg lbi clbi diff --git a/Cabal/src/Distribution/Simple/Build/PackageInfoModule.hs b/Cabal/src/Distribution/Simple/Build/PackageInfoModule.hs index be5aa378796..ea576ce3227 100644 --- a/Cabal/src/Distribution/Simple/Build/PackageInfoModule.hs +++ b/Cabal/src/Distribution/Simple/Build/PackageInfoModule.hs @@ -19,11 +19,14 @@ import Distribution.Compat.Prelude import Prelude () import Distribution.Package -import Distribution.PackageDescription -import Distribution.Simple.Compiler -import Distribution.Simple.LocalBuildInfo -import Distribution.Utils.ShortText -import Distribution.Version + ( PackageName + , packageName + , packageVersion + , unPackageName + ) +import Distribution.Types.PackageDescription (PackageDescription (..)) +import Distribution.Types.Version (versionNumbers) +import Distribution.Utils.ShortText (fromShortText) import qualified Distribution.Simple.Build.PackageInfoModule.Z as Z @@ -33,8 +36,8 @@ import qualified Distribution.Simple.Build.PackageInfoModule.Z as Z -- ------------------------------------------------------------ -generatePackageInfoModule :: PackageDescription -> LocalBuildInfo -> String -generatePackageInfoModule pkg_descr lbi = +generatePackageInfoModule :: PackageDescription -> String +generatePackageInfoModule pkg_descr = Z.render Z.Z { Z.zPackageName = showPkgName $ packageName pkg_descr @@ -42,15 +45,7 @@ generatePackageInfoModule pkg_descr lbi = , Z.zSynopsis = fromShortText $ synopsis pkg_descr , Z.zCopyright = fromShortText $ copyright pkg_descr , Z.zHomepage = fromShortText $ homepage pkg_descr - , Z.zSupportsNoRebindableSyntax = supports_rebindable_syntax } - where - supports_rebindable_syntax = ghc_newer_than (mkVersion [7, 0, 1]) - - ghc_newer_than minVersion = - case compilerCompatVersion GHC (compiler lbi) of - Nothing -> False - Just version -> version `withinRange` orLaterVersion minVersion showPkgName :: PackageName -> String showPkgName = map fixchar . unPackageName diff --git a/Cabal/src/Distribution/Simple/Build/PackageInfoModule/Z.hs b/Cabal/src/Distribution/Simple/Build/PackageInfoModule/Z.hs index 6fdbfb176b7..015c3ea3058 100644 --- a/Cabal/src/Distribution/Simple/Build/PackageInfoModule/Z.hs +++ b/Cabal/src/Distribution/Simple/Build/PackageInfoModule/Z.hs @@ -2,7 +2,7 @@ module Distribution.Simple.Build.PackageInfoModule.Z (render, Z (..)) where -import Distribution.ZinzaPrelude +import Distribution.ZinzaPrelude (Generic, execWriter, tell) data Z = Z { zPackageName :: String @@ -10,18 +10,12 @@ data Z = Z , zSynopsis :: String , zCopyright :: String , zHomepage :: String - , zSupportsNoRebindableSyntax :: Bool } deriving (Generic) render :: Z -> String render z_root = execWriter $ do - if (zSupportsNoRebindableSyntax z_root) - then do - tell "{-# LANGUAGE NoRebindableSyntax #-}\n" - return () - else do - return () + tell "{-# LANGUAGE NoRebindableSyntax #-}\n" tell "{-# OPTIONS_GHC -w #-}\n" tell "\n" tell "{-|\n" diff --git a/Cabal/src/Distribution/Simple/Build/PathsModule.hs b/Cabal/src/Distribution/Simple/Build/PathsModule.hs index 9392acf3cef..525c19598b8 100644 --- a/Cabal/src/Distribution/Simple/Build/PathsModule.hs +++ b/Cabal/src/Distribution/Simple/Build/PathsModule.hs @@ -44,8 +44,6 @@ generatePathsModule pkg_descr lbi clbi = Z.Z { Z.zPackageName = packageName pkg_descr , Z.zVersionDigits = show $ versionNumbers $ packageVersion pkg_descr - , Z.zSupportsCpp = supports_cpp - , Z.zSupportsNoRebindableSyntax = supports_rebindable_syntax , Z.zAbsolute = absolute , Z.zRelocatable = relocatable lbi , Z.zIsWindows = isWindows @@ -63,15 +61,6 @@ generatePathsModule pkg_descr lbi clbi = , Z.zSysconfdir = zSysconfdir } where - supports_cpp = supports_language_pragma - supports_rebindable_syntax = ghc_newer_than (mkVersion [7, 0, 1]) - supports_language_pragma = ghc_newer_than (mkVersion [6, 6, 1]) - - ghc_newer_than minVersion = - case compilerCompatVersion GHC (compiler lbi) of - Nothing -> False - Just version -> version `withinRange` orLaterVersion minVersion - -- In several cases we cannot make relocatable installations absolute = hasLibs pkg_descr -- we can only make progs relocatable diff --git a/Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs b/Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs index d401ce305c4..e324c8ea11c 100644 --- a/Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs +++ b/Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs @@ -5,8 +5,6 @@ import Distribution.ZinzaPrelude data Z = Z {zPackageName :: PackageName, zVersionDigits :: String, - zSupportsCpp :: Bool, - zSupportsNoRebindableSyntax :: Bool, zAbsolute :: Bool, zRelocatable :: Bool, zIsWindows :: Bool, @@ -25,18 +23,8 @@ data Z deriving Generic render :: Z -> String render z_root = execWriter $ do - if (zSupportsCpp z_root) - then do - tell "{-# LANGUAGE CPP #-}\n" - return () - else do - return () - if (zSupportsNoRebindableSyntax z_root) - then do - tell "{-# LANGUAGE NoRebindableSyntax #-}\n" - return () - else do - return () + tell "{-# LANGUAGE CPP #-}\n" + tell "{-# LANGUAGE NoRebindableSyntax #-}\n" if (zNot z_root (zAbsolute z_root)) then do tell "{-# LANGUAGE ForeignFunctionInterface #-}\n" @@ -91,25 +79,8 @@ render z_root = execWriter $ do else do return () tell "\n" - if (zSupportsCpp z_root) - then do - tell "#if defined(VERSION_base)\n" - tell "\n" - tell "#if MIN_VERSION_base(4,0,0)\n" - tell "catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a\n" - tell "#else\n" - tell "catchIO :: IO a -> (Exception.Exception -> IO a) -> IO a\n" - tell "#endif\n" - tell "\n" - tell "#else\n" - tell "catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a\n" - tell "#endif\n" - tell "catchIO = Exception.catch\n" - return () - else do - tell "catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a\n" - tell "catchIO = Exception.catch\n" - return () + tell "catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a\n" + tell "catchIO = Exception.catch\n" tell "\n" tell "-- |The package version.\n" tell "version :: Version\n" diff --git a/Cabal/src/Distribution/Simple/Compiler.hs b/Cabal/src/Distribution/Simple/Compiler.hs index 38478a71b4c..4f66f90eea8 100644 --- a/Cabal/src/Distribution/Simple/Compiler.hs +++ b/Cabal/src/Distribution/Simple/Compiler.hs @@ -492,15 +492,8 @@ reexportedAsSupported comp = case compilerFlavor comp of -- "dynamic-library-dirs"? libraryDynDirSupported :: Compiler -> Bool libraryDynDirSupported comp = case compilerFlavor comp of - GHC -> - -- Not just v >= mkVersion [8,0,1,20161022], as there - -- are many GHC 8.1 nightlies which don't support this. - ( (v >= mkVersion [8, 0, 1, 20161022] && v < mkVersion [8, 1]) - || v >= mkVersion [8, 1, 20161021] - ) + GHC -> True _ -> False - where - v = compilerVersion comp -- | Does this compiler's "ar" command supports response file -- arguments (i.e. @file-style arguments). diff --git a/Cabal/src/Distribution/Simple/Configure.hs b/Cabal/src/Distribution/Simple/Configure.hs index 5d8ab963c7c..9826f722acb 100644 --- a/Cabal/src/Distribution/Simple/Configure.hs +++ b/Cabal/src/Distribution/Simple/Configure.hs @@ -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 -> @@ -2922,12 +2922,7 @@ checkForeignLibSupported :: Compiler -> Platform -> ForeignLib -> Maybe String checkForeignLibSupported comp platform flib = go (compilerFlavor comp) where go :: CompilerFlavor -> Maybe String - go GHC - | compilerVersion comp < mkVersion [7, 8] = - unsupported - [ "Building foreign libraries is only supported with GHC >= 7.8" - ] - | otherwise = goGhcPlatform platform + go GHC = goGhcPlatform platform go _ = unsupported [ "Building foreign libraries is currently only supported with ghc" diff --git a/Cabal/src/Distribution/Simple/Errors.hs b/Cabal/src/Distribution/Simple/Errors.hs index f2f57fd907b..bf329b13ced 100644 --- a/Cabal/src/Distribution/Simple/Errors.hs +++ b/Cabal/src/Distribution/Simple/Errors.hs @@ -96,8 +96,7 @@ data CabalException | AmbiguousBuildTarget [(String, [(String, String)])] | CheckBuildTargets String | VersionMismatchGHC FilePath Version FilePath Version - | CheckPackageDbStackPost76 - | CheckPackageDbStackPre76 + | CheckPackageDbStack | GlobalPackageDbSpecifiedFirst | CantInstallForeignLib | NoSupportForPreProcessingTest TestType @@ -230,8 +229,7 @@ exceptionCode e = case e of AmbiguousBuildTarget{} -> 7865 CheckBuildTargets{} -> 4733 VersionMismatchGHC{} -> 4000 - CheckPackageDbStackPost76{} -> 3000 - CheckPackageDbStackPre76{} -> 5640 + CheckPackageDbStack{} -> 3000 GlobalPackageDbSpecifiedFirst{} -> 2345 CantInstallForeignLib{} -> 8221 NoSupportForPreProcessingTest{} -> 3008 @@ -470,13 +468,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" diff --git a/Cabal/src/Distribution/Simple/GHC.hs b/Cabal/src/Distribution/Simple/GHC.hs index c1eece45c3f..1e25eb00bf2 100644 --- a/Cabal/src/Distribution/Simple/GHC.hs +++ b/Cabal/src/Distribution/Simple/GHC.hs @@ -200,8 +200,8 @@ configureCompiler verbosity hcPath conf0 = do ++ prettyShow ghcVersion let implInfo = ghcVersionImplInfo ghcVersion - languages <- Internal.getLanguages verbosity implInfo ghcProg - extensions0 <- Internal.getExtensions verbosity implInfo ghcProg + languages <- Internal.getLanguages implInfo + extensions0 <- Internal.getExtensions verbosity ghcProg ghcInfo <- Internal.getGhcInfo verbosity implInfo ghcProg @@ -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 @@ -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 @@ -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. @@ -1134,23 +1116,9 @@ installLib verbosity lbi targetDir dynlibTargetDir bytecodeTargetDir _builtDir p -- ----------------------------------------------------------------------------- -- Registering -hcPkgInfo :: ProgramDb -> HcPkg.HcPkgInfo +hcPkgInfo :: ProgramDb -> HcPkg.ConfiguredProgram hcPkgInfo progdb = - HcPkg.HcPkgInfo - { HcPkg.hcPkgProgram = ghcPkgProg - , HcPkg.noPkgDbStack = v < [6, 9] - , HcPkg.noVerboseFlag = v < [6, 11] - , HcPkg.flagPackageConf = v < [7, 5] - , HcPkg.supportsDirDbs = v >= [6, 8] - , HcPkg.requiresDirDbs = v >= [7, 10] - , HcPkg.nativeMultiInstance = v >= [7, 10] - , HcPkg.recacheMultiInstance = v >= [6, 12] - , HcPkg.suppressFilesCheck = v >= [6, 6] - } - where - v = versionNumbers ver - ghcPkgProg = fromMaybe (error "GHC.hcPkgInfo: no ghc program") $ lookupProgram ghcPkgProgram progdb - ver = fromMaybe (error "GHC.hcPkgInfo: no ghc version") $ programVersion ghcPkgProg + fromMaybe (error "GHC.hcPkgInfo: no ghc program") $ lookupProgram ghcPkgProgram progdb registerPackage :: Verbosity diff --git a/Cabal/src/Distribution/Simple/GHC/Build/Link.hs b/Cabal/src/Distribution/Simple/GHC/Build/Link.hs index d2a967dae45..c6683f6fe4f 100644 --- a/Cabal/src/Distribution/Simple/GHC/Build/Link.hs +++ b/Cabal/src/Distribution/Simple/GHC/Build/Link.hs @@ -17,7 +17,6 @@ import Distribution.Compat.ResponseFile import Distribution.InstalledPackageInfo (InstalledPackageInfo) import qualified Distribution.InstalledPackageInfo as IPI import qualified Distribution.InstalledPackageInfo as InstalledPackageInfo -import qualified Distribution.ModuleName as ModuleName import Distribution.Package import Distribution.PackageDescription as PD import Distribution.PackageDescription.Utils (cabalBug) @@ -32,7 +31,6 @@ import Distribution.Simple.GHC.ImplInfo import qualified Distribution.Simple.GHC.Internal as Internal import Distribution.Simple.LocalBuildInfo import qualified Distribution.Simple.PackageIndex as PackageIndex -import Distribution.Simple.PreProcess.Types import Distribution.Simple.Program import qualified Distribution.Simple.Program.Ar as Ar import Distribution.Simple.Program.GHC @@ -228,7 +226,7 @@ linkOrLoadComponent CLib lib -> do let libWays = wantedLibWays isIndef rpaths <- get_rpaths (Set.fromList libWays) - linkLibrary buildTargetDir cleanedExtraLibDirs pkg_descr verbosity runGhcProg lib lbi clbi extraSources rpaths libWays + linkLibrary buildTargetDir cleanedExtraLibDirs verbosity runGhcProg lib lbi clbi extraSources rpaths libWays CFLib flib -> do let flib_way = wantedFLibWay (withDynFLib flib) rpaths <- get_rpaths (Set.singleton flib_way) @@ -243,8 +241,6 @@ linkLibrary -- ^ The library target build directory -> [SymbolicPath Pkg (Dir Lib)] -- ^ The list of extra lib dirs that exist (aka "cleaned") - -> PackageDescription - -- ^ The package description containing this library -> Verbosity -> (GhcOptions -> IO ()) -- ^ Run the configured Ghc program @@ -258,18 +254,13 @@ linkLibrary -> [BuildWay] -- ^ Wanted build ways and corresponding build options -> IO () -linkLibrary buildTargetDir cleanedExtraLibDirs pkg_descr verbosity runGhcProg lib lbi clbi extraSources rpaths wantedWays = do +linkLibrary buildTargetDir cleanedExtraLibDirs verbosity runGhcProg lib lbi clbi extraSources rpaths wantedWays = do let - common = configCommonFlags $ configFlags lbi - mbWorkDir = flagToMaybe $ setupWorkingDir common - compiler_id = compilerId comp comp = compiler lbi - ghcVersion = compilerVersion comp implInfo = getImplInfo comp uid = componentUnitId clbi libBi = libBuildInfo lib - Platform _hostArch hostOS = hostPlatform lbi vanillaLibFilePath = buildTargetDir makeRelativePathEx (mkLibName uid) profileLibFilePath = buildTargetDir makeRelativePathEx (mkProfLibName uid) sharedLibFilePath = @@ -286,19 +277,6 @@ linkLibrary buildTargetDir cleanedExtraLibDirs pkg_descr verbosity runGhcProg li makeRelativePathEx (mkBytecodeLibName compiler_id uid) ghciLibFilePath = buildTargetDir makeRelativePathEx (Internal.mkGHCiLibName uid) ghciProfLibFilePath = buildTargetDir makeRelativePathEx (Internal.mkGHCiProfLibName uid) - libInstallPath = - libdir $ - absoluteComponentInstallDirs - pkg_descr - lbi - uid - NoCopyDest - sharedLibInstallPath = - libInstallPath - mkSharedLibName (hostPlatform lbi) compiler_id uid - profSharedLibInstallPath = - libInstallPath - mkProfSharedLibName (hostPlatform lbi) compiler_id uid getObjWayFiles :: BuildWay -> IO [SymbolicPath Pkg File] getObjWayFiles w = getObjFiles (buildWayObjectExtension objExtension w) (buildWayObjectExtension objExtension w) @@ -318,18 +296,6 @@ linkLibrary buildTargetDir cleanedExtraLibDirs pkg_descr verbosity runGhcProg li hs_ext True , pure $ map (srcObjPath obj_ext) extraSources - , catMaybes - <$> sequenceA - [ findFileCwdWithExtension - mbWorkDir - [Suffix obj_ext] - [buildTargetDir] - xPath - | ghcVersion < mkVersion [7, 2] -- ghc-7.2+ does not make _stub.o files - , x <- allLibModules lib clbi - , let xPath :: RelativePath Artifacts File - xPath = makeRelativePathEx $ ModuleName.toFilePath x ++ "_stub" - ] ] -- Get the @.o@ path from a source path (e.g. @.hs@), @@ -397,14 +363,7 @@ linkLibrary buildTargetDir cleanedExtraLibDirs pkg_descr verbosity runGhcProg li , ghcOptDynLinkMode = toFlag GhcDynamicOnly , ghcOptInputFiles = toNubListR $ map coerceSymbolicPath dynObjectFiles , ghcOptOutputFile = toFlag sharedLibFilePath - , -- For dynamic libs, Mac OS/X needs to know the install location - -- at build time. This only applies to GHC < 7.8 - see the - -- discussion in #1660. - ghcOptDylibName = - if hostOS == OSX - && ghcVersion < mkVersion [7, 8] - then toFlag sharedLibInstallPath - else mempty + , ghcOptDylibName = mempty , ghcOptLinkLibs = extraLibs libBi , ghcOptLinkLibPath = toNubListR cleanedExtraLibDirs , ghcOptLinkFrameworks = toNubListR $ map getSymbolicPath $ PD.frameworks libBi @@ -423,14 +382,7 @@ linkLibrary buildTargetDir cleanedExtraLibDirs pkg_descr verbosity runGhcProg li , ghcOptDynLinkMode = toFlag GhcDynamicOnly , ghcOptInputFiles = toNubListR pdynObjectFiles , ghcOptOutputFile = toFlag profSharedLibFilePath - , -- For dynamic libs, Mac OS/X needs to know the install location - -- at build time. This only applies to GHC < 7.8 - see the - -- discussion in #1660. - ghcOptDylibName = - if hostOS == OSX - && ghcVersion < mkVersion [7, 8] - then toFlag profSharedLibInstallPath - else mempty + , ghcOptDylibName = mempty , ghcOptLinkLibs = extraLibs libBi , ghcOptLinkLibPath = toNubListR cleanedExtraLibDirs , ghcOptLinkFrameworks = toNubListR $ map getSymbolicPath $ PD.frameworks libBi @@ -543,14 +495,11 @@ linkExecutable linkerOpts (way, buildOpts) targetDir targetName runGhcProg lbi = -- assume there is a main function in another non-haskell object ghcOptLinkNoHsMain = toFlag (ghcOptInputFiles baseOpts == mempty && ghcOptInputScripts baseOpts == mempty) } - comp = compiler lbi -- Work around old GHCs not relinking in this -- situation, see #3294 let target = targetDir makeRelativePathEx (exeTargetName (hostPlatform lbi) targetName) - when (compilerVersion comp < mkVersion [7, 7]) $ - removeFileForcibly (interpretSymbolicPathLBI lbi target) runGhcProg linkOpts{ghcOptOutputFile = toFlag target} -- | Link a foreign library component @@ -657,7 +606,7 @@ getRPaths pbci = do supportRPaths OSX = True supportRPaths FreeBSD = case compid of - CompilerId GHC ver | ver >= mkVersion [7, 10, 2] -> True + CompilerId GHC _ver -> True _ -> False supportRPaths OpenBSD = False supportRPaths NetBSD = False diff --git a/Cabal/src/Distribution/Simple/GHC/ImplInfo.hs b/Cabal/src/Distribution/Simple/GHC/ImplInfo.hs index f575697819b..feb7cea3da7 100644 --- a/Cabal/src/Distribution/Simple/GHC/ImplInfo.hs +++ b/Cabal/src/Distribution/Simple/GHC/ImplInfo.hs @@ -20,7 +20,13 @@ import Distribution.Compat.Prelude import Prelude () import Distribution.Simple.Compiler -import Distribution.Version + ( Compiler + , CompilerFlavor (..) + , compilerCompatVersion + , compilerFlavor + , compilerVersion + ) +import Distribution.Types.Version (Version, versionNumbers) -- | -- Information about features and quirks of a GHC-based implementation. @@ -34,32 +40,14 @@ import Distribution.Version -- module) should use implementation info rather than version numbers -- to test for supported features. data GhcImplInfo = GhcImplInfo - { supportsHaskell2010 :: Bool - -- ^ -XHaskell2010 and -XHaskell98 flags - , supportsGHC2021 :: Bool + { supportsGHC2021 :: Bool -- ^ -XGHC2021 flag , supportsGHC2024 :: Bool -- ^ -XGHC2024 flag - , reportsNoExt :: Bool - -- ^ --supported-languages gives Ext and NoExt - , alwaysNondecIndent :: Bool - -- ^ NondecreasingIndentation is always on - , flagGhciScript :: Bool - -- ^ -ghci-script flag supported - , flagProfAuto :: Bool - -- ^ new style -fprof-auto* flags , flagProfLate :: Bool -- ^ fprof-late flag - , flagPackageConf :: Bool - -- ^ use package-conf instead of package-db - , flagDebugInfo :: Bool - -- ^ -g flag supported , flagHie :: Bool -- ^ -hiedir flag supported - , supportsDebugLevels :: Bool - -- ^ supports numeric @-g@ levels - , supportsPkgEnvFiles :: Bool - -- ^ picks up @.ghc.environment@ files , flagWarnMissingHomeModules :: Bool -- ^ -Wmissing-home-modules is supported , unitIdForExes :: Bool @@ -88,19 +76,10 @@ getImplInfo comp = ghcVersionImplInfo :: Version -> GhcImplInfo ghcVersionImplInfo ver = GhcImplInfo - { supportsHaskell2010 = v >= [7] - , supportsGHC2021 = v >= [9, 1] + { supportsGHC2021 = v >= [9, 1] , supportsGHC2024 = v >= [9, 9] - , reportsNoExt = v >= [7] - , alwaysNondecIndent = v < [7, 1] - , flagGhciScript = v >= [7, 2] - , flagProfAuto = v >= [7, 4] , flagProfLate = v >= [9, 4] - , flagPackageConf = v < [7, 5] - , flagDebugInfo = v >= [7, 10] , flagHie = v >= [8, 8] - , supportsDebugLevels = v >= [8, 0] - , supportsPkgEnvFiles = v >= [8, 0, 1, 20160901] -- broken in 8.0.1, fixed in 8.0.2 , flagWarnMissingHomeModules = v >= [8, 2] , unitIdForExes = v >= [9, 2] } @@ -115,19 +94,10 @@ ghcjsVersionImplInfo -> GhcImplInfo ghcjsVersionImplInfo _ghcjsver ghcver = GhcImplInfo - { supportsHaskell2010 = True - , supportsGHC2021 = True + { supportsGHC2021 = ghcv >= [9, 1] , supportsGHC2024 = ghcv >= [9, 9] - , reportsNoExt = True - , alwaysNondecIndent = False - , flagGhciScript = True - , flagProfAuto = True - , flagProfLate = True - , flagPackageConf = False - , flagDebugInfo = False + , flagProfLate = ghcv >= [9, 4] , flagHie = ghcv >= [8, 8] - , supportsDebugLevels = ghcv >= [8, 0] - , supportsPkgEnvFiles = ghcv >= [8, 0, 2] -- TODO: check this works in ghcjs , flagWarnMissingHomeModules = ghcv >= [8, 2] , unitIdForExes = ghcv >= [9, 2] } diff --git a/Cabal/src/Distribution/Simple/GHC/Internal.hs b/Cabal/src/Distribution/Simple/GHC/Internal.hs index 51e984a141f..f32b0e34eb3 100644 --- a/Cabal/src/Distribution/Simple/GHC/Internal.hs +++ b/Cabal/src/Distribution/Simple/GHC/Internal.hs @@ -192,10 +192,8 @@ configureToolchain _implInfo ghcProg ghcInfo = ccFlags = getFlags "C compiler flags" cxxFlags = getFlags "C++ compiler flags" - -- GHC 7.8 renamed "Gcc Linker flags" to "C compiler link flags" - -- and "Ld Linker flags" to "ld flags" (GHC #4862). - gccLinkerFlags = getFlags "Gcc Linker flags" ++ getFlags "C compiler link flags" - ldLinkerFlags = getFlags "Ld Linker flags" ++ getFlags "ld flags" + gccLinkerFlags = getFlags "C compiler link flags" + ldLinkerFlags = getFlags "ld flags" -- It appears that GHC 7.6 and earlier encode the tokenized flags as a -- [String] in these settings whereas later versions just encode the flags as @@ -271,11 +269,9 @@ configureToolchain _implInfo ghcProg ghcInfo = else return ldProg getLanguages - :: Verbosity - -> GhcImplInfo - -> ConfiguredProgram + :: GhcImplInfo -> IO [(Language, String)] -getLanguages _ implInfo _ +getLanguages implInfo -- TODO: should be using --supported-languages rather than hard coding | supportsGHC2024 implInfo = return @@ -290,12 +286,11 @@ getLanguages _ implInfo _ , (Haskell2010, "-XHaskell2010") , (Haskell98, "-XHaskell98") ] - | supportsHaskell2010 implInfo = + | otherwise = return [ (Haskell98, "-XHaskell98") , (Haskell2010, "-XHaskell2010") ] - | otherwise = return [(Haskell98, "")] getGhcInfo :: Verbosity @@ -317,45 +312,18 @@ getGhcInfo verbosity _implInfo ghcProg = do getExtensions :: Verbosity - -> GhcImplInfo -> ConfiguredProgram -> IO [(Extension, Maybe String)] -getExtensions verbosity implInfo ghcProg = do +getExtensions verbosity ghcProg = do str <- getProgramOutput verbosity (suppressOverrideArgs ghcProg) ["--supported-languages"] - let extStrs = - if reportsNoExt implInfo - then lines str - else -- Older GHCs only gave us either Foo or NoFoo, - -- so we have to work out the other one ourselves - - [ extStr'' - | extStr <- lines str - , let extStr' = case extStr of - 'N' : 'o' : xs -> xs - _ -> "No" ++ extStr - , extStr'' <- [extStr, extStr'] - ] - let extensions0 = - [ (ext, Just $ "-X" ++ prettyShow ext) - | Just ext <- map simpleParsec extStrs - ] - extensions1 = - if alwaysNondecIndent implInfo - then -- ghc-7.2 split NondecreasingIndentation off - -- into a proper extension. Before that it - -- was always on. - -- Since it was not a proper extension, it could - -- not be turned off, hence we omit a - -- DisableExtension entry here. - - (EnableExtension NondecreasingIndentation, Nothing) - : extensions0 - else extensions0 - return extensions1 + return + [ (ext, Just $ "-X" ++ prettyShow ext) + | Just ext <- map simpleParsec $ lines str + ] includePaths :: LocalBuildInfo diff --git a/Cabal/src/Distribution/Simple/GHCJS.hs b/Cabal/src/Distribution/Simple/GHCJS.hs index 412842ed9ac..838c87cf5b2 100644 --- a/Cabal/src/Distribution/Simple/GHCJS.hs +++ b/Cabal/src/Distribution/Simple/GHCJS.hs @@ -153,8 +153,8 @@ configureCompiler verbosity hcPath conf0 = do let implInfo = ghcjsVersionImplInfo ghcjsVersion ghcjsGhcVersion - languages <- Internal.getLanguages verbosity implInfo ghcjsProg - extensions <- Internal.getExtensions verbosity implInfo ghcjsProg + languages <- Internal.getLanguages implInfo + extensions <- Internal.getExtensions verbosity ghcjsProg ghcjsInfo <- Internal.getGhcInfo verbosity implInfo ghcjsProg let ghcInfoMap = Map.fromList ghcjsInfo @@ -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 @@ -810,15 +793,7 @@ buildOrReplLib mReplFlags verbosity numJobs _pkg_descr lbi lib clbi = do , ghcOptInputFiles = toNubListR dynamicObjectFiles , ghcOptOutputFile = toFlag sharedLibFilePath , ghcOptExtra = hcOptions GHC libBi ++ hcSharedOptions GHC libBi - , -- For dynamic libs, Mac OS/X needs to know the install location - -- at build time. This only applies to GHC < 7.8 - see the - -- discussion in #1660. - {- - ghcOptDylibName = if hostOS == OSX - && ghcVersion < mkVersion [7,8] - then toFlag sharedLibInstallPath - else mempty, -} - ghcOptHideAllPackages = toFlag True + , ghcOptHideAllPackages = toFlag True , ghcOptNoAutoLinkPackages = toFlag True , ghcOptPackageDBs = withPackageDB lbi , ghcOptThisUnitId = case clbi of @@ -1569,8 +1544,6 @@ gbuild verbosity numJobs pkg_descr lbi bm clbi = do -- Work around old GHCs not relinking in this -- situation, see #3294 let target = targetDir makeRelativePathEx targetName - when (compilerVersion comp < mkVersion [7, 7]) $ - removeFileForcibly (i target) runGhcProg linkOpts{ghcOptOutputFile = toFlag target} GBuildFLib flib -> do let rtsInfo = extractRtsInfo lbi @@ -1739,7 +1712,7 @@ getRPaths lbi clbi | supportRPaths hostOS = do supportRPaths OSX = True supportRPaths FreeBSD = case compid of - CompilerId GHC ver | ver >= mkVersion [7, 10, 2] -> True + CompilerId GHC _ -> True _ -> False supportRPaths OpenBSD = False supportRPaths NetBSD = False @@ -2032,23 +2005,9 @@ findGhcjsPkgGhcjsVersion verbosity pgm = -- ----------------------------------------------------------------------------- -- Registering -hcPkgInfo :: ProgramDb -> HcPkg.HcPkgInfo +hcPkgInfo :: ProgramDb -> HcPkg.ConfiguredProgram hcPkgInfo progdb = - HcPkg.HcPkgInfo - { HcPkg.hcPkgProgram = ghcjsPkgProg - , HcPkg.noPkgDbStack = False - , HcPkg.noVerboseFlag = False - , HcPkg.flagPackageConf = False - , HcPkg.supportsDirDbs = True - , HcPkg.requiresDirDbs = ver >= v7_10 - , HcPkg.nativeMultiInstance = ver >= v7_10 - , HcPkg.recacheMultiInstance = True - , HcPkg.suppressFilesCheck = True - } - where - v7_10 = mkVersion [7, 10] - ghcjsPkgProg = fromMaybe (error "GHCJS.hcPkgInfo no ghcjs program") $ lookupProgram ghcjsPkgProgram progdb - ver = fromMaybe (error "GHCJS.hcPkgInfo no ghcjs version") $ programVersion ghcjsPkgProg + fromMaybe (error "GHCJS.hcPkgInfo no ghcjs program") $ lookupProgram ghcjsPkgProgram progdb registerPackage :: Verbosity diff --git a/Cabal/src/Distribution/Simple/Program/Builtin.hs b/Cabal/src/Distribution/Simple/Program/Builtin.hs index 7934d3be6b5..89379e3ab44 100644 --- a/Cabal/src/Distribution/Simple/Program/Builtin.hs +++ b/Cabal/src/Distribution/Simple/Program/Builtin.hs @@ -105,20 +105,7 @@ ghcProgram = } where ghcPostConf _verbosity ghcProg = do - let setLanguageEnv prog = - prog - { programOverrideEnv = - ("LANGUAGE", Just "en") - : programOverrideEnv ghcProg - } - - ignorePackageEnv prog = prog{programDefaultArgs = "-package-env=-" : programDefaultArgs prog} - - -- Only the 7.8 branch seems to be affected. Fixed in 7.8.4. - affectedVersionRange = - intersectVersionRanges - (laterVersion $ mkVersion [7, 8, 0]) - (earlierVersion $ mkVersion [7, 8, 4]) + let ignorePackageEnv prog = prog{programDefaultArgs = "-package-env=-" : programDefaultArgs prog} canIgnorePackageEnv = orLaterVersion $ mkVersion [8, 4, 4] @@ -130,11 +117,7 @@ ghcProgram = ( \v -> -- By default, ignore GHC_ENVIRONMENT variable of any package environment -- files. See #10759 - applyWhen (withinRange v canIgnorePackageEnv) ignorePackageEnv - -- Workaround for https://gitlab.haskell.org/ghc/ghc/-/issues/8825 - -- (spurious warning on non-english locales) - $ - applyWhen (withinRange v affectedVersionRange) setLanguageEnv ghcProg + applyWhen (withinRange v canIgnorePackageEnv) ignorePackageEnv ghcProg ) (programVersion ghcProg) diff --git a/Cabal/src/Distribution/Simple/Program/GHC.hs b/Cabal/src/Distribution/Simple/Program/GHC.hs index 7ecef3ce04a..d68ae7af414 100644 --- a/Cabal/src/Distribution/Simple/Program/GHC.hs +++ b/Cabal/src/Distribution/Simple/Program/GHC.hs @@ -1,6 +1,7 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE LambdaCase #-} {-# LANGUAGE MultiWayIf #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE RecordWildCards #-} @@ -796,18 +797,12 @@ renderGhcOptions comp _platform@(Platform _arch os) opts | not (flagBool ghcOptProfilingMode) -> [] Nothing -> [] - Just GhcProfAutoAll - | flagProfAuto implInfo -> ["-fprof-auto"] - | otherwise -> ["-auto-all"] -- not the same, but close + Just GhcProfAutoAll -> ["-fprof-auto"] Just GhcProfLate | flagProfLate implInfo -> ["-fprof-late"] | otherwise -> ["-fprof-auto-top"] -- not the same, not very close, but what we have. - Just GhcProfAutoToplevel - | flagProfAuto implInfo -> ["-fprof-auto-top"] - | otherwise -> ["-auto-all"] - Just GhcProfAutoExported - | flagProfAuto implInfo -> ["-fprof-auto-exported"] - | otherwise -> ["-auto"] + Just GhcProfAutoToplevel -> ["-fprof-auto-top"] + Just GhcProfAutoExported -> ["-fprof-auto-exported"] , ["-split-sections" | flagBool ghcOptSplitSections] , case compilerCompatVersion GHC comp of -- the -split-objs flag was removed in GHC 9.8 @@ -938,7 +933,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 @@ -948,9 +943,7 @@ renderGhcOptions comp _platform@(Platform _arch os) opts , ---------------------------- -- Language and extensions - if supportsHaskell2010 implInfo - then ["-X" ++ prettyShow lang | lang <- flag ghcOptLanguage] - else [] + ["-X" ++ prettyShow lang | lang <- flag ghcOptLanguage] , [ ext' | ext <- flags ghcOptExtensions , ext' <- case Map.lookup ext (ghcOptExtensionMap opts) of @@ -965,7 +958,9 @@ renderGhcOptions comp _platform@(Platform _arch os) opts , ---------------- -- GHCi - concat [["-ghci-script", script] | flagGhciScript implInfo, script <- ghcOptGHCiScripts opts] + concat + [ ["-ghci-script", script] | script <- ghcOptGHCiScripts opts + ] , --------------- -- Inputs @@ -999,27 +994,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) @@ -1036,11 +1013,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]) diff --git a/Cabal/src/Distribution/Simple/Program/HcPkg.hs b/Cabal/src/Distribution/Simple/Program/HcPkg.hs index ad635f362e7..df37425b4d8 100644 --- a/Cabal/src/Distribution/Simple/Program/HcPkg.hs +++ b/Cabal/src/Distribution/Simple/Program/HcPkg.hs @@ -14,7 +14,7 @@ -- Currently only GHC and GHCJS have hc-pkg programs. module Distribution.Simple.Program.HcPkg ( -- * Types - HcPkgInfo (..) + ConfiguredProgram (..) , RegisterOptions (..) , defaultRegisterOptions @@ -45,19 +45,44 @@ module Distribution.Simple.Program.HcPkg import Distribution.Compat.Prelude hiding (init) import Prelude () -import Distribution.InstalledPackageInfo -import Distribution.Parsec -import Distribution.Pretty +import Distribution.InstalledPackageInfo (InstalledPackageInfo (..), parseInstalledPackageInfo, showInstalledPackageInfo) +import Distribution.Parsec (simpleParsec) +import Distribution.Pretty (prettyShow) import Distribution.Simple.Compiler -import Distribution.Simple.Errors + ( PackageDB + , PackageDBS + , PackageDBStack + , PackageDBStackS + , PackageDBX (..) + , registrationPackageDB + ) +import Distribution.Simple.Errors (CabalException (..)) import Distribution.Simple.Program.Run -import Distribution.Simple.Program.Types -import Distribution.Simple.Utils -import Distribution.Types.ComponentId -import Distribution.Types.PackageId -import Distribution.Types.UnitId + ( IOEncoding (..) + , ProgramInvocation (..) + , getProgramInvocationLBS + , getProgramInvocationOutput + , programInvocation + , programInvocationCwd + , runProgramInvocation + ) +import Distribution.Simple.Program.Types (ConfiguredProgram (..)) +import Distribution.Simple.Utils (IOData (..), dieWithException, writeUTF8File) +import Distribution.Types.ComponentId (mkComponentId) +import Distribution.Types.PackageId (PackageId) +import Distribution.Types.UnitId (mkLegacyUnitId, unUnitId) import Distribution.Utils.Path -import Distribution.Verbosity + ( CWD + , FileLike ((<.>)) + , FileOrDir (Dir) + , PathLike (()) + , Pkg + , PkgDB + , SymbolicPath + , interpretSymbolicPath + , interpretSymbolicPathCWD + ) +import Distribution.Verbosity (Verbosity, VerbosityLevel (..), verbosityLevel) import Data.List (stripPrefix) import System.FilePath as FilePath @@ -72,53 +97,27 @@ import qualified Data.ByteString.Lazy as LBS import qualified Data.List.NonEmpty as NE import qualified System.FilePath.Posix as FilePath.Posix --- | Information about the features and capabilities of an @hc-pkg@ --- program. -data HcPkgInfo = HcPkgInfo - { hcPkgProgram :: ConfiguredProgram - , noPkgDbStack :: Bool - -- ^ no package DB stack supported - , noVerboseFlag :: Bool - -- ^ hc-pkg does not support verbosity flags - , flagPackageConf :: Bool - -- ^ use package-conf option instead of package-db - , supportsDirDbs :: Bool - -- ^ supports directory style package databases - , requiresDirDbs :: Bool - -- ^ requires directory style package databases - , nativeMultiInstance :: Bool - -- ^ supports --enable-multi-instance flag - , recacheMultiInstance :: Bool - -- ^ supports multi-instance via recache - , suppressFilesCheck :: Bool - -- ^ supports --force-files or equivalent - } - -- | Call @hc-pkg@ to initialise a package database at the location {path}. -- -- > hc-pkg init {path} -init :: HcPkgInfo -> Verbosity -> Bool -> FilePath -> IO () -init hpi verbosity preferCompat path - | not (supportsDirDbs hpi) - || (not (requiresDirDbs hpi) && preferCompat) = - writeFile path "[]" - | otherwise = - runProgramInvocation verbosity (initInvocation hpi verbosity path) +init :: ConfiguredProgram -> Verbosity -> FilePath -> IO () +init hpi verbosity path = + runProgramInvocation verbosity (initInvocation hpi verbosity path) -- | Run @hc-pkg@ using a given package DB stack, directly forwarding the -- provided command-line arguments to it. invoke - :: HcPkgInfo + :: ConfiguredProgram -> Verbosity -> Maybe (SymbolicPath CWD (Dir Pkg)) -> PackageDBStack -> [String] -> IO () -invoke hpi verbosity mbWorkDir dbStack extraArgs = +invoke ghcProg verbosity mbWorkDir dbStack extraArgs = runProgramInvocation verbosity invocation where - args = packageDbStackOpts hpi dbStack ++ extraArgs - invocation = programInvocationCwd mbWorkDir (hcPkgProgram hpi) args + args = packageDbStackOpts dbStack ++ extraArgs + invocation = programInvocationCwd mbWorkDir ghcProg args -- | Additional variations in the behaviour for 'register'. data RegisterOptions = RegisterOptions @@ -126,9 +125,7 @@ data RegisterOptions = RegisterOptions -- ^ Allows re-registering \/ overwriting an existing package , registerMultiInstance :: Bool -- ^ Insist on the ability to register multiple instances of a - -- single version of a single package. This will fail if the @hc-pkg@ - -- does not support it, see 'nativeMultiInstance' and - -- 'recacheMultiInstance'. + -- single version of a single package. , registerSuppressFilesCheck :: Bool -- ^ Require that no checks are performed on the existence of package -- files mentioned in the registration info. This must be used if @@ -149,7 +146,7 @@ defaultRegisterOptions = -- -- > hc-pkg register {filename | -} [--user | --global | --package-db] register - :: HcPkgInfo + :: ConfiguredProgram -> Verbosity -> Maybe (SymbolicPath CWD (Dir from)) -> PackageDBStackS from @@ -157,26 +154,10 @@ register -> RegisterOptions -> IO () register hpi verbosity mbWorkDir packagedbs pkgInfo registerOptions - | registerMultiInstance registerOptions - , not (nativeMultiInstance hpi || recacheMultiInstance hpi) = - dieWithException verbosity RegMultipleInstancePkg - | registerSuppressFilesCheck registerOptions - , not (suppressFilesCheck hpi) = - dieWithException verbosity SuppressingChecksOnFile - -- This is a trick. Older versions of GHC do not support the - -- --enable-multi-instance flag for ghc-pkg register but it turns out that - -- the same ability is available by using ghc-pkg recache. The recache - -- command is there to support distro package managers that like to work - -- by just installing files and running update commands, rather than - -- special add/remove commands. So the way to register by this method is - -- to write the package registration file directly into the package db and - -- then call hc-pkg recache. - -- - | registerMultiInstance registerOptions - , recacheMultiInstance hpi = + | registerMultiInstance registerOptions = do let pkgdb = registrationPackageDB packagedbs - writeRegistrationFileDirectly verbosity hpi mbWorkDir pkgdb pkgInfo + writeRegistrationFileDirectly verbosity mbWorkDir pkgdb pkgInfo recache hpi verbosity mbWorkDir pkgdb | otherwise = runProgramInvocation @@ -185,27 +166,24 @@ register hpi verbosity mbWorkDir packagedbs pkgInfo registerOptions writeRegistrationFileDirectly :: Verbosity - -> HcPkgInfo -> Maybe (SymbolicPath CWD (Dir from)) -> PackageDBS from -> InstalledPackageInfo -> IO () -writeRegistrationFileDirectly verbosity hpi mbWorkDir (SpecificPackageDB dir) pkgInfo - | supportsDirDbs hpi = - do - let pkgfile = interpretSymbolicPath mbWorkDir dir prettyShow (installedUnitId pkgInfo) <.> "conf" - writeUTF8File pkgfile (showInstalledPackageInfo pkgInfo) - | otherwise = - dieWithException verbosity NoSupportDirStylePackageDb -writeRegistrationFileDirectly verbosity _ _ _ _ = - -- We don't know here what the dir for the global or user dbs are, - -- if that's needed it'll require a bit more plumbing to support. - dieWithException verbosity OnlySupportSpecificPackageDb +writeRegistrationFileDirectly verbosity mbWorkDir package pkgInfo = + case package of + (SpecificPackageDB dir) -> do + let pkgfile = interpretSymbolicPath mbWorkDir dir prettyShow (installedUnitId pkgInfo) <.> "conf" + writeUTF8File pkgfile (showInstalledPackageInfo pkgInfo) + _ -> do + -- We don't know here what the dir for the global or user dbs are, + -- if that's needed it'll require a bit more plumbing to support. + dieWithException verbosity OnlySupportSpecificPackageDb -- | Call @hc-pkg@ to unregister a package -- -- > hc-pkg unregister [pkgid] [--user | --global | --package-db] -unregister :: HcPkgInfo -> Verbosity -> Maybe (SymbolicPath CWD (Dir Pkg)) -> PackageDB -> PackageId -> IO () +unregister :: ConfiguredProgram -> Verbosity -> Maybe (SymbolicPath CWD (Dir Pkg)) -> PackageDB -> PackageId -> IO () unregister hpi verbosity mbWorkDir packagedb pkgid = runProgramInvocation verbosity @@ -214,7 +192,7 @@ unregister hpi verbosity mbWorkDir packagedb pkgid = -- | Call @hc-pkg@ to recache the registered packages. -- -- > hc-pkg recache [--user | --global | --package-db] -recache :: HcPkgInfo -> Verbosity -> Maybe (SymbolicPath CWD (Dir from)) -> PackageDBS from -> IO () +recache :: ConfiguredProgram -> Verbosity -> Maybe (SymbolicPath CWD (Dir from)) -> PackageDBS from -> IO () recache hpi verbosity mbWorkDir packagedb = runProgramInvocation verbosity @@ -224,7 +202,7 @@ recache hpi verbosity mbWorkDir packagedb = -- -- > hc-pkg expose [pkgid] [--user | --global | --package-db] expose - :: HcPkgInfo + :: ConfiguredProgram -> Verbosity -> Maybe (SymbolicPath CWD (Dir Pkg)) -> PackageDB @@ -239,28 +217,28 @@ expose hpi verbosity mbWorkDir packagedb pkgid = -- -- > hc-pkg describe [pkgid] [--user | --global | --package-db] describe - :: HcPkgInfo + :: ConfiguredProgram -> Verbosity -> Maybe (SymbolicPath CWD (Dir Pkg)) -> PackageDBStack -> PackageId -> IO [InstalledPackageInfo] -describe hpi verbosity mbWorkDir packagedb pid = do +describe ghcProg verbosity mbWorkDir packagedb pid = do output <- getProgramInvocationLBS verbosity - (describeInvocation hpi (verbosityLevel verbosity) mbWorkDir packagedb pid) + (describeInvocation ghcProg (verbosityLevel verbosity) mbWorkDir packagedb pid) `catchIO` \_ -> return mempty case parsePackages output of Left ok -> return ok - _ -> dieWithException verbosity $ FailedToParseOutputDescribe (programId (hcPkgProgram hpi)) pid + _ -> dieWithException verbosity $ FailedToParseOutputDescribe (programId ghcProg) pid -- | Call @hc-pkg@ to hide a package. -- -- > hc-pkg hide [pkgid] [--user | --global | --package-db] hide - :: HcPkgInfo + :: ConfiguredProgram -> Verbosity -> Maybe (SymbolicPath CWD (Dir Pkg)) -> PackageDB @@ -274,22 +252,22 @@ hide hpi verbosity mbWorkDir packagedb pkgid = -- | Call @hc-pkg@ to get all the details of all the packages in the given -- package database. dump - :: HcPkgInfo + :: ConfiguredProgram -> Verbosity -> Maybe (SymbolicPath CWD (Dir from)) -> PackageDBX (SymbolicPath from (Dir PkgDB)) -> IO [InstalledPackageInfo] -dump hpi verbosity mbWorkDir packagedb = do +dump ghcProg verbosity mbWorkDir packagedb = do output <- getProgramInvocationLBS verbosity - (dumpInvocation hpi (verbosityLevel verbosity) mbWorkDir packagedb) + (dumpInvocation ghcProg (verbosityLevel verbosity) mbWorkDir packagedb) `catchIO` \e -> - dieWithException verbosity $ DumpFailed (programId (hcPkgProgram hpi)) (displayException e) + dieWithException verbosity $ DumpFailed (programId ghcProg) (displayException e) case parsePackages output of Left ok -> return ok - _ -> dieWithException verbosity $ FailedToParseOutputDump (programId (hcPkgProgram hpi)) + _ -> dieWithException verbosity $ FailedToParseOutputDump (programId ghcProg) parsePackages :: LBS.ByteString -> Either [InstalledPackageInfo] [String] parsePackages lbs0 = @@ -388,21 +366,21 @@ setUnitId pkginfo = pkginfo -- Note in particular that it does not include the 'UnitId', just -- the source 'PackageId' which is not necessarily unique in any package db. list - :: HcPkgInfo + :: ConfiguredProgram -> Verbosity -> Maybe (SymbolicPath CWD (Dir Pkg)) -> PackageDB -> IO [PackageId] -list hpi verbosity mbWorkDir packagedb = do +list ghcProg verbosity mbWorkDir packagedb = do output <- getProgramInvocationOutput verbosity - (listInvocation hpi (verbosityLevel verbosity) mbWorkDir packagedb) - `catchIO` \_ -> dieWithException verbosity $ ListFailed (programId (hcPkgProgram hpi)) + (listInvocation ghcProg (verbosityLevel verbosity) mbWorkDir packagedb) + `catchIO` \_ -> dieWithException verbosity $ ListFailed (programId ghcProg) case parsePackageIds output of Just ok -> return ok - _ -> dieWithException verbosity $ FailedToParseOutputList (programId (hcPkgProgram hpi)) + _ -> dieWithException verbosity $ FailedToParseOutputList (programId ghcProg) where parsePackageIds = traverse simpleParsec . words @@ -410,24 +388,24 @@ list hpi verbosity mbWorkDir packagedb = do -- The program invocations -- -initInvocation :: HcPkgInfo -> Verbosity -> FilePath -> ProgramInvocation -initInvocation hpi verbosity path = - programInvocation (hcPkgProgram hpi) args +initInvocation :: ConfiguredProgram -> Verbosity -> FilePath -> ProgramInvocation +initInvocation ghcProg verbosity path = + programInvocation ghcProg args where args = ["init", path] - ++ verbosityOpts hpi (verbosityLevel verbosity) + ++ verbosityOpts (verbosityLevel verbosity) registerInvocation - :: HcPkgInfo + :: ConfiguredProgram -> VerbosityLevel -> Maybe (SymbolicPath CWD (Dir from)) -> PackageDBStackS from -> InstalledPackageInfo -> RegisterOptions -> ProgramInvocation -registerInvocation hpi verbosity mbWorkDir packagedbs pkgInfo registerOptions = - (programInvocationCwd mbWorkDir (hcPkgProgram hpi) (args "-")) +registerInvocation ghcProg verbosity mbWorkDir packagedbs pkgInfo registerOptions = + (programInvocationCwd mbWorkDir ghcProg (args "-")) { progInvokeInput = Just $ IODataText $ showInstalledPackageInfo pkgInfo , progInvokeInputEncoding = IOEncodingUTF8 } @@ -439,146 +417,135 @@ registerInvocation hpi verbosity mbWorkDir packagedbs pkgInfo registerOptions = args file = [cmdname, file] - ++ packageDbStackOpts hpi packagedbs + ++ packageDbStackOpts packagedbs ++ [ "--enable-multi-instance" | registerMultiInstance registerOptions ] ++ [ "--force-files" | registerSuppressFilesCheck registerOptions ] - ++ verbosityOpts hpi verbosity + ++ verbosityOpts verbosity unregisterInvocation - :: HcPkgInfo + :: ConfiguredProgram -> VerbosityLevel -> Maybe (SymbolicPath CWD (Dir Pkg)) -> PackageDB -> PackageId -> ProgramInvocation -unregisterInvocation hpi verbosity mbWorkDir packagedb pkgid = - programInvocationCwd mbWorkDir (hcPkgProgram hpi) $ - ["unregister", packageDbOpts hpi packagedb, prettyShow pkgid] - ++ verbosityOpts hpi verbosity +unregisterInvocation ghcProg verbosity mbWorkDir packagedb pkgid = + programInvocationCwd mbWorkDir ghcProg $ + ["unregister", packageDbOpts packagedb, prettyShow pkgid] + ++ verbosityOpts verbosity recacheInvocation - :: HcPkgInfo + :: ConfiguredProgram -> VerbosityLevel -> Maybe (SymbolicPath CWD (Dir from)) -> PackageDBS from -> ProgramInvocation -recacheInvocation hpi verbosity mbWorkDir packagedb = - programInvocationCwd mbWorkDir (hcPkgProgram hpi) $ - ["recache", packageDbOpts hpi packagedb] - ++ verbosityOpts hpi verbosity +recacheInvocation ghcProg verbosity mbWorkDir packagedb = + programInvocationCwd mbWorkDir ghcProg $ + ["recache", packageDbOpts packagedb] + ++ verbosityOpts verbosity exposeInvocation - :: HcPkgInfo + :: ConfiguredProgram -> VerbosityLevel -> Maybe (SymbolicPath CWD (Dir Pkg)) -> PackageDB -> PackageId -> ProgramInvocation -exposeInvocation hpi verbosity mbWorkDir packagedb pkgid = - programInvocationCwd mbWorkDir (hcPkgProgram hpi) $ - ["expose", packageDbOpts hpi packagedb, prettyShow pkgid] - ++ verbosityOpts hpi verbosity +exposeInvocation ghcProg verbosity mbWorkDir packagedb pkgid = + programInvocationCwd mbWorkDir ghcProg $ + ["expose", packageDbOpts packagedb, prettyShow pkgid] + ++ verbosityOpts verbosity describeInvocation - :: HcPkgInfo + :: ConfiguredProgram -> VerbosityLevel -> Maybe (SymbolicPath CWD (Dir Pkg)) -> PackageDBStack -> PackageId -> ProgramInvocation -describeInvocation hpi verbosity mbWorkDir packagedbs pkgid = - programInvocationCwd mbWorkDir (hcPkgProgram hpi) $ +describeInvocation ghcProg verbosity mbWorkDir packagedbs pkgid = + programInvocationCwd mbWorkDir ghcProg $ ["describe", prettyShow pkgid] - ++ packageDbStackOpts hpi packagedbs - ++ verbosityOpts hpi verbosity + ++ packageDbStackOpts packagedbs + ++ verbosityOpts verbosity hideInvocation - :: HcPkgInfo + :: ConfiguredProgram -> VerbosityLevel -> Maybe (SymbolicPath CWD (Dir Pkg)) -> PackageDB -> PackageId -> ProgramInvocation -hideInvocation hpi verbosity mbWorkDir packagedb pkgid = - programInvocationCwd mbWorkDir (hcPkgProgram hpi) $ - ["hide", packageDbOpts hpi packagedb, prettyShow pkgid] - ++ verbosityOpts hpi verbosity +hideInvocation ghcProg verbosity mbWorkDir packagedb pkgid = + programInvocationCwd mbWorkDir ghcProg $ + ["hide", packageDbOpts packagedb, prettyShow pkgid] + ++ verbosityOpts verbosity dumpInvocation - :: HcPkgInfo + :: ConfiguredProgram -> VerbosityLevel -> Maybe (SymbolicPath CWD (Dir from)) -> PackageDBX (SymbolicPath from (Dir PkgDB)) -> ProgramInvocation -dumpInvocation hpi _verbosity mbWorkDir packagedb = - (programInvocationCwd mbWorkDir (hcPkgProgram hpi) args) +dumpInvocation ghcProg _verbosity mbWorkDir packagedb = + (programInvocationCwd mbWorkDir ghcProg args) { progInvokeOutputEncoding = IOEncodingUTF8 } where args = - ["dump", packageDbOpts hpi packagedb] - ++ verbosityOpts hpi Silent + ["dump", packageDbOpts packagedb] + ++ verbosityOpts Silent -- We use verbosity level 'Silent' because it is important that we -- do not contaminate the output with info/debug messages. listInvocation - :: HcPkgInfo + :: ConfiguredProgram -> VerbosityLevel -> Maybe (SymbolicPath CWD (Dir Pkg)) -> PackageDB -> ProgramInvocation -listInvocation hpi _verbosity mbWorkDir packagedb = - (programInvocationCwd mbWorkDir (hcPkgProgram hpi) args) +listInvocation ghcProg _verbosity mbWorkDir packagedb = + (programInvocationCwd mbWorkDir ghcProg args) { progInvokeOutputEncoding = IOEncodingUTF8 } where args = - ["list", "--simple-output", packageDbOpts hpi packagedb] - ++ verbosityOpts hpi Silent + ["list", "--simple-output", packageDbOpts packagedb] + ++ verbosityOpts Silent -- We use verbosity level 'Silent' because it is important that we -- do not contaminate the output with info/debug messages. -packageDbStackOpts :: HcPkgInfo -> PackageDBStackS from -> [String] -packageDbStackOpts hpi dbstack - | noPkgDbStack hpi = [packageDbOpts hpi (registrationPackageDB dbstack)] - | otherwise = case dbstack of - (GlobalPackageDB : UserPackageDB : dbs) -> - "--global" - : "--user" - : map specific dbs - (GlobalPackageDB : dbs) -> - "--global" - : ("--no-user-" ++ packageDbFlag hpi) - : map specific dbs - _ -> ierror +packageDbStackOpts :: PackageDBStackS from -> [String] +packageDbStackOpts dbstack = case dbstack of + (GlobalPackageDB : UserPackageDB : dbs) -> + "--global" + : "--user" + : map specific dbs + (GlobalPackageDB : dbs) -> + "--global" + : "--no-user-package-db" + : map specific dbs + _ -> ierror where - specific (SpecificPackageDB db) = "--" ++ packageDbFlag hpi ++ "=" ++ interpretSymbolicPathCWD db + specific (SpecificPackageDB db) = "--package-db=" ++ interpretSymbolicPathCWD db specific _ = ierror ierror :: a ierror = error ("internal error: unexpected package db stack: " ++ show dbstack) -packageDbFlag :: HcPkgInfo -> String -packageDbFlag hpi - | flagPackageConf hpi = - "package-conf" - | otherwise = - "package-db" - -packageDbOpts :: HcPkgInfo -> PackageDBX (SymbolicPath from (Dir PkgDB)) -> String -packageDbOpts _ GlobalPackageDB = "--global" -packageDbOpts _ UserPackageDB = "--user" -packageDbOpts hpi (SpecificPackageDB db) = "--" ++ packageDbFlag hpi ++ "=" ++ interpretSymbolicPathCWD db +packageDbOpts :: PackageDBX (SymbolicPath from (Dir PkgDB)) -> String +packageDbOpts GlobalPackageDB = "--global" +packageDbOpts UserPackageDB = "--user" +packageDbOpts (SpecificPackageDB db) = "--package-db=" ++ interpretSymbolicPathCWD db -verbosityOpts :: HcPkgInfo -> VerbosityLevel -> [String] -verbosityOpts hpi v - | noVerboseFlag hpi = - [] +verbosityOpts :: VerbosityLevel -> [String] +verbosityOpts v | v >= Deafening = ["-v2"] | v == Silent = ["-v0"] | otherwise = [] diff --git a/Cabal/src/Distribution/Simple/Register.hs b/Cabal/src/Distribution/Simple/Register.hs index 61ac50f1ff9..46bd977aeb6 100644 --- a/Cabal/src/Distribution/Simple/Register.hs +++ b/Cabal/src/Distribution/Simple/Register.hs @@ -370,20 +370,19 @@ relocRegistrationInfo verbosity pkg lib lbi clbi abi_hash packageDb = initPackageDB :: Verbosity -> Compiler -> ProgramDb -> FilePath -> IO () initPackageDB verbosity comp progdb dbPath = - createPackageDB verbosity comp progdb False dbPath + createPackageDB verbosity comp progdb dbPath -- | Create an empty package DB at the specified location. createPackageDB :: Verbosity -> Compiler -> ProgramDb - -> Bool -> FilePath -> IO () -createPackageDB verbosity comp progdb preferCompat dbPath = +createPackageDB verbosity comp progdb dbPath = case compilerFlavor comp of - GHC -> HcPkg.init (GHC.hcPkgInfo progdb) verbosity preferCompat dbPath - GHCJS -> HcPkg.init (GHCJS.hcPkgInfo progdb) verbosity False dbPath + GHC -> HcPkg.init (GHC.hcPkgInfo progdb) verbosity dbPath + GHCJS -> HcPkg.init (GHCJS.hcPkgInfo progdb) verbosity dbPath UHC -> return () _ -> dieWithException verbosity CreatePackageDB @@ -423,7 +422,7 @@ withHcPkg -> String -> Compiler -> ProgramDb - -> (HcPkg.HcPkgInfo -> IO a) + -> (HcPkg.ConfiguredProgram -> IO a) -> IO a withHcPkg verbosity name comp progdb f = case compilerFlavor comp of @@ -455,7 +454,7 @@ writeHcPkgRegisterScript -> Maybe (SymbolicPath CWD (Dir Pkg)) -> [InstalledPackageInfo] -> PackageDBStack - -> HcPkg.HcPkgInfo + -> HcPkg.ConfiguredProgram -> IO () writeHcPkgRegisterScript verbosity mbWorkDir ipis packageDbs hpi = do let genScript installedPkgInfo = diff --git a/cabal-dev-scripts/src/GenPathsModule.hs b/cabal-dev-scripts/src/GenPathsModule.hs index 7c5c947a5b7..19cc8874144 100644 --- a/cabal-dev-scripts/src/GenPathsModule.hs +++ b/cabal-dev-scripts/src/GenPathsModule.hs @@ -25,8 +25,6 @@ $(capture "decls" [d| data Z = Z { zPackageName :: PackageName , zVersionDigits :: String - , zSupportsCpp :: Bool - , zSupportsNoRebindableSyntax :: Bool , zAbsolute :: Bool , zRelocatable :: Bool , zIsWindows :: Bool diff --git a/cabal-dev-scripts/src/GenUtils.hs b/cabal-dev-scripts/src/GenUtils.hs index 5751f99a1aa..0bf24c23d27 100644 --- a/cabal-dev-scripts/src/GenUtils.hs +++ b/cabal-dev-scripts/src/GenUtils.hs @@ -7,7 +7,6 @@ module GenUtils where import Control.Lens (each, ix, (%~), (&)) import Data.Char (toUpper) -import Data.Maybe (fromMaybe) import Data.Proxy (Proxy (..)) import Data.Text (Text) import GHC.Generics (Generic) diff --git a/cabal-install/src/Distribution/Client/CmdExec.hs b/cabal-install/src/Distribution/Client/CmdExec.hs index f750e439341..b1e9abc8890 100644 --- a/cabal-install/src/Distribution/Client/CmdExec.hs +++ b/cabal-install/src/Distribution/Client/CmdExec.hs @@ -46,7 +46,6 @@ import Distribution.Client.ProjectOrchestration ) import Distribution.Client.ProjectPlanOutput ( PostBuildProjectStatus - , argsEquivalentOfGhcEnvironmentFile , createPackageEnvironmentAndArgs , updatePostBuildProjectStatus ) @@ -64,10 +63,6 @@ import Distribution.Client.Setup import Distribution.Simple.Command ( CommandUI (..) ) -import Distribution.Simple.GHC - ( GhcImplInfo (supportsPkgEnvFiles) - , getImplInfo - ) import Distribution.Simple.Program ( ConfiguredProgram , programDefaultArgs @@ -181,28 +176,16 @@ execAction flags extraArgs globalFlags = do -- point at the file. -- In case ghc is too old to support environment files, -- we pass the same info as arguments - let compiler = pkgConfigCompiler $ elaboratedShared buildCtx - envFilesSupported = supportsPkgEnvFiles (getImplInfo compiler) case extraArgs of [] -> dieWithException verbosity SpecifyAnExecutable exe : args -> do (program, _) <- requireProgram verbosity (simpleProgram exe) programDb - let environmentPackageArgs = - argsEquivalentOfGhcEnvironmentFile - compiler - (distDirLayout baseCtx) - (elaboratedPlanOriginal buildCtx) - buildStatus - programIsConfiguredCompiler = + let programIsConfiguredCompiler = matchCompilerPath (elaboratedShared buildCtx) program - - ( if envFilesSupported - then withTempEnvFile verbosity baseCtx buildCtx buildStatus - else \f -> f environmentPackageArgs [] - ) - $ \argOverrides envOverrides -> do + (withTempEnvFile verbosity baseCtx buildCtx buildStatus) $ + \argOverrides envOverrides -> do let program' = withOverrides envOverrides diff --git a/cabal-install/src/Distribution/Client/CmdInstall.hs b/cabal-install/src/Distribution/Client/CmdInstall.hs index 3884bb056e9..10f262ed10c 100644 --- a/cabal-install/src/Distribution/Client/CmdInstall.hs +++ b/cabal-install/src/Distribution/Client/CmdInstall.hs @@ -143,10 +143,8 @@ import Distribution.Simple.Flag ) import Distribution.Simple.GHC ( GhcEnvironmentFileEntry (..) - , GhcImplInfo (..) , ParseErrorExc , getGhcAppDir - , getImplInfo , ghcPlatformAndVersionString , readGhcEnvironmentFile , renderGhcEnvironmentFile @@ -442,12 +440,9 @@ installAction flags@NixStyleFlags{extraFlags, configFlags, installFlags, project (compiler@Compiler{compilerId = CompilerId compilerFlavor compilerVersion}, platform, progDb) <- configCompilerEx hcFlavor hcPath hcPkg preProgDb verbosity - let - GhcImplInfo{supportsPkgEnvFiles} = getImplInfo compiler - (usedPackageEnvFlag, envFile) <- getEnvFile clientInstallFlags platform compilerVersion (usedExistingPkgEnvFile, existingEnvEntries) <- - getExistingEnvEntries verbosity compilerFlavor supportsPkgEnvFiles envFile + getExistingEnvEntries verbosity compilerFlavor envFile packageDbs <- getPackageDbStack compiler projectConfigStoreDir projectConfigLogsDir projectConfigPackageDBs installedIndex <- getInstalledPackages verbosity compiler packageDbs progDb @@ -534,7 +529,6 @@ installAction flags@NixStyleFlags{extraFlags, configFlags, installFlags, project verbosity buildCtx installedIndex - compiler packageDbs envFile nonGlobalEnvEntries' @@ -960,7 +954,6 @@ installLibraries :: Verbosity -> ProjectBuildContext -> PI.PackageIndex InstalledPackageInfo - -> Compiler -> PackageDBStackCWD -> FilePath -- ^ Environment file @@ -973,62 +966,54 @@ installLibraries verbosity buildCtx installedIndex - compiler packageDbs' envFile envEntries showWarning = do - if supportsPkgEnvFiles $ getImplInfo compiler - then do - let validDb (SpecificPackageDB fp) = doesPathExist fp - validDb _ = pure True - -- if a user "installs" a global package and no existing cabal db exists, none will be created. - -- this ensures we don't add the "phantom" path to the file. - packageDbs <- filterM validDb packageDbs' - let - getLatest = - (=<<) (maybeToList . safeHead . snd) - . take 1 - . sortBy (comparing (Down . fst)) - . PI.lookupPackageName installedIndex - globalLatest = concatMap getLatest globalPackages - globalEntries = GhcEnvFilePackageId . installedUnitId <$> globalLatest - baseEntries = - GhcEnvFileClearPackageDbStack : fmap GhcEnvFilePackageDb packageDbs - pkgEntries = - ordNub $ - globalEntries - ++ envEntries - ++ entriesForLibraryComponents (targetsMap buildCtx) - contents' = renderGhcEnvironmentFile (baseEntries ++ pkgEntries) - createDirectoryIfMissing True (takeDirectory envFile) - writeFileAtomic envFile (BS.pack contents') - when showWarning $ - warn verbosity $ - "The libraries were installed by creating a global GHC environment file at:\n" - ++ envFile - ++ "\n" - ++ "\n" - ++ "The presence of such an environment file is likely to confuse or break other " - ++ "tools because it changes GHC's behaviour: it changes the default package set in " - ++ "ghc and ghci from its normal value (which is \"all boot libraries\"). GHC " - ++ "environment files are little-used and often not tested for.\n" - ++ "\n" - ++ "Furthermore, management of these environment files is still more difficult than " - ++ "it could be; see e.g. https://github.com/haskell/cabal/issues/6481 .\n" - ++ "\n" - ++ "Double-check that creating a global GHC environment file is really what you " - ++ "wanted! You can limit the effects of the environment file by creating it in a " - ++ "specific directory using the --package-env flag. For example, use:\n" - ++ "\n" - ++ "cabal install --lib --package-env .\n" - ++ "\n" - ++ "to create the file in the current directory." - else - warn verbosity $ - "The current compiler doesn't support safely installing libraries, " - ++ "so only executables will be available. (Library installation is " - ++ "supported on GHC 8.0+ only)" + let validDb (SpecificPackageDB fp) = doesPathExist fp + validDb _ = pure True + -- if a user "installs" a global package and no existing cabal db exists, none will be created. + -- this ensures we don't add the "phantom" path to the file. + packageDbs <- filterM validDb packageDbs' + let + getLatest = + (=<<) (maybeToList . safeHead . snd) + . take 1 + . sortBy (comparing (Down . fst)) + . PI.lookupPackageName installedIndex + globalLatest = concatMap getLatest globalPackages + globalEntries = GhcEnvFilePackageId . installedUnitId <$> globalLatest + baseEntries = + GhcEnvFileClearPackageDbStack : fmap GhcEnvFilePackageDb packageDbs + pkgEntries = + ordNub $ + globalEntries + ++ envEntries + ++ entriesForLibraryComponents (targetsMap buildCtx) + contents' = renderGhcEnvironmentFile (baseEntries ++ pkgEntries) + createDirectoryIfMissing True (takeDirectory envFile) + writeFileAtomic envFile (BS.pack contents') + when showWarning $ + warn verbosity $ + "The libraries were installed by creating a global GHC environment file at:\n" + ++ envFile + ++ "\n" + ++ "\n" + ++ "The presence of such an environment file is likely to confuse or break other " + ++ "tools because it changes GHC's behaviour: it changes the default package set in " + ++ "ghc and ghci from its normal value (which is \"all boot libraries\"). GHC " + ++ "environment files are little-used and often not tested for.\n" + ++ "\n" + ++ "Furthermore, management of these environment files is still more difficult than " + ++ "it could be; see e.g. https://github.com/haskell/cabal/issues/6481 .\n" + ++ "\n" + ++ "Double-check that creating a global GHC environment file is really what you " + ++ "wanted! You can limit the effects of the environment file by creating it in a " + ++ "specific directory using the --package-env flag. For example, use:\n" + ++ "\n" + ++ "cabal install --lib --package-env .\n" + ++ "\n" + ++ "to create the file in the current directory." -- See ticket #8894. This is safe to include any nonreinstallable boot pkg, -- but the particular package users will always expect to be in scope without specific installation @@ -1287,12 +1272,11 @@ getEnvFile clientInstallFlags platform compilerVersion = do -- | Returns the list of @GhcEnvFilePackageId@ values already existing in the -- environment being operated on. The @Bool@ is @True@ if we took settings -- from an existing file, @False@ otherwise. -getExistingEnvEntries :: Verbosity -> CompilerFlavor -> Bool -> FilePath -> IO (Bool, [GhcEnvironmentFileEntry FilePath]) -getExistingEnvEntries verbosity compilerFlavor supportsPkgEnvFiles envFile = do +getExistingEnvEntries :: Verbosity -> CompilerFlavor -> FilePath -> IO (Bool, [GhcEnvironmentFileEntry FilePath]) +getExistingEnvEntries verbosity compilerFlavor envFile = do envFileExists <- doesFileExist envFile (usedExisting, allEntries) <- if (compilerFlavor == GHC || compilerFlavor == GHCJS) - && supportsPkgEnvFiles && envFileExists then catch ((True,) <$> readGhcEnvironmentFile envFile) $ \(_ :: ParseErrorExc) -> warn diff --git a/cabal-install/src/Distribution/Client/CmdRepl.hs b/cabal-install/src/Distribution/Client/CmdRepl.hs index b9f361271cf..940237200ea 100644 --- a/cabal-install/src/Distribution/Client/CmdRepl.hs +++ b/cabal-install/src/Distribution/Client/CmdRepl.hs @@ -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' @@ -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' @@ -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, diff --git a/cabal-install/src/Distribution/Client/Init/NonInteractive/Heuristics.hs b/cabal-install/src/Distribution/Client/Init/NonInteractive/Heuristics.hs index 923dd289dc0..76b98a5279a 100644 --- a/cabal-install/src/Distribution/Client/Init/NonInteractive/Heuristics.hs +++ b/cabal-install/src/Distribution/Client/Init/NonInteractive/Heuristics.hs @@ -73,11 +73,8 @@ guessCabalSpecVersion = do -- | Guess the language specification based on the GHC version guessLanguage :: Interactive m => Compiler -> m Language -guessLanguage Compiler{compilerId = CompilerId GHC ver} = - return $ - if ver < mkVersion [7, 0, 1] - then Haskell98 - else Haskell2010 +guessLanguage Compiler{compilerId = CompilerId GHC _ver} = + return Haskell2010 guessLanguage _ = return defaultLanguage -- | Guess the package name based on the given root directory. diff --git a/cabal-install/src/Distribution/Client/ProjectBuilding.hs b/cabal-install/src/Distribution/Client/ProjectBuilding.hs index b2f24efc5d6..97b3de3b177 100644 --- a/cabal-install/src/Distribution/Client/ProjectBuilding.hs +++ b/cabal-install/src/Distribution/Client/ProjectBuilding.hs @@ -473,7 +473,7 @@ createPackageDBIfMissing exists <- Cabal.doesPackageDBExist dbPath unless exists $ do createDirectoryIfMissingVerbose verbosity True (takeDirectory dbPath) - Cabal.createPackageDB verbosity compiler progdb False dbPath + Cabal.createPackageDB verbosity compiler progdb dbPath createPackageDBIfMissing _ _ _ _ = return () -- | Given all the context and resources, (re)build an individual package. diff --git a/cabal-install/src/Distribution/Client/ProjectPlanOutput.hs b/cabal-install/src/Distribution/Client/ProjectPlanOutput.hs index 880770693fd..f5bbfa7e13a 100644 --- a/cabal-install/src/Distribution/Client/ProjectPlanOutput.hs +++ b/cabal-install/src/Distribution/Client/ProjectPlanOutput.hs @@ -47,8 +47,6 @@ import Distribution.Simple.BuildPaths import Distribution.Simple.Compiler import Distribution.Simple.GHC ( GhcEnvironmentFileEntry (..) - , GhcImplInfo (supportsPkgEnvFiles) - , getImplInfo , simpleGhcEnvironmentFile , writeGhcEnvironmentFile ) @@ -854,8 +852,7 @@ writePlanGhcEnvironment , pkgConfigPlatform = platform } postBuildStatus - | compilerFlavor compiler == GHC - , supportsPkgEnvFiles (getImplInfo compiler) = + | compilerFlavor compiler == GHC = -- TODO: check ghcjs compat fmap Just $ writeGhcEnvironmentFile diff --git a/cabal-install/src/Distribution/Client/ProjectPlanning.hs b/cabal-install/src/Distribution/Client/ProjectPlanning.hs index f6d97a8f8fa..df93e343ea3 100644 --- a/cabal-install/src/Distribution/Client/ProjectPlanning.hs +++ b/cabal-install/src/Distribution/Client/ProjectPlanning.hs @@ -1479,8 +1479,6 @@ planPackages -- GHC 8.6 needs Cabal >= 2.4 -- GHC 8.4 needs Cabal >= 2.2 -- GHC 8.2 needs Cabal >= 2.0 - -- GHC 8.0 needs Cabal >= 1.24 - -- GHC 7.10 needs Cabal >= 1.22 -- -- (NB: we don't need to consider older GHCs as Cabal >= 1.20 is -- the absolute lower bound) @@ -1497,10 +1495,7 @@ planPackages | isGHC, compVer >= mkVersion [8, 8] = mkVersion [3, 0] | isGHC, compVer >= mkVersion [8, 6] = mkVersion [2, 4] | isGHC, compVer >= mkVersion [8, 4] = mkVersion [2, 2] - | isGHC, compVer >= mkVersion [8, 2] = mkVersion [2, 0] - | isGHC, compVer >= mkVersion [8, 0] = mkVersion [1, 24] - | isGHC, compVer >= mkVersion [7, 10] = mkVersion [1, 22] - | otherwise = mkVersion [1, 20] + | otherwise = mkVersion [2, 0] where isGHC = compFlav `elem` [GHC, GHCJS] compFlav = compilerFlavor comp @@ -4093,27 +4088,13 @@ setupHsConfigureFlags ElabComponent _ -> toFlag elabComponentId configProgramPaths = Map.toList elabProgramPaths - configProgramArgs - | {- elabSetupScriptCliVersion < mkVersion [1,24,3] -} True = - -- workaround for - -- - -- It turns out, that even with Cabal 2.0, there's still cases such as e.g. - -- custom Setup.hs scripts calling out to GHC even when going via - -- @runProgram ghcProgram@, as e.g. happy does in its - -- - -- (see also ) - -- - -- So for now, let's pass the rather harmless and idempotent - -- `-hide-all-packages` flag to all invocations (which has - -- the benefit that every GHC invocation starts with a - -- consistently well-defined clean slate) until we find a - -- better way. - Map.toList $ - Map.insertWith - (++) - "ghc" - ["-hide-all-packages"] - elabProgramArgs + configProgramArgs = + Map.toList $ + Map.insertWith + (++) + "ghc" + ["-hide-all-packages"] + elabProgramArgs configProgramPathExtra = toNubList elabProgramPathExtra configHcFlavor = toFlag (compilerFlavor pkgConfigCompiler) configHcPath = mempty -- we use configProgramPaths instead diff --git a/cabal-install/src/Distribution/Client/ProjectPlanning/SetupPolicy.hs b/cabal-install/src/Distribution/Client/ProjectPlanning/SetupPolicy.hs index 0ef3b872286..e3a6595ecdb 100644 --- a/cabal-install/src/Distribution/Client/ProjectPlanning/SetupPolicy.hs +++ b/cabal-install/src/Distribution/Client/ProjectPlanning/SetupPolicy.hs @@ -237,9 +237,5 @@ legacyCustomSetupPkgs compiler (Platform _ os) = ++ ["unix" | os /= Windows] ++ ["ghc-prim" | isGHC] ++ ["template-haskell" | isGHC] - ++ ["old-time" | notGHC710] where isGHC = compilerCompatFlavor GHC compiler - notGHC710 = case compilerCompatVersion GHC compiler of - Nothing -> False - Just v -> v <= mkVersion [7, 9] diff --git a/cabal-install/tests/IntegrationTests2.hs b/cabal-install/tests/IntegrationTests2.hs index c35faec5efa..6d378fa40e6 100644 --- a/cabal-install/tests/IntegrationTests2.hs +++ b/cabal-install/tests/IntegrationTests2.hs @@ -1914,16 +1914,11 @@ testSetupScriptStyles config reportSubCase = do plan0@(_, _, sharedConfig) <- planProject testdir1 config - let isOSX (Platform _ OSX) = True - isOSX _ = False - compilerVer = compilerVersion (pkgConfigCompiler sharedConfig) + let compilerVer = compilerVersion (pkgConfigCompiler sharedConfig) -- Skip the Custom tests when the shipped Cabal library is buggy - unless - ( (isOSX (pkgConfigPlatform sharedConfig) && (compilerVer < mkVersion [7, 10])) - -- 9.10 ships Cabal 3.12.0.0 affected by #9940 - || (mkVersion [9, 10] <= compilerVer && compilerVer < mkVersion [9, 11]) - ) - $ do + -- 9.10 ships Cabal 3.12.0.0 affected by #9940 + unless (mkVersion [9, 10] <= compilerVer && compilerVer < mkVersion [9, 11]) $ + do (plan1, res1) <- executePlan plan0 pkg1 <- expectPackageInstalled plan1 res1 pkgidA elabSetupScriptStyle pkg1 @?= SetupCustomExplicitDeps diff --git a/cabal-install/tests/UnitTests/Distribution/Client/Init/NonInteractive.hs b/cabal-install/tests/UnitTests/Distribution/Client/Init/NonInteractive.hs index 6e3c096467b..bee9189d220 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/Init/NonInteractive.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/Init/NonInteractive.hs @@ -1179,11 +1179,6 @@ nonInteractiveTests pkgIx srcDb comp = (`languageHeuristics` (comp{compilerId = CompilerId GHC $ mkVersion [8, 10, 4]})) Haskell2010 [] - , testSimple - "Lower version compiler" - (`languageHeuristics` (comp{compilerId = CompilerId GHC $ mkVersion [6, 0, 1]})) - Haskell98 - [] ] , testGroup "Check extraDocFileHeuristics output" diff --git a/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs b/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs index db0f99fd6e8..2b98aa05432 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs @@ -27,7 +27,6 @@ import System.IO.Unsafe (unsafePerformIO) import Distribution.Deprecated.ParseUtils import qualified Distribution.Deprecated.ReadP as Parse -import Distribution.Compiler import Distribution.Package import Distribution.PackageDescription import qualified Distribution.Simple.InstallDirs as InstallDirs @@ -36,7 +35,6 @@ import Distribution.Simple.Program.Types import Distribution.Simple.Utils (toUTF8BS) import Distribution.System (OS (Windows), buildOS) import Distribution.Types.PackageVersionConstraint -import Distribution.Version import Distribution.Parsec import Distribution.Pretty @@ -74,16 +72,10 @@ tests = , testProperty "buildonly" prop_roundtrip_legacytypes_buildonly , testProperty "specific" prop_roundtrip_legacytypes_specific ] - ++ - -- a couple tests seem to trigger a RTS fault in ghc-7.6 and older - -- unclear why as of yet - concat - [ [ testProperty "shared" prop_roundtrip_legacytypes_shared - , testProperty "local" prop_roundtrip_legacytypes_local - , testProperty "all" prop_roundtrip_legacytypes_all - ] - | not usingGhc76orOlder - ] + ++ [ testProperty "shared" prop_roundtrip_legacytypes_shared + , testProperty "local" prop_roundtrip_legacytypes_local + , testProperty "all" prop_roundtrip_legacytypes_all + ] , testGroup "individual parser tests" [ testProperty "package location" prop_parsePackageLocationTokenQ @@ -103,11 +95,6 @@ tests = , testGetProjectRootUsability , testFindProjectRoot ] - where - usingGhc76orOlder = - case buildCompilerId of - CompilerId GHC v -> v < mkVersion [7, 7] - _ -> False testGetProjectRootUsability :: TestTree testGetProjectRootUsability = diff --git a/changelog.d/11630.md b/changelog.d/11630.md new file mode 100644 index 00000000000..e2951aa5d74 --- /dev/null +++ b/changelog.d/11630.md @@ -0,0 +1,7 @@ +--- +synopsis: Drop support for anything below GHC 8.0.0, base 4.9.0.0, Cabal 2.0.0.0 +packages: [cabal-install-solver, cabal-install, Cabal-syntax, Cabal] +prs: 11630 +--- +Drop support for anything below GHC 8.0.0, base 4.9.0.0, Cabal 2.0.0.0 +These versions were no longer tested and likely non-functional. diff --git a/templates/Paths_pkg.template.hs b/templates/Paths_pkg.template.hs index 9577070e169..5f04cd3aa05 100644 --- a/templates/Paths_pkg.template.hs +++ b/templates/Paths_pkg.template.hs @@ -1,9 +1,5 @@ -{% if supportsCpp %} {-# LANGUAGE CPP #-} -{% endif %} -{% if supportsNoRebindableSyntax %} {-# LANGUAGE NoRebindableSyntax #-} -{% endif %} {% if not absolute %} {-# LANGUAGE ForeignFunctionInterface #-} {% endif %} @@ -45,23 +41,8 @@ import Prelude import System.Environment (getExecutablePath) {% endif %} -{% if supportsCpp %} -#if defined(VERSION_base) - -#if MIN_VERSION_base(4,0,0) -catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a -#else -catchIO :: IO a -> (Exception.Exception -> IO a) -> IO a -#endif - -#else catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a -#endif catchIO = Exception.catch -{% else %} -catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a -catchIO = Exception.catch -{% endif %} -- |The package version. version :: Version