diff options
-rw-r--r-- | docs/users_guide/phases.rst | 2 | ||||
-rw-r--r-- | hadrian/src/Rules/Generate.hs | 2 | ||||
-rw-r--r-- | includes/ghc.mk | 2 | ||||
-rw-r--r-- | libraries/base/System/Info.hs | 36 | ||||
-rw-r--r-- | libraries/base/tests/SystemInfoTest.hs | 13 | ||||
-rw-r--r-- | libraries/base/tests/SystemInfoTest.stdout | 1 | ||||
-rw-r--r-- | libraries/base/tests/all.T | 1 |
7 files changed, 44 insertions, 13 deletions
diff --git a/docs/users_guide/phases.rst b/docs/users_guide/phases.rst index c7a17f6475..af65d613aa 100644 --- a/docs/users_guide/phases.rst +++ b/docs/users_guide/phases.rst @@ -336,7 +336,7 @@ defined by your local GHC installation, the following trick is useful: .. index:: single: __GLASGOW_HASKELL_FULL_VERSION__ This macro exposes the full version string. - For instance: ``__FULL_GHC_VERSION__==8.11.0.20200319``. + For instance: ``__GLASGOW_HASKELL_FULL_VERSION__==8.11.0.20200319``. Its value comes from the ``ProjectVersion`` Autotools variable. ``__GLASGOW_HASKELL_PATCHLEVEL1__``; \ ``__GLASGOW_HASKELL_PATCHLEVEL2__`` diff --git a/hadrian/src/Rules/Generate.hs b/hadrian/src/Rules/Generate.hs index 2ac01b4f48..62a7bbebbc 100644 --- a/hadrian/src/Rules/Generate.hs +++ b/hadrian/src/Rules/Generate.hs @@ -407,7 +407,7 @@ generateGhcVersionH = do , "#define __GLASGOW_HASKELL__ " ++ version , "#endif" , "#if !defined(__GLASGOW_HASKELL_FULL_VERSION__)" - , "#define __GLASGOW_HASKELL_FULL_VERSION__ " ++ fullVersion + , "#define __GLASGOW_HASKELL_FULL_VERSION__ \"" ++ fullVersion ++ "\"" , "#endif" , ""] ++ diff --git a/includes/ghc.mk b/includes/ghc.mk index 178bd537ff..cb95d9089b 100644 --- a/includes/ghc.mk +++ b/includes/ghc.mk @@ -75,7 +75,7 @@ $$(includes_$1_H_VERSION) : mk/project.mk | $$$$(dir $$$$@)/. @echo "#define __GHCVERSION_H__" >> $$@ @echo >> $$@ @echo "#define __GLASGOW_HASKELL__ $$(ProjectVersionInt)" >> $$@ - @echo "#define __GLASGOW_HASKELL_FULL_VERSION__ $$(ProjectVersion)" >> $$@ + @echo "#define __GLASGOW_HASKELL_FULL_VERSION__ \"$$(ProjectVersion)\"" >> $$@ @echo >> $$@ @if [ -n "$$(ProjectPatchLevel1)" ]; then \ echo "#define __GLASGOW_HASKELL_PATCHLEVEL1__ $$(ProjectPatchLevel1)" >> $$@; \ 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. diff --git a/libraries/base/tests/SystemInfoTest.hs b/libraries/base/tests/SystemInfoTest.hs new file mode 100644 index 0000000000..ef8c829df4 --- /dev/null +++ b/libraries/base/tests/SystemInfoTest.hs @@ -0,0 +1,13 @@ +{-# LANGUAGE CPP #-} +module Main where + +import Data.Version (showVersion) +import System.Info (fullCompilerVersion) + +main :: IO () +main = if textualVersion == macroVersion + then putStrLn "Match" + else putStrLn $ "[!]" <> textualVersion <> "should be equal to " <> macroVersion + where + macroVersion = __GLASGOW_HASKELL_FULL_VERSION__ + textualVersion = showVersion fullCompilerVersion diff --git a/libraries/base/tests/SystemInfoTest.stdout b/libraries/base/tests/SystemInfoTest.stdout new file mode 100644 index 0000000000..1796dc2720 --- /dev/null +++ b/libraries/base/tests/SystemInfoTest.stdout @@ -0,0 +1 @@ +Match diff --git a/libraries/base/tests/all.T b/libraries/base/tests/all.T index 4a29e8b571..c29b5b3a63 100644 --- a/libraries/base/tests/all.T +++ b/libraries/base/tests/all.T @@ -12,6 +12,7 @@ def normalise_quotes (str): #-------------------------------------- # Test functions #-------------------------------------- +test('SystemInfoTest', normal, compile_and_run, ['']) test('readFloat', exit_code(1), compile_and_run, ['']) test('enumDouble', normal, compile_and_run, ['']) test('enumRatio', normal, compile_and_run, ['']) |