77{-# LANGUAGE LambdaCase #-}
88{-# LANGUAGE RankNTypes #-}
99{-# LANGUAGE ScopedTypeVariables #-}
10+ #ifdef GIT_REV
11+ {-# LANGUAGE TemplateHaskell #-}
12+ #endif
1013
1114-----------------------------------------------------------------------------
1215
2629-- various directory and file functions that do extra logging.
2730module Distribution.Simple.Utils
2831 ( cabalVersion
32+ , cabalGitInfo
2933
3034 -- * logging and errors
3135 , dieNoVerbosity
@@ -285,6 +289,16 @@ import System.IO.Unsafe
285289import qualified System.Process as Process
286290import qualified Text.PrettyPrint as Disp
287291
292+ #ifdef GIT_REV
293+ import Data.Either (isLeft )
294+ import GitHash
295+ ( giHash
296+ , giBranch
297+ , giCommitDate
298+ , tGitInfoCwdTry
299+ )
300+ #endif
301+
288302-- We only get our own version number when we're building with ourselves
289303cabalVersion :: Version
290304#if defined(BOOTSTRAPPED_CABAL)
@@ -295,6 +309,28 @@ cabalVersion = mkVersion [CABAL_VERSION]
295309cabalVersion = mkVersion [3 ,0 ] -- used when bootstrapping
296310#endif
297311
312+ -- |
313+ -- `Cabal` Git information. Only filled in if built in a Git tree in
314+ -- developmnent mode and Template Haskell is available.
315+ cabalGitInfo :: String
316+ #ifdef GIT_REV
317+ cabalGitInfo = concat [ " (commit "
318+ , giHash'
319+ , branchInfo
320+ , " , "
321+ , either (const " " ) giCommitDate gi'
322+ , " )"
323+ ]
324+ where
325+ gi' = $$ tGitInfoCwdTry
326+ giHash' = take 7 . either (const " " ) giHash $ gi'
327+ branchInfo | isLeft gi' = " "
328+ | either id giBranch gi' == " master" = " "
329+ | otherwise = " on " <> either id giBranch gi'
330+ #else
331+ cabalGitInfo = " "
332+ #endif
333+
298334-- ----------------------------------------------------------------------------
299335-- Exception and logging utils
300336
0 commit comments