-
Notifications
You must be signed in to change notification settings - Fork 721
/
Rev.hs
42 lines (35 loc) · 1.28 KB
/
Rev.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ForeignFunctionInterface #-}
module Cardano.Git.Rev
( gitRev
) where
import Data.Text (Text)
import qualified Data.Text as T
import Cardano.Git.RevFromGit (gitRevFromGit)
import GHC.Foreign (peekCStringLen)
import Foreign.C.String (CString)
import System.IO (utf8)
import System.IO.Unsafe (unsafeDupablePerformIO)
foreign import ccall "&_cardano_git_rev" c_gitrev :: CString
gitRev :: Text
gitRev | gitRevEmbed /= zeroRev = gitRevEmbed
| T.null fromGit = zeroRev
| otherwise = fromGit
where
-- Git revision embedded after compilation using
-- Data.FileEmbed.injectWith. If nothing has been injected,
-- this will be filled with 0 characters.
gitRevEmbed :: Text
gitRevEmbed = T.pack $ drop 28 $ unsafeDupablePerformIO (peekCStringLen utf8 (c_gitrev, 68))
-- Git revision found during compilation by running git. If
-- git could not be run, then this will be empty.
#if defined(arm_HOST_ARCH)
-- cross compiling to arm fails; due to a linker bug
fromGit = ""
#else
fromGit = T.strip (T.pack $(gitRevFromGit))
#endif
zeroRev :: Text
zeroRev = "0000000000000000000000000000000000000000"