aboutsummaryrefslogtreecommitdiff
path: root/src/CabalHelper
diff options
context:
space:
mode:
Diffstat (limited to 'src/CabalHelper')
-rw-r--r--src/CabalHelper/Compiletime/Cabal.hs44
-rw-r--r--src/CabalHelper/Compiletime/Compile.hs1
-rw-r--r--src/CabalHelper/Compiletime/Program/CabalInstall.hs4
-rw-r--r--src/CabalHelper/Compiletime/Program/GHC.hs2
-rw-r--r--src/CabalHelper/Compiletime/Types.hs1
-rw-r--r--src/CabalHelper/Compiletime/Types/Cabal.hs59
6 files changed, 70 insertions, 41 deletions
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