7
7
{-# LANGUAGE LambdaCase #-}
8
8
{-# LANGUAGE RankNTypes #-}
9
9
{-# LANGUAGE ScopedTypeVariables #-}
10
+ #ifdef GIT_REV
11
+ {-# LANGUAGE TemplateHaskell #-}
12
+ #endif
10
13
11
14
-----------------------------------------------------------------------------
12
15
26
29
-- various directory and file functions that do extra logging.
27
30
module Distribution.Simple.Utils
28
31
( cabalVersion
32
+ , cabalGitInfo
29
33
30
34
-- * logging and errors
31
35
, dieNoVerbosity
@@ -285,6 +289,16 @@ import System.IO.Unsafe
285
289
import qualified System.Process as Process
286
290
import qualified Text.PrettyPrint as Disp
287
291
292
+ #ifdef GIT_REV
293
+ import Data.Either (isLeft )
294
+ import GitHash
295
+ ( giHash
296
+ , giBranch
297
+ , giCommitDate
298
+ , tGitInfoCwdTry
299
+ )
300
+ #endif
301
+
288
302
-- We only get our own version number when we're building with ourselves
289
303
cabalVersion :: Version
290
304
#if defined(BOOTSTRAPPED_CABAL)
@@ -295,6 +309,28 @@ cabalVersion = mkVersion [CABAL_VERSION]
295
309
cabalVersion = mkVersion [3 ,0 ] -- used when bootstrapping
296
310
#endif
297
311
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
+
298
334
-- ----------------------------------------------------------------------------
299
335
-- Exception and logging utils
300
336
0 commit comments