diff options
author | Hécate <hecate+gitlab@glitchbra.in> | 2020-06-30 23:09:23 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-07-18 07:26:42 -0400 |
commit | 6ba6a881c58459008f02fb4816f8dec2800c2b73 (patch) | |
tree | f160876889f9cc322494ba540837953179825edd /libraries/base/System | |
parent | 750a1595ef31cdc335f3bab045b2f19a9c43ff93 (diff) | |
download | haskell-6ba6a881c58459008f02fb4816f8dec2800c2b73.tar.gz |
Implement `fullCompilerVersion`
Follow-up of https://gitlab.haskell.org/ghc/ghc/-/issues/18403
This MR adds `fullCompilerVersion`, a function that shares the same
backend as the `--numeric-version` GHC flag, exposing a full,
three-digit version datatype.
Diffstat (limited to 'libraries/base/System')
-rw-r--r-- | libraries/base/System/Info.hs | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/libraries/base/System/Info.hs b/libraries/base/System/Info.hs index 840a9b5a25..70284d44ef 100644 --- a/libraries/base/System/Info.hs +++ b/libraries/base/System/Info.hs @@ -1,12 +1,12 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE Safe #-} -{-# LANGUAGE CPP #-} ----------------------------------------------------------------------------- -- | -- Module : System.Info -- Copyright : (c) The University of Glasgow 2001 -- License : BSD-style (see the file libraries/base/LICENSE) --- +-- -- Maintainer : libraries@haskell.org -- Stability : experimental -- Portability : portable @@ -19,18 +19,18 @@ ----------------------------------------------------------------------------- module System.Info - ( - os, - arch, - compilerName, - compilerVersion - ) where + ( os + , arch + , compilerName + , compilerVersion + , fullCompilerVersion + ) where -import Data.Version +import Data.Version (Version (..)) -- | The version of 'compilerName' with which the program was compiled -- or is being interpreted. --- +-- -- ==== __Example__ -- > ghci> compilerVersion -- > Version {versionBranch = [8,8], versionTags = []} @@ -38,6 +38,22 @@ compilerVersion :: Version compilerVersion = Version [major, minor] [] where (major, minor) = compilerVersionRaw `divMod` 100 +-- | The full version of 'compilerName' with which the program was compiled +-- or is being interpreted. It includes the major, minor, revision and an additional +-- identifier, generally in the form "<year><month><day>". +fullCompilerVersion :: Version +fullCompilerVersion = Version version [] + where + version :: [Int] + version = fmap read $ splitVersion __GLASGOW_HASKELL_FULL_VERSION__ + +splitVersion :: String -> [String] +splitVersion s = + case dropWhile (== '.') s of + "" -> [] + s' -> let (w, s'') = break (== '.') s' + in w : splitVersion s'' + #include "ghcplatform.h" -- | The operating system on which the program is running. |