From e0ad7594dd510f64debc26004a6d02b0b829770a Mon Sep 17 00:00:00 2001 From: Herbert Lange Date: Fri, 8 Aug 2025 17:36:03 +0200 Subject: [PATCH 1/5] add build time and git info to BuildInfo --- gf.cabal | 3 ++- src/compiler/GF/Infra/BuildInfo.hs | 26 ++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/gf.cabal b/gf.cabal index ce0682d46..0b43c3a8a 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.20.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..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 From 1c4cde7c66d0583c40dbc69e63878e7ee52b8042 Mon Sep 17 00:00:00 2001 From: Herbert Lange Date: Fri, 8 Aug 2025 17:43:56 +0200 Subject: [PATCH 2/5] updating formating for git info --- src/compiler/GF/Infra/BuildInfo.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/GF/Infra/BuildInfo.hs b/src/compiler/GF/Infra/BuildInfo.hs index 2896a17fe..0e0103f3d 100644 --- a/src/compiler/GF/Infra/BuildInfo.hs +++ b/src/compiler/GF/Infra/BuildInfo.hs @@ -22,7 +22,7 @@ buildTime = $(do -- 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) + 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 #-} From f96830f7def621efdfe00278bf0024693a3e75cc Mon Sep 17 00:00:00 2001 From: Herbert Lange Date: Fri, 8 Aug 2025 17:50:33 +0200 Subject: [PATCH 3/5] change template haskell required version --- gf.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gf.cabal b/gf.cabal index 0b43c3a8a..69ea85e1c 100644 --- a/gf.cabal +++ b/gf.cabal @@ -159,7 +159,7 @@ library parallel >= 3.2.1.1 && < 3.3, process >= 1.4.3 && < 1.7, time >= 1.6.0 && <= 1.12.2, - template-haskell >= 2.20.0.0 + template-haskell >= 2.13.0.0 hs-source-dirs: src/compiler exposed-modules: From 78beac759862d330a89a5479c5dab84e5d8cd526 Mon Sep 17 00:00:00 2001 From: Herbert Lange Date: Fri, 8 Aug 2025 18:02:59 +0200 Subject: [PATCH 4/5] change date/time formating --- src/compiler/GF/Infra/BuildInfo.hs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/compiler/GF/Infra/BuildInfo.hs b/src/compiler/GF/Infra/BuildInfo.hs index 0e0103f3d..13c101ec5 100644 --- a/src/compiler/GF/Infra/BuildInfo.hs +++ b/src/compiler/GF/Infra/BuildInfo.hs @@ -9,7 +9,6 @@ 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 @@ -17,7 +16,7 @@ buildTime :: String buildTime = $(do timeZone <- liftIO getCurrentTimeZone time <- liftIO $ utcToLocalTime timeZone <$> getCurrentTime - return $ LitE $ StringL $ iso8601Show time ) + return $ LitE $ StringL $ formatTime defaultTimeLocale "%F %T" time ) -- Use Template Haskell to get current Git information gitInfo :: String From 9e5701b13c61c4ff63df6beb9fa7200ba8a81f9f Mon Sep 17 00:00:00 2001 From: Herbert Lange Date: Fri, 8 Aug 2025 18:06:03 +0200 Subject: [PATCH 5/5] hide ambiguous function --- src/compiler/GF/Infra/BuildInfo.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/GF/Infra/BuildInfo.hs b/src/compiler/GF/Infra/BuildInfo.hs index 13c101ec5..1807b4031 100644 --- a/src/compiler/GF/Infra/BuildInfo.hs +++ b/src/compiler/GF/Infra/BuildInfo.hs @@ -8,7 +8,7 @@ import Data.Version(showVersion) import Language.Haskell.TH.Syntax import Control.Monad.IO.Class import Control.Exception -import Data.Time +import Data.Time hiding (buildTime) import System.Process -- Use Template Haskell to get compile time