summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHécate <hecate+gitlab@glitchbra.in>2020-07-01 23:35:39 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-07-03 17:34:36 -0400
commit7aa6ef110d8cc6626b1cf18d85a37cbac53e2795 (patch)
tree80a703c03e8fee5850954a89e84750f53c391e7f
parent41d2649288a5debcb4c8003e54b7d3072ab951c5 (diff)
downloadhaskell-7aa6ef110d8cc6626b1cf18d85a37cbac53e2795.tar.gz
Add the __GHC_FULL_VERSION__ CPP macro to expose the full GHC version
-rw-r--r--docs/users_guide/phases.rst7
-rw-r--r--hadrian/src/Rules/Generate.hs6
-rw-r--r--includes/ghc.mk1
-rw-r--r--testsuite/tests/driver/FullGHCVersion.hs10
-rw-r--r--testsuite/tests/driver/FullGHCVersion.stdout1
-rw-r--r--testsuite/tests/driver/all.T1
6 files changed, 25 insertions, 1 deletions
diff --git a/docs/users_guide/phases.rst b/docs/users_guide/phases.rst
index 33a57385bf..5975962370 100644
--- a/docs/users_guide/phases.rst
+++ b/docs/users_guide/phases.rst
@@ -332,6 +332,13 @@ defined by your local GHC installation, the following trick is useful:
source, including the C source generated from a Haskell module (i.e.
``.hs``, ``.lhs``, ``.c`` and ``.hc`` files).
+``__GLASGOW_HASKELL_FULL_VERSION__``
+ .. index::
+ single: __GLASGOW_HASKELL_FULL_VERSION__
+ This macro exposes the full version string.
+ For instance: ``__FULL_GHC_VERSION__==8.11.0.20200319``.
+ Its value comes from the ``ProjectVersion`` Autotools variable.
+
``__GLASGOW_HASKELL_PATCHLEVEL1__``; \ ``__GLASGOW_HASKELL_PATCHLEVEL2__``
.. index::
single: __GLASGOW_HASKELL_PATCHLEVEL2__
diff --git a/hadrian/src/Rules/Generate.hs b/hadrian/src/Rules/Generate.hs
index 6222fcd3af..5f226f438d 100644
--- a/hadrian/src/Rules/Generate.hs
+++ b/hadrian/src/Rules/Generate.hs
@@ -398,6 +398,7 @@ generateGhcAutoconfH = do
generateGhcVersionH :: Expr String
generateGhcVersionH = do
trackGenerateHs
+ fullVersion <- getSetting ProjectVersion
version <- getSetting ProjectVersionInt
patchLevel1 <- getSetting ProjectPatchLevel1
patchLevel2 <- getSetting ProjectPatchLevel2
@@ -406,7 +407,10 @@ generateGhcVersionH = do
, "#define __GHCVERSION_H__"
, ""
, "#if !defined(__GLASGOW_HASKELL__)"
- , "# define __GLASGOW_HASKELL__ " ++ version
+ , "#define __GLASGOW_HASKELL__ " ++ version
+ , "#endif"
+ , "#if !defined(__GLASGOW_HASKELL_FULL_VERSION__)"
+ , "#define __GLASGOW_HASKELL_FULL_VERSION__ " ++ fullVersion
, "#endif"
, ""]
++
diff --git a/includes/ghc.mk b/includes/ghc.mk
index c8180548d3..178bd537ff 100644
--- a/includes/ghc.mk
+++ b/includes/ghc.mk
@@ -75,6 +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 >> $$@
@if [ -n "$$(ProjectPatchLevel1)" ]; then \
echo "#define __GLASGOW_HASKELL_PATCHLEVEL1__ $$(ProjectPatchLevel1)" >> $$@; \
diff --git a/testsuite/tests/driver/FullGHCVersion.hs b/testsuite/tests/driver/FullGHCVersion.hs
new file mode 100644
index 0000000000..8fb56ced13
--- /dev/null
+++ b/testsuite/tests/driver/FullGHCVersion.hs
@@ -0,0 +1,10 @@
+{-# LANGUAGE CPP #-}
+
+module Main where
+
+main :: IO ()
+#if defined(__GLASGOW_HASKELL_FULL_VERSION__)
+main = putStrLn "__GLASGOW_HASKELL_FULL_VERSION__ is well-defined!"
+#else
+main = putStrLn "__GLASGOW_HASKELL_FULL_VERSION__ is not defined!"
+#endif
diff --git a/testsuite/tests/driver/FullGHCVersion.stdout b/testsuite/tests/driver/FullGHCVersion.stdout
new file mode 100644
index 0000000000..8a374b4e5d
--- /dev/null
+++ b/testsuite/tests/driver/FullGHCVersion.stdout
@@ -0,0 +1 @@
+__GLASGOW_HASKELL_FULL_VERSION__ is well-defined!
diff --git a/testsuite/tests/driver/all.T b/testsuite/tests/driver/all.T
index b78b13b3bb..d39614ee7d 100644
--- a/testsuite/tests/driver/all.T
+++ b/testsuite/tests/driver/all.T
@@ -282,3 +282,4 @@ test('T16737',
test('T17143', exit_code(1), run_command, ['{compiler} T17143.hs -S -fno-code'])
test('T17786', unless(opsys('mingw32'), skip), makefile_test, [])
test('T18369', normal, compile, ['-O'])
+test('FullGHCVersion', normal, compile_and_run, ['-package ghc-boot'])