summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gf.cabal3
-rw-r--r--src/compiler/GF/Infra/BuildInfo.hs25
2 files changed, 25 insertions, 3 deletions
diff --git a/gf.cabal b/gf.cabal
index fc14643b7..4586436f8 100644
--- a/gf.cabal
+++ b/gf.cabal
@@ -158,7 +158,8 @@ library
json >= 0.9.1 && <= 0.11,
parallel >= 3.2.1.1 && < 3.3,
process >= 1.4.3 && < 1.7,
- time >= 1.6.0 && <= 1.12.2
+ time >= 1.6.0 && <= 1.12.2,
+ template-haskell >= 2.13.0.0
hs-source-dirs: src/compiler
exposed-modules:
diff --git a/src/compiler/GF/Infra/BuildInfo.hs b/src/compiler/GF/Infra/BuildInfo.hs
index f0230246b..1807b4031 100644
--- a/src/compiler/GF/Infra/BuildInfo.hs
+++ b/src/compiler/GF/Infra/BuildInfo.hs
@@ -1,13 +1,34 @@
{-# LANGUAGE CPP #-}
+{-# LANGUAGE TemplateHaskell #-}
+
module GF.Infra.BuildInfo where
import System.Info
import Data.Version(showVersion)
+import Language.Haskell.TH.Syntax
+import Control.Monad.IO.Class
+import Control.Exception
+import Data.Time hiding (buildTime)
+import System.Process
+
+-- Use Template Haskell to get compile time
+buildTime :: String
+buildTime = $(do
+ timeZone <- liftIO getCurrentTimeZone
+ time <- liftIO $ utcToLocalTime timeZone <$> getCurrentTime
+ return $ LitE $ StringL $ formatTime defaultTimeLocale "%F %T" time )
+
+-- Use Template Haskell to get current Git information
+gitInfo :: String
+gitInfo = $(do
+ info <- liftIO $ try $ readProcess "git" ["log", "--format=commit %h tag %(describe:tags=true)", "-1"] "" :: Q (Either SomeException String)
+ return $ LitE $ StringL $ either (\_ -> "unavailable") id info )
+
{-# NOINLINE buildInfo #-}
buildInfo =
"Built on "++os++"/"++arch
- ++" with "++compilerName++"-"++showVersion compilerVersion
- ++", flags:"
+ ++" with "++compilerName++"-"++showVersion compilerVersion ++ " at " ++ buildTime ++ "\nGit info: " ++ gitInfo
+ ++"\nFlags:"
#ifdef USE_INTERRUPT
++" interrupt"
#endif