diff options
author | Daniel Gröber <dxld@darkboxed.org> | 2018-04-24 00:31:17 +0200 |
---|---|---|
committer | Daniel Gröber <dxld@darkboxed.org> | 2018-06-16 04:13:13 +0200 |
commit | 7fc3b9d468a4a2997a7fed63e378567f2ef3a401 (patch) | |
tree | 115244f1ea5dcd988ceac1f0e9203af493c410bc | |
parent | 8648be0324c8f9e5f2904907ae5da3f867ea9f5a (diff) |
Drop Cabal<2.0 compiletime support
We still support <2.0 at runtime this only concerns the Cabal version used at
cabal-install time.
-rw-r--r-- | .gitlab-ci.yml | 22 | ||||
-rw-r--r-- | Setup.hs | 113 | ||||
-rw-r--r-- | cabal-helper.cabal | 15 | ||||
-rw-r--r-- | tests/GhcSession.hs | 47 |
4 files changed, 32 insertions, 165 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d1a7777..7da4957 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,27 +11,17 @@ job-ghc8.2.2-cabal-install2.0.0.0: stage: build script: "$CI_PROJECT_DIR/scripts/ci/build.sh" -job-ghc8.0.2-cabal-install1.24.0.2: - image: registry.gitlab.com/dxld/ghc-mod:ghc8.0.2-cabal-install1.24.0.2 +job-ghc8.0.2-cabal-install2.0.0.0: + image: registry.gitlab.com/dxld/ghc-mod:ghc8.0.2-cabal-install2.0.0.0 stage: build script: "$CI_PROJECT_DIR/scripts/ci/build.sh" -job-ghc7.10.3-cabal-install1.24.0.2: - image: registry.gitlab.com/dxld/ghc-mod:ghc7.10.3-cabal-install1.24.0.2 +job-ghc7.10.3-cabal-install2.0.0.0: + image: registry.gitlab.com/dxld/ghc-mod:ghc7.10.3-cabal-install2.0.0.0 stage: build script: "$CI_PROJECT_DIR/scripts/ci/build.sh" -job-ghc7.8.4-cabal-install1.24.0.2: - image: registry.gitlab.com/dxld/ghc-mod:ghc7.8.4-cabal-install1.24.0.2 - stage: build - script: "$CI_PROJECT_DIR/scripts/ci/build.sh" - -job-ghc7.6.3-cabal-install1.24.0.2: - image: registry.gitlab.com/dxld/ghc-mod:ghc7.6.3-cabal-install1.24.0.2 - stage: build - script: "$CI_PROJECT_DIR/scripts/ci/build.sh" - -job-ghc7.4.2-cabal-install1.24.0.2: - image: registry.gitlab.com/dxld/ghc-mod:ghc7.4.2-cabal-install1.24.0.2 +job-ghc7.8.4-cabal-install2.0.0.0: + image: registry.gitlab.com/dxld/ghc-mod:ghc7.8.4-cabal-install2.0.0.0 stage: build script: "$CI_PROJECT_DIR/scripts/ci/build.sh" @@ -1,115 +1,2 @@ -{-# LANGUAGE CPP, RecordWildCards, NamedFieldPuns #-} - -#ifndef MIN_VERSION_Cabal -#define MIN_VERSION_Cabal(x,y,z) 0 -#endif - -#if MIN_VERSION_Cabal(2,0,0) - --- https://github.com/haskell/cabal/pull/4501 is upstream in 2.0, yey import Distribution.Simple main = defaultMain - -#else - -import Distribution.Simple -import Distribution.Simple.Utils -import Distribution.Simple.Setup -import Distribution.Simple.Install -import Distribution.Simple.Register -import Distribution.Simple.BuildPaths -import qualified Distribution.Simple.InstallDirs as ID -import Distribution.Simple.LocalBuildInfo -import Distribution.Simple.Program -import Distribution.PackageDescription - -import Control.Applicative -- for GHC<7.10 -import Control.Monad -import Data.List -import Data.Maybe -import System.FilePath -import System.Directory (renameFile) - -main :: IO () -main = defaultMainWithHooks $ simpleUserHooks { - instHook = inst, - copyHook = copy, - buildHook = \pd lbi hooks flags -> (buildHook simpleUserHooks) pd (patchLibexecdir lbi) hooks flags, - hookedPrograms = [ simpleProgram "cabal" ] - } - -patchLibexecdir :: LocalBuildInfo -> LocalBuildInfo -patchLibexecdir lbi = let - idirtpl = installDirTemplates lbi - libexecdir' = toPathTemplate $ fromPathTemplate (libexecdir idirtpl) </> "$abi/$pkgid" - lbi' = lbi { installDirTemplates = idirtpl { libexecdir = libexecdir' } } - in - lbi' - --- mostly copypasta from 'defaultInstallHook' -inst :: - PackageDescription -> LocalBuildInfo -> UserHooks -> InstallFlags -> IO () -inst pd lbi _uf ifl = do - let copyFlags = defaultCopyFlags { - copyDistPref = installDistPref ifl, - copyDest = toFlag NoCopyDest, - copyVerbosity = installVerbosity ifl - } - xInstallTarget pd lbi copyFlags (\pd' lbi' -> install pd' lbi' copyFlags) - let registerFlags = defaultRegisterFlags { - regDistPref = installDistPref ifl, - regInPlace = installInPlace ifl, - regPackageDB = installPackageDB ifl, - regVerbosity = installVerbosity ifl - } - when (hasLibs pd) $ register pd lbi registerFlags - -copy :: PackageDescription -> LocalBuildInfo -> UserHooks -> CopyFlags -> IO () -copy pd lbi _uh cf = - xInstallTarget pd lbi cf (\pd' lbi' -> install pd' lbi' cf) - -xInstallTarget :: PackageDescription - -> LocalBuildInfo - -> CopyFlags - -> (PackageDescription -> LocalBuildInfo -> IO ()) - -> IO () -xInstallTarget pd lbi cf fn = do - let (extended, regular) = partition isExeScopePrivate (executables pd) - - let pd_regular = pd { executables = regular } - - _ <- flip mapM extended $ \exe -> do - - let pd_extended = onlyExePackageDesc [exe] pd - - fn pd_extended lbi - - let lbi' = patchLibexecdir lbi - copydest = fromFlag (copyDest cf) - verbosity = fromFlag (copyVerbosity cf) - InstallDirs { bindir, libexecdir } = absoluteInstallDirs pd lbi' copydest - progprefix = substPathTemplate (packageId pd) lbi (progPrefix lbi) - progsuffix = substPathTemplate (packageId pd) lbi (progSuffix lbi) - fixedExeBaseName = progprefix ++ exeName exe ++ progsuffix - - fixedExeFileName = bindir </> fixedExeBaseName <.> exeExtension - newExeFileName = libexecdir </> fixedExeBaseName <.> exeExtension - - createDirectoryIfMissingVerbose verbosity True libexecdir - renameFile fixedExeFileName newExeFileName - - fn pd_regular lbi - -isExeScopePrivate :: Executable -> Bool -isExeScopePrivate exe = - fromMaybe False $ (=="private") <$> lookup "x-scope" fields - where - fields = customFieldsBI $ buildInfo exe - -onlyExePackageDesc :: [Executable] -> PackageDescription -> PackageDescription -onlyExePackageDesc exes pd = emptyPackageDescription { - package = package pd - , executables = exes - } - -#endif diff --git a/cabal-helper.cabal b/cabal-helper.cabal index a54d61f..13b6cd9 100644 --- a/cabal-helper.cabal +++ b/cabal-helper.cabal @@ -30,8 +30,8 @@ license-files: LICENSE author: Daniel Gröber <dxld@darkboxed.org> maintainer: dxld@darkboxed.org category: Distribution -build-type: Custom -cabal-version: >=1.14 +build-type: Simple +cabal-version: 2.0 extra-source-files: README.md src/CabalHelper/Runtime/*.hs @@ -62,12 +62,6 @@ source-repository head type: git location: https://github.com/DanielG/cabal-helper.git -custom-setup - setup-depends: base - , Cabal < 2.3 && >= 2.0 || < 1.25 && >= 1.14 - , filepath < 1.5 - , directory < 1.4 - flag dev description: Build development components default: False @@ -86,6 +80,8 @@ flag dev -- -- Instantiate common some-name -- -- $ gawk -i inplace -f scripts/update-cabal-common-section-instantiations.awk cabal-helper.cabal +-- +-- FIXME: We can use Cabal 2.0 features now, yey! library default-language: Haskell2010 @@ -96,6 +92,8 @@ library CabalHelper.Shared.InterfaceTypes CabalHelper.Shared.Sandbox Paths_cabal_helper + autogen-modules: Paths_cabal_helper + ghc-options: -Wall build-depends: base < 5 && >= 4.5 @@ -122,7 +120,6 @@ executable cabal-helper-wrapper if flag(dev) ghc-options: -Wall scope: private - x-scope: private -- Common c-h-wrapper-fields -- See [Note test dependencies] default-language: Haskell2010 diff --git a/tests/GhcSession.hs b/tests/GhcSession.hs index 4845565..6e71075 100644 --- a/tests/GhcSession.hs +++ b/tests/GhcSession.hs @@ -1,10 +1,7 @@ -{-# LANGUAGE TupleSections, ScopedTypeVariables, CPP #-} +{-# LANGUAGE TupleSections, ScopedTypeVariables #-} module Main where import GHC -#if __GLASGOW_HASKELL__ <= 706 -import GhcMonad -#endif import GHC.Paths (libdir) import DynFlags @@ -19,7 +16,7 @@ import System.FilePath ((</>)) import System.Directory import System.IO import System.IO.Temp -import System.Process (readProcess) +import System.Process (rawSystem, readProcess) import Distribution.Helper @@ -31,12 +28,13 @@ main = do args <- getArgs topdir <- getCurrentDirectory res <- mapM (setup topdir test) $ case args of - [] -> [ ("tests/exelib" , parseVer "1.10") - , ("tests/exeintlib", parseVer "2.0") - , ("tests/fliblib" , parseVer "2.0") - , ("tests/bkpregex" , parseVer "2.0") + [] -> [ ("tests/exelib" , parseVer "1.10", parseVer "0") + , ("tests/exeintlib", parseVer "2.0", parseVer "0") + , ("tests/fliblib" , parseVer "2.0", parseVer "0") + , ("tests/bkpregex" , parseVer "2.0", parseVer "8.1") + -- min Cabal lib ver -^ min GHC ver -^ ] - xs -> map (,parseVer "0") xs + xs -> map (, parseVer "0", parseVer "0") xs if any (==False) $ concat res then exitFailure @@ -46,21 +44,29 @@ cabalInstallVersion :: IO Version cabalInstallVersion = parseVer . trim <$> readProcess "cabal" ["--numeric-version"] "" +ghcVersion :: IO Version +ghcVersion = + parseVer . trim <$> readProcess "ghc" ["--numeric-version"] "" + cabalInstallBuiltinCabalVersion :: IO Version cabalInstallBuiltinCabalVersion = parseVer . trim <$> readProcess "cabal" ["act-as-setup", "--", "--numeric-version"] "" -setup :: FilePath -> (FilePath -> IO [Bool]) -> (FilePath, Version) -> IO [Bool] -setup topdir act (srcdir, min_cabal_ver) = do +setup :: FilePath -> (FilePath -> IO [Bool]) -> (FilePath, Version, Version) -> IO [Bool] +setup topdir act (srcdir, min_cabal_ver, min_ghc_ver) = do ci_ver <- cabalInstallVersion c_ver <- cabalInstallBuiltinCabalVersion + g_ver <- ghcVersion let mreason | (ci_ver < parseVer "1.24") = Just $ "cabal-install-" ++ showVersion ci_ver ++ " is too old" | c_ver < min_cabal_ver = Just $ "Cabal-" ++ showVersion c_ver ++ " < " ++ showVersion min_cabal_ver + | g_ver < min_ghc_ver = + Just $ "ghc-" ++ showVersion g_ver + ++ " < " ++ showVersion min_ghc_ver | otherwise = Nothing @@ -82,8 +88,7 @@ setup topdir act (srcdir, min_cabal_ver) = do run :: String -> [String] -> IO () run x xs = do print $ x:xs - o <- readProcess x xs "" - putStrLn o + ExitSuccess <- rawSystem x xs return () test :: FilePath -> IO [Bool] @@ -116,11 +121,7 @@ compileModule nb ep opts = do E.handle (\(ec :: ExitCode) -> print ec >> return False) $ do -#if __GLASGOW_HASKELL__ <= 704 - defaultErrorHandler defaultLogAction $ do -#else defaultErrorHandler defaultFatalMessager defaultFlushOut $ do -#endif runGhc (Just libdir) $ do @@ -165,7 +166,6 @@ compileModule nb ep opts = do setTargets ts' _ <- load LoadAllTargets -#if __GLASGOW_HASKELL__ >= 706 when (nb == NoBuildOutput) $ do setContext $ case ep of ChLibEntrypoint ms ms' ss -> @@ -174,16 +174,9 @@ compileModule nb ep opts = do map (IIModule . mkModuleName . unChModuleName) $ ChModuleName "Main" : ms ChSetupEntrypoint -> map (IIModule . mkModuleName) ["Main"] -#endif - liftIO'CH $ print ExitSuccess + liftIO $ print ExitSuccess return True unChModuleName :: ChModuleName -> String unChModuleName (ChModuleName mn) = mn - -#if __GLASGOW_HASKELL__ <= 706 -liftIO'CH = GhcMonad.liftIO -#else -liftIO'CH = liftIO -#endif |