{-# LANGUAGE DeriveFunctor #-}
module CabalHelper.Compiletime.Types.Cabal where
import Data.Version
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