aboutsummaryrefslogtreecommitdiff
path: root/src/CabalHelper/Compiletime/Types
diff options
context:
space:
mode:
authorDaniel Gröber <dxld@darkboxed.org>2020-05-01 23:00:21 +0200
committerDaniel Gröber <dxld@darkboxed.org>2020-05-02 15:44:26 +0200
commit11a515ed0e887eef081e514b51f29589cf6693ca (patch)
treec6b87fea634488a415359ede673f3f6ada5504b5 /src/CabalHelper/Compiletime/Types
parent15d23d0731aa4e592e709e3626444e18ce3f804a (diff)
Move CabalVersion and related types into a new module
Diffstat (limited to 'src/CabalHelper/Compiletime/Types')
-rw-r--r--src/CabalHelper/Compiletime/Types/Cabal.hs59
1 files changed, 59 insertions, 0 deletions
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