Skip to content

Commit d07646e

Browse files
authored
Merge pull request #192 from GrammaticalFramework/build-timestamp
Add build timestamps to GF prompt
2 parents 3b69a28 + 9e5701b commit d07646e

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

gf.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ library
158158
json >= 0.9.1 && <= 0.11,
159159
parallel >= 3.2.1.1 && < 3.3,
160160
process >= 1.4.3 && < 1.7,
161-
time >= 1.6.0 && <= 1.12.2
161+
time >= 1.6.0 && <= 1.12.2,
162+
template-haskell >= 2.13.0.0
162163

163164
hs-source-dirs: src/compiler
164165
exposed-modules:

src/compiler/GF/Infra/BuildInfo.hs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
11
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE TemplateHaskell #-}
3+
24
module GF.Infra.BuildInfo where
35
import System.Info
46
import Data.Version(showVersion)
57

8+
import Language.Haskell.TH.Syntax
9+
import Control.Monad.IO.Class
10+
import Control.Exception
11+
import Data.Time hiding (buildTime)
12+
import System.Process
13+
14+
-- Use Template Haskell to get compile time
15+
buildTime :: String
16+
buildTime = $(do
17+
timeZone <- liftIO getCurrentTimeZone
18+
time <- liftIO $ utcToLocalTime timeZone <$> getCurrentTime
19+
return $ LitE $ StringL $ formatTime defaultTimeLocale "%F %T" time )
20+
21+
-- Use Template Haskell to get current Git information
22+
gitInfo :: String
23+
gitInfo = $(do
24+
info <- liftIO $ try $ readProcess "git" ["log", "--format=commit %h tag %(describe:tags=true)", "-1"] "" :: Q (Either SomeException String)
25+
return $ LitE $ StringL $ either (\_ -> "unavailable") id info )
26+
627
{-# NOINLINE buildInfo #-}
728
buildInfo =
829
"Built on "++os++"/"++arch
9-
++" with "++compilerName++"-"++showVersion compilerVersion
10-
++", flags:"
30+
++" with "++compilerName++"-"++showVersion compilerVersion ++ " at " ++ buildTime ++ "\nGit info: " ++ gitInfo
31+
++"\nFlags:"
1132
#ifdef USE_INTERRUPT
1233
++" interrupt"
1334
#endif

0 commit comments

Comments
 (0)