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 /src/CabalHelper/Compiletime/Program | |
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.
Diffstat (limited to 'src/CabalHelper/Compiletime/Program')
-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 |
3 files changed, 22 insertions, 12 deletions
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 |