diff options
author | Daniel Gröber <dxld@darkboxed.org> | 2019-08-06 19:39:23 +0200 |
---|---|---|
committer | Daniel Gröber <dxld@darkboxed.org> | 2020-05-10 21:50:44 +0200 |
commit | bda559bf059ee42e3e01c1280f7a64dd2673d725 (patch) | |
tree | bdfe97db7a53bd68638a6a7f102cd0942456e948 | |
parent | f606584fd104f864694e4fb9b943ef13904cdc96 (diff) |
Refactor Program versions handling
This mainly renames the program version getters to get* and make them
consistenly return Version directly. Such that wrappers like GhcVersion
have to be added at the callsites of the relevant functions.
-rw-r--r-- | lib/Distribution/Helper.hs | 2 | ||||
-rw-r--r-- | src/CabalHelper/Compiletime/Compile.hs | 4 | ||||
-rw-r--r-- | src/CabalHelper/Compiletime/Program/CabalInstall.hs | 17 | ||||
-rw-r--r-- | src/CabalHelper/Compiletime/Program/GHC.hs | 12 | ||||
-rw-r--r-- | src/CabalHelper/Compiletime/Program/Stack.hs | 5 | ||||
-rw-r--r-- | tests/CompileTest.hs | 4 | ||||
-rw-r--r-- | tests/GhcSession.hs | 32 |
7 files changed, 39 insertions, 37 deletions
diff --git a/lib/Distribution/Helper.hs b/lib/Distribution/Helper.hs index f8adcc4..4696590 100644 --- a/lib/Distribution/Helper.hs +++ b/lib/Distribution/Helper.hs @@ -312,7 +312,7 @@ unitInfo u = Query $ \qe -> getUnitInfo qe u -- | Get information on all units in a project. allUnits :: (UnitInfo -> a) -> Query pt (NonEmpty a) -allUnits f = do +allUnits f = fmap f <$> (T.mapM unitInfo =<< join . fmap pUnits <$> projectPackages) diff --git a/src/CabalHelper/Compiletime/Compile.hs b/src/CabalHelper/Compiletime/Compile.hs index e468c1b..e5d7dcd 100644 --- a/src/CabalHelper/Compiletime/Compile.hs +++ b/src/CabalHelper/Compiletime/Compile.hs @@ -112,7 +112,7 @@ compileHelper' => CompHelperEnv' UnpackedCabalVersion -> IO (Either ExitCode FilePath) compileHelper' CompHelperEnv {..} = do - ghcVer <- ghcVersion + ghcVer <- GhcVersion <$> getGhcVersion Just (prepare, comp) <- case cheCabalVer of cabalVer@CabalHEAD {} -> runMaybeT $ msum $ map (\f -> f ghcVer cabalVer) [ compileWithCabalV2GhcEnv' @@ -217,7 +217,7 @@ compileHelper' CompHelperEnv {..} = do compileWithCabalV2GhcEnv' :: Env => GhcVersion -> UnpackedCabalVersion -> MaybeT IO (IO (), Compile) compileWithCabalV2GhcEnv' ghcVer cabalVer = do _ <- maybe mzero pure cheDistV2 -- bail if this isn't a v2-build project - CabalInstallVersion instVer <- liftIO cabalInstallVersion + instVer <- liftIO getCabalInstallVersion guard $ instVer >= (Version [2,4,1,0] []) -- ^ didn't test with older versions guard $ ghcVer >= (GhcVersion (Version [8,0] [])) diff --git a/src/CabalHelper/Compiletime/Program/CabalInstall.hs b/src/CabalHelper/Compiletime/Program/CabalInstall.hs index 40f0561..36d6c63 100644 --- a/src/CabalHelper/Compiletime/Program/CabalInstall.hs +++ b/src/CabalHelper/Compiletime/Program/CabalInstall.hs @@ -57,11 +57,16 @@ newtype CabalInstallVersion = CabalInstallVersion { cabalInstallVer :: Version } data HEAD = HEAD deriving (Eq, Show) -cabalInstallVersion :: (Verbose, Progs) => IO CabalInstallVersion -cabalInstallVersion = do - CabalInstallVersion . parseVer . trim +getCabalInstallVersion :: (Verbose, Progs) => IO Version +getCabalInstallVersion = do + parseVer . trim <$> readProcess' (cabalProgram ?progs) ["--numeric-version"] "" +getCabalInstallBuiltinCabalVersion :: (Verbose, Progs) => IO Version +getCabalInstallBuiltinCabalVersion = + parseVer . trim <$> readProcess' (cabalProgram ?progs) + ["act-as-setup", "--", "--numeric-version"] "" + installCabalLibV1 :: Env => GhcVersion -> UnpackedCabalVersion -> IO PackageDbDir installCabalLibV1 ghcVer cabalVer = do withSystemTempDirectory "cabal-helper.install-cabal-tmp" $ \tmpdir -> do @@ -117,7 +122,7 @@ callCabalInstallV1 ghcVer unpackedCabalVer = do - civ@CabalInstallVersion {..} <- cabalInstallVersion + cabalInstallVer <- getCabalInstallVersion cabal_opts <- return $ concat [ [ "--package-db=clear" @@ -140,7 +145,7 @@ callCabalInstallV1 callProcessStderr (Just "/") [] (cabalProgram ?progs) cabal_opts - runSetupHs ghcVer db srcdir unpackedCabalVer civ + runSetupHs ghcVer db srcdir unpackedCabalVer $ CabalInstallVersion cabalInstallVer hPutStrLn stderr "done" @@ -221,7 +226,7 @@ installCabalLibV2 _ghcVer cv (PackageEnvFile env_file) = do return $ ("Cabal-"++showVersion cabalVer, "/") CabalHEAD (_commitid, CabalSourceDir srcdir) -> do return (".", srcdir) - CabalInstallVersion {..} <- cabalInstallVersion + cabalInstallVer <- getCabalInstallVersion cabal_opts <- return $ concat [ if cabalInstallVer >= Version [1,20] [] then ["--no-require-sandbox"] diff --git a/src/CabalHelper/Compiletime/Program/GHC.hs b/src/CabalHelper/Compiletime/Program/GHC.hs index 9ab0b33..7723a1f 100644 --- a/src/CabalHelper/Compiletime/Program/GHC.hs +++ b/src/CabalHelper/Compiletime/Program/GHC.hs @@ -60,16 +60,16 @@ newtype GhcVersion = GhcVersion { unGhcVersion :: Version } showGhcVersion :: GhcVersion -> String showGhcVersion (GhcVersion v) = showVersion v -ghcVersion :: (Verbose, Progs) => IO GhcVersion -ghcVersion = GhcVersion . +getGhcVersion :: (Verbose, Progs) => IO Version +getGhcVersion = parseVer . trim <$> readProcess' (ghcProgram ?progs) ["--numeric-version"] "" ghcLibdir :: (Verbose, Progs) => IO FilePath ghcLibdir = do trim <$> readProcess' (ghcProgram ?progs) ["--print-libdir"] "" -ghcPkgVersion :: (Verbose, Progs) => IO Version -ghcPkgVersion = +getGhcPkgVersion :: (Verbose, Progs) => IO Version +getGhcPkgVersion = parseVer . trim . dropWhile (not . isDigit) <$> readProcess' (ghcPkgProgram ?progs) ["--version"] "" @@ -85,9 +85,9 @@ createPkgDb cabalVer = do getPrivateCabalPkgDb :: (Verbose, Progs) => ResolvedCabalVersion -> IO PackageDbDir getPrivateCabalPkgDb cabalVer = do appdir <- appCacheDir - ghcVer <- ghcVersion + ghcVer <- getGhcVersion let db_path = - appdir </> "ghc-" ++ showGhcVersion ghcVer ++ ".package-dbs" + appdir </> "ghc-" ++ showVersion ghcVer ++ ".package-dbs" </> "Cabal-" ++ showResolvedCabalVersion cabalVer return $ PackageDbDir db_path diff --git a/src/CabalHelper/Compiletime/Program/Stack.hs b/src/CabalHelper/Compiletime/Program/Stack.hs index dc0b0e5..fe817cb 100644 --- a/src/CabalHelper/Compiletime/Program/Stack.hs +++ b/src/CabalHelper/Compiletime/Program/Stack.hs @@ -38,8 +38,13 @@ import Prelude import CabalHelper.Compiletime.Types import CabalHelper.Compiletime.Types.RelativePath +import CabalHelper.Compiletime.Process import CabalHelper.Shared.Common +getStackVersion :: (Verbose, Progs) => IO Version +getStackVersion = + parseVer . trim <$> readProcess' (stackProgram ?progs) [ "--numeric-version" ] "" + getPackage :: QueryEnvI c 'Stack -> CabalFile -> IO (Package 'Stack) getPackage qe cabal_file@(CabalFile cabal_file_path) = do let pkgdir = takeDirectory cabal_file_path diff --git a/tests/CompileTest.hs b/tests/CompileTest.hs index c0280bf..8af7335 100644 --- a/tests/CompileTest.hs +++ b/tests/CompileTest.hs @@ -72,7 +72,7 @@ main = do case args of "list-versions":[] -> do - mapM_ print =<< relevantCabalVersions =<< ghcVersion + mapM_ print =<< relevantCabalVersions =<< (GhcVersion <$> getGhcVersion) "list-versions":ghc_ver_str:[] -> mapM_ print =<< relevantCabalVersions (GhcVersion (parseVer ghc_ver_str)) _ -> @@ -125,7 +125,7 @@ allCabalVersions (GhcVersion ghc_ver) = do testRelevantCabalVersions :: Env => IO () testRelevantCabalVersions = do - ghc_ver <- ghcVersion + ghc_ver <- GhcVersion <$> getGhcVersion relevant_cabal_versions <- relevantCabalVersions ghc_ver testCabalVersions $ map CabalVersion relevant_cabal_versions ++ [CabalHEAD ()] diff --git a/tests/GhcSession.hs b/tests/GhcSession.hs index c776164..c5047ea 100644 --- a/tests/GhcSession.hs +++ b/tests/GhcSession.hs @@ -34,12 +34,13 @@ import Text.Show.Pretty (pPrint) import Distribution.Helper import CabalHelper.Shared.Common -import CabalHelper.Compiletime.Types (Env) +import CabalHelper.Compiletime.Types (Env, Verbose, Progs) import CabalHelper.Compiletime.Process (readProcess, callProcessStderr) import CabalHelper.Compiletime.Program.GHC - (GhcVersion(..), ghcVersion, ghcLibdir) + (GhcVersion(..), getGhcVersion, ghcLibdir) import CabalHelper.Compiletime.Program.CabalInstall - (CabalInstallVersion(..), cabalInstallVersion) + (getCabalInstallVersion, getCabalInstallBuiltinCabalVersion) +import CabalHelper.Compiletime.Program.Stack (getStackVersion) import TestOptions @@ -71,16 +72,16 @@ main = do ?progs = modProgs defaultPrograms in action - GhcVersion g_ver <- withEnv ghcVersion - CabalInstallVersion ci_ver <- withEnv cabalInstallVersion - s_ver <- withEnv stackVersion + g_ver <- withEnv getGhcVersion + ci_ver <- withEnv getCabalInstallVersion + s_ver <- withEnv getStackVersion `E.catch` \(_ :: IOError) -> return (makeVersion [0]) -- Cabal lib version f_c_ver :: ProjType -> Either SkipReason Version <- do - ci_c_ver <- Right <$> withEnv cabalInstallBuiltinCabalVersion + ci_c_ver <- Right <$> withEnv getCabalInstallBuiltinCabalVersion s_c_ver :: Either SkipReason Version - <- sequence $ withEnv stackBuiltinCabalVersion s_ver g_ver + <- sequence $ withEnv getStackBuiltinCabalVersion s_ver g_ver return $ \pt -> case pt of Cabal CV1 -> ci_c_ver Cabal CV2 -> ci_c_ver @@ -518,14 +519,10 @@ copyMuliPackageProject progs srcdir destdir copyPkgExtra = do , "--output-directory="++destdir </> pkgdir ] copyPkgExtra (srcdir </> pkgdir) (destdir </> pkgdir) -stackVersion :: (?progs :: Programs) => IO Version -stackVersion = - parseVer . trim <$> readProcess (stackProgram ?progs) [ "--numeric-version" ] "" - -stackBuiltinCabalVersion - :: (?progs :: Programs) +getStackBuiltinCabalVersion + :: (Verbose, Progs) => Version -> Version -> Either SkipReason (IO Version) -stackBuiltinCabalVersion s_ver g_ver = do +getStackBuiltinCabalVersion s_ver g_ver = do _ <- stackCheckCompat s_ver res <- lookupStackResolver g_ver return $ parseVer . trim <$> readProcess (stackProgram ?progs) @@ -540,11 +537,6 @@ stackCheckCompat s_ver = | otherwise -> Right () -cabalInstallBuiltinCabalVersion :: (?progs :: Programs) => IO Version -cabalInstallBuiltinCabalVersion = - parseVer . trim <$> readProcess (cabalProgram ?progs) - ["act-as-setup", "--", "--numeric-version"] "" - normalizeOutputWithVars = replaceStrings replaceStrings :: [(String, String)] -> String -> String replaceStrings ts str = |