From 11a515ed0e887eef081e514b51f29589cf6693ca Mon Sep 17 00:00:00 2001 From: Daniel Gröber Date: Fri, 1 May 2020 23:00:21 +0200 Subject: Move CabalVersion and related types into a new module --- src/CabalHelper/Compiletime/Types/Cabal.hs | 59 ++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/CabalHelper/Compiletime/Types/Cabal.hs (limited to 'src/CabalHelper/Compiletime/Types') 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 +-- +-- 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 -- cgit v1.2.3