diff options
| author | Inari Listenmaa <inari.listenmaa@gmail.com> | 2025-08-08 19:32:52 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-08 19:32:52 +0200 |
| commit | d07646e75356746ae3a3be96b74d11a367af9333 (patch) | |
| tree | 009f93d930a6d36434c208242582d32997ffc511 /src/compiler | |
| parent | 3b69a28dbd0ba1abb38f92a576c97ee1e667b985 (diff) | |
| parent | 9e5701b13c61c4ff63df6beb9fa7200ba8a81f9f (diff) | |
Merge pull request #192 from GrammaticalFramework/build-timestamp
Add build timestamps to GF prompt
Diffstat (limited to 'src/compiler')
| -rw-r--r-- | src/compiler/GF/Infra/BuildInfo.hs | 25 |
1 files changed, 23 insertions, 2 deletions
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 |
