summaryrefslogtreecommitdiff
path: root/src/compiler/GF/Infra
diff options
context:
space:
mode:
authorHerbert Lange <herbert.lange@gu.se>2025-08-08 17:36:03 +0200
committerHerbert Lange <herbert.lange@gu.se>2025-08-08 17:36:03 +0200
commite0ad7594dd510f64debc26004a6d02b0b829770a (patch)
tree1aba7ae365d274f453699a666befa483646207ff /src/compiler/GF/Infra
parente7c0b6dada71f16160aa60e6fed6251280cbaf16 (diff)
add build time and git info to BuildInfo
Diffstat (limited to 'src/compiler/GF/Infra')
-rw-r--r--src/compiler/GF/Infra/BuildInfo.hs26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/compiler/GF/Infra/BuildInfo.hs b/src/compiler/GF/Infra/BuildInfo.hs
index f0230246b..2896a17fe 100644
--- a/src/compiler/GF/Infra/BuildInfo.hs
+++ b/src/compiler/GF/Infra/BuildInfo.hs
@@ -1,13 +1,35 @@
{-# 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
+import Data.Time.Format.ISO8601
+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 $ iso8601Show 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