{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module Cardano.Tools.GitRev (gitRev) where
import qualified Cardano.Git.Rev
import Data.Text (Text)
import qualified Data.Text as T
import GitHash (giDirty, giHash, tGitInfoCwdTry)
gitRev :: Text
gitRev :: Text
gitRev
| (Char -> Bool) -> Text -> Bool
T.all (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'0') Text
rev = Text
"unavailable (git info missing at build time)"
| Bool
otherwise = Text
rev
where
rev :: Text
rev =
$$(let eGitInfo = $$tGitInfoCwdTry in
case eGitInfo of
Right gitInfo ->
[||T.pack (giHash gitInfo) <> if giDirty gitInfo then "-dirty" else ""||]
Left _ -> [||otherRev||]
)
otherRev :: Text
otherRev = $(Cardano.Git.Rev.gitRev)