2020-01-11 20:15:05 +00:00
|
|
|
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
|
|
|
|
|
2020-07-21 23:08:58 +00:00
|
|
|
{-|
|
|
|
|
Module : GHCup.Version
|
2020-11-20 17:37:48 +00:00
|
|
|
Description : Version information and version handling.
|
2020-07-21 23:08:58 +00:00
|
|
|
Copyright : (c) Julian Ospald, 2020
|
2020-07-30 18:04:02 +00:00
|
|
|
License : LGPL-3.0
|
2020-07-21 23:08:58 +00:00
|
|
|
Maintainer : hasufell@hasufell.de
|
|
|
|
Stability : experimental
|
2021-05-14 21:09:45 +00:00
|
|
|
Portability : portable
|
2020-07-21 23:08:58 +00:00
|
|
|
-}
|
2020-01-11 20:15:05 +00:00
|
|
|
module GHCup.Version where
|
|
|
|
|
2020-11-20 17:37:48 +00:00
|
|
|
import GHCup.Types
|
2021-02-25 14:33:52 +00:00
|
|
|
import Paths_ghcup (version)
|
2020-01-11 20:15:05 +00:00
|
|
|
|
2021-02-25 14:33:52 +00:00
|
|
|
import Data.Version (Version(versionBranch))
|
|
|
|
import Data.Versions hiding (version)
|
2020-04-09 14:59:25 +00:00
|
|
|
import URI.ByteString
|
|
|
|
import URI.ByteString.QQ
|
|
|
|
|
2021-02-25 14:33:52 +00:00
|
|
|
import qualified Data.List.NonEmpty as NE
|
2020-04-17 14:56:56 +00:00
|
|
|
import qualified Data.Text as T
|
|
|
|
|
2020-08-09 15:39:02 +00:00
|
|
|
-- | This reflects the API version of the YAML.
|
2020-04-09 14:59:25 +00:00
|
|
|
ghcupURL :: URI
|
2021-07-28 17:17:59 +00:00
|
|
|
ghcupURL = [uri|https://www.haskell.org/ghcup/data/ghcup-0.0.6.yaml|]
|
2020-01-11 20:15:05 +00:00
|
|
|
|
2020-08-09 15:39:02 +00:00
|
|
|
-- | The current ghcup version.
|
2020-01-11 20:15:05 +00:00
|
|
|
ghcUpVer :: PVP
|
2021-02-25 14:33:52 +00:00
|
|
|
ghcUpVer = PVP . NE.fromList . fmap fromIntegral $ versionBranch version
|
2020-04-17 14:56:56 +00:00
|
|
|
|
2020-07-21 23:08:58 +00:00
|
|
|
-- | ghcup version as numeric string.
|
2020-04-17 14:56:56 +00:00
|
|
|
numericVer :: String
|
|
|
|
numericVer = T.unpack . prettyPVP $ ghcUpVer
|
2020-11-20 17:37:48 +00:00
|
|
|
|
|
|
|
versionCmp :: Versioning -> VersionCmp -> Bool
|
|
|
|
versionCmp ver1 (VR_gt ver2) = ver1 > ver2
|
|
|
|
versionCmp ver1 (VR_gteq ver2) = ver1 >= ver2
|
|
|
|
versionCmp ver1 (VR_lt ver2) = ver1 < ver2
|
|
|
|
versionCmp ver1 (VR_lteq ver2) = ver1 <= ver2
|
|
|
|
versionCmp ver1 (VR_eq ver2) = ver1 == ver2
|
|
|
|
|
|
|
|
versionRange :: Versioning -> VersionRange -> Bool
|
|
|
|
versionRange ver' (SimpleRange cmps) = and $ fmap (versionCmp ver') cmps
|
|
|
|
versionRange ver' (OrRange cmps range) =
|
|
|
|
versionRange ver' (SimpleRange cmps) || versionRange ver' range
|
|
|
|
|