diff options
-rw-r--r-- | cabal-helper.cabal | 1 | ||||
-rw-r--r-- | lib/Distribution/Helper.hs | 3 | ||||
-rw-r--r-- | src/CabalHelper/Compiletime/Cabal.hs | 44 | ||||
-rw-r--r-- | src/CabalHelper/Compiletime/Compile.hs | 1 | ||||
-rw-r--r-- | src/CabalHelper/Compiletime/Program/CabalInstall.hs | 4 | ||||
-rw-r--r-- | src/CabalHelper/Compiletime/Program/GHC.hs | 2 | ||||
-rw-r--r-- | src/CabalHelper/Compiletime/Types.hs | 1 | ||||
-rw-r--r-- | src/CabalHelper/Compiletime/Types/Cabal.hs | 59 | ||||
-rw-r--r-- | tests/CompileTest.hs | 1 |
9 files changed, 74 insertions, 42 deletions
diff --git a/cabal-helper.cabal b/cabal-helper.cabal index 6a035c4..d059338 100644 --- a/cabal-helper.cabal +++ b/cabal-helper.cabal @@ -137,6 +137,7 @@ common c-h-internal CabalHelper.Compiletime.Program.GHC CabalHelper.Compiletime.Sandbox CabalHelper.Compiletime.Types + CabalHelper.Compiletime.Types.Cabal CabalHelper.Compiletime.Types.RelativePath CabalHelper.Runtime.Compat CabalHelper.Runtime.HelperMain diff --git a/lib/Distribution/Helper.hs b/lib/Distribution/Helper.hs index 507adad..3c5007d 100644 --- a/lib/Distribution/Helper.hs +++ b/lib/Distribution/Helper.hs @@ -147,6 +147,7 @@ import CabalHelper.Compiletime.Log import CabalHelper.Compiletime.Process import CabalHelper.Compiletime.Sandbox import CabalHelper.Compiletime.Types +import CabalHelper.Compiletime.Types.Cabal import CabalHelper.Compiletime.Types.RelativePath import CabalHelper.Shared.InterfaceTypes import CabalHelper.Shared.Common @@ -768,7 +769,7 @@ newtype Helper pt getHelper :: PreInfo pt -> ProjInfo pt -> QueryEnvI c pt -> IO (Helper pt) getHelper _pre_info ProjInfo{piCabalVersion} qe@QueryEnv{..} - | piCabalVersion == bultinCabalVersion = return $ Helper $ + | CabalVersion piCabalVersion == bultinCabalVersion = return $ Helper $ \Unit{ uDistDir=DistDirLib distdir , uPackage=Package{pCabalFile=CabalFile cabal_file} } args -> diff --git a/src/CabalHelper/Compiletime/Cabal.hs b/src/CabalHelper/Compiletime/Cabal.hs index 1c4efa5..aad004c 100644 --- a/src/CabalHelper/Compiletime/Cabal.hs +++ b/src/CabalHelper/Compiletime/Cabal.hs @@ -15,7 +15,8 @@ Description : Cabal library source unpacking License : Apache-2.0 -} -{-# LANGUAGE DeriveFunctor, ViewPatterns, OverloadedStrings, CPP #-} +{-# LANGUAGE DeriveFunctor, ViewPatterns, OverloadedStrings #-} +{-# LANGUAGE CPP #-} -- for VERSION_Cabal module CabalHelper.Compiletime.Cabal where @@ -37,43 +38,10 @@ import qualified Data.ByteString as BS import qualified Data.ByteString.Char8 as BS8 import CabalHelper.Compiletime.Types +import CabalHelper.Compiletime.Types.Cabal import CabalHelper.Compiletime.Process import CabalHelper.Shared.Common (replace, parseVer, parseVerMay, parsePkgIdBS, panicIO) -type UnpackedCabalVersion = CabalVersion' (CommitId, CabalSourceDir) -type ResolvedCabalVersion = CabalVersion' CommitId -type CabalVersion = CabalVersion' () - -unpackedToResolvedCabalVersion :: UnpackedCabalVersion -> ResolvedCabalVersion -unpackedToResolvedCabalVersion (CabalHEAD (commit, _)) = CabalHEAD commit -unpackedToResolvedCabalVersion (CabalVersion ver) = CabalVersion ver - --- | Cabal library version we're compiling the helper exe against. -data CabalVersion' a - = CabalHEAD a - | CabalVersion { cvVersion :: Version } - deriving (Eq, Ord, Functor) - -newtype CommitId = CommitId { unCommitId :: String } - -showUnpackedCabalVersion :: UnpackedCabalVersion -> String -showUnpackedCabalVersion (CabalHEAD (commitid, _)) = - "HEAD-" ++ unCommitId commitid -showUnpackedCabalVersion CabalVersion {cvVersion} = - showVersion cvVersion - -showResolvedCabalVersion :: ResolvedCabalVersion -> String -showResolvedCabalVersion (CabalHEAD commitid) = - "HEAD-" ++ unCommitId commitid -showResolvedCabalVersion CabalVersion {cvVersion} = - showVersion cvVersion - -showCabalVersion :: CabalVersion -> String -showCabalVersion (CabalHEAD ()) = - "HEAD" -showCabalVersion CabalVersion {cvVersion} = - showVersion cvVersion - data CabalPatchDescription = CabalPatchDescription { cpdVersions :: [Version] , cpdUnpackVariant :: UnpackCabalVariant @@ -164,8 +132,6 @@ unpackCabal (CabalHEAD ()) tmpdir = do (commit, csdir) <- unpackCabalHEAD tmpdir return $ CabalHEAD (commit, csdir) -data UnpackCabalVariant = Pristine | LatestRevision -newtype CabalSourceDir = CabalSourceDir { unCabalSourceDir :: FilePath } unpackCabalHackage :: (Verbose, Progs) => Version @@ -254,8 +220,8 @@ complainIfNoCabalFile _ (Just cabal_file) = return cabal_file complainIfNoCabalFile pkgdir Nothing = panicIO $ "No cabal file found in package-dir: '"++pkgdir++"'" -bultinCabalVersion :: Version -bultinCabalVersion = parseVer VERSION_Cabal +bultinCabalVersion :: CabalVersion +bultinCabalVersion = CabalVersion $ parseVer VERSION_Cabal readSetupConfigHeader :: FilePath -> IO (Maybe UnitHeader) readSetupConfigHeader file = bracket (openFile file ReadMode) hClose $ \h -> do diff --git a/src/CabalHelper/Compiletime/Compile.hs b/src/CabalHelper/Compiletime/Compile.hs index d2886e8..2993906 100644 --- a/src/CabalHelper/Compiletime/Compile.hs +++ b/src/CabalHelper/Compiletime/Compile.hs @@ -58,6 +58,7 @@ import CabalHelper.Compiletime.Program.CabalInstall import CabalHelper.Compiletime.Sandbox ( getSandboxPkgDb ) import CabalHelper.Compiletime.Types +import CabalHelper.Compiletime.Types.Cabal import CabalHelper.Shared.Common diff --git a/src/CabalHelper/Compiletime/Program/CabalInstall.hs b/src/CabalHelper/Compiletime/Program/CabalInstall.hs index d5ed15e..9823c50 100644 --- a/src/CabalHelper/Compiletime/Program/CabalInstall.hs +++ b/src/CabalHelper/Compiletime/Program/CabalInstall.hs @@ -43,8 +43,10 @@ import qualified CabalHelper.Compiletime.Cabal as Cabal import CabalHelper.Compiletime.Types import CabalHelper.Compiletime.Program.GHC ( GhcVersion(..), createPkgDb ) +import CabalHelper.Compiletime.Types.Cabal + ( CabalSourceDir(..), UnpackedCabalVersion, CabalVersion'(..) ) import CabalHelper.Compiletime.Cabal - ( CabalSourceDir(..), UnpackedCabalVersion, CabalVersion'(..), unpackCabalV1 ) + ( unpackCabalV1 ) import CabalHelper.Compiletime.Process import CabalHelper.Shared.InterfaceTypes ( ChComponentName(..), ChLibraryName(..) ) diff --git a/src/CabalHelper/Compiletime/Program/GHC.hs b/src/CabalHelper/Compiletime/Program/GHC.hs index 95293fb..9ab0b33 100644 --- a/src/CabalHelper/Compiletime/Program/GHC.hs +++ b/src/CabalHelper/Compiletime/Program/GHC.hs @@ -31,7 +31,7 @@ import System.Directory import CabalHelper.Shared.Common (parseVer, trim, appCacheDir, parsePkgId) import CabalHelper.Compiletime.Types -import CabalHelper.Compiletime.Cabal +import CabalHelper.Compiletime.Types.Cabal ( ResolvedCabalVersion, showResolvedCabalVersion, UnpackedCabalVersion , unpackedToResolvedCabalVersion, CabalVersion'(..) ) import CabalHelper.Compiletime.Process diff --git a/src/CabalHelper/Compiletime/Types.hs b/src/CabalHelper/Compiletime/Types.hs index ab84178..b96101a 100644 --- a/src/CabalHelper/Compiletime/Types.hs +++ b/src/CabalHelper/Compiletime/Types.hs @@ -30,6 +30,7 @@ import GHC.Generics import System.FilePath (takeDirectory) import System.Posix.Types import CabalHelper.Compiletime.Types.RelativePath +import CabalHelper.Compiletime.Types.Cabal import CabalHelper.Shared.InterfaceTypes import Data.List.NonEmpty (NonEmpty) diff --git a/src/CabalHelper/Compiletime/Types/Cabal.hs b/src/CabalHelper/Compiletime/Types/Cabal.hs new file mode 100644 index 0000000..90ee975 --- /dev/null +++ b/src/CabalHelper/Compiletime/Types/Cabal.hs @@ -0,0 +1,59 @@ +-- cabal-helper: Simple interface to Cabal's configuration state +-- Copyright (C) 2020 Daniel Gröber <cabal-helper@dxld.at> +-- +-- SPDX-License-Identifier: Apache-2.0 +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 + +{-| +Module : CabalHelper.Compiletime.Types.Cabal +License : Apache-2.0 +-} + +{-# LANGUAGE DeriveFunctor #-} + +module CabalHelper.Compiletime.Types.Cabal where + +import Data.Version + +-- | Cabal library version we're compiling the helper exe against. +data CabalVersion' a + = CabalHEAD a + | CabalVersion { cvVersion :: Version } + deriving (Eq, Ord, Functor) + +newtype CommitId = CommitId { unCommitId :: String } + +type UnpackedCabalVersion = CabalVersion' (CommitId, CabalSourceDir) +type ResolvedCabalVersion = CabalVersion' CommitId +type CabalVersion = CabalVersion' () + +data UnpackCabalVariant = Pristine | LatestRevision +newtype CabalSourceDir = CabalSourceDir { unCabalSourceDir :: FilePath } + + +unpackedToResolvedCabalVersion :: UnpackedCabalVersion -> ResolvedCabalVersion +unpackedToResolvedCabalVersion (CabalHEAD (commit, _)) = CabalHEAD commit +unpackedToResolvedCabalVersion (CabalVersion ver) = CabalVersion ver + +showUnpackedCabalVersion :: UnpackedCabalVersion -> String +showUnpackedCabalVersion (CabalHEAD (commitid, _)) = + "HEAD-" ++ unCommitId commitid +showUnpackedCabalVersion CabalVersion {cvVersion} = + showVersion cvVersion + +showResolvedCabalVersion :: ResolvedCabalVersion -> String +showResolvedCabalVersion (CabalHEAD commitid) = + "HEAD-" ++ unCommitId commitid +showResolvedCabalVersion CabalVersion {cvVersion} = + showVersion cvVersion + +showCabalVersion :: CabalVersion -> String +showCabalVersion (CabalHEAD ()) = + "HEAD" +showCabalVersion CabalVersion {cvVersion} = + showVersion cvVersion diff --git a/tests/CompileTest.hs b/tests/CompileTest.hs index 8f79868..02580f8 100644 --- a/tests/CompileTest.hs +++ b/tests/CompileTest.hs @@ -36,6 +36,7 @@ import CabalHelper.Compiletime.Cabal import CabalHelper.Compiletime.Compile import CabalHelper.Compiletime.Program.GHC import CabalHelper.Compiletime.Types +import CabalHelper.Compiletime.Types.Cabal import CabalHelper.Shared.Common import TestOptions |