# LANGUAGE CPP #
{-# LANGUAGE OverloadedStrings #-}
# LANGUAGE TemplateHaskell #

module Cardano.Config.Git.Rev (
      gitRev
    ) where

import           Cardano.Prelude

import           Data.FileEmbed (dummySpaceWith)
import qualified Data.Text as T

import           Cardano.Config.Git.RevFromGit (gitRevFromGit)

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 = decodeUtf8 $(dummySpaceWith "gitrev" 40)

        -- 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"

# LANGUAGE OverloadedStrings #
 Git revision embedded after compilation using
 this will be filled with 0 characters.
 Git revision found during compilation by running git. If
 git could not be run, then this will be empty.
 cross compiling to arm fails; due to a linker bug
# LANGUAGE CPP #
# LANGUAGE TemplateHaskell #

module Cardano.Config.Git.Rev (
      gitRev
    ) where

import           Cardano.Prelude

import           Data.FileEmbed (dummySpaceWith)
import qualified Data.Text as T

import           Cardano.Config.Git.RevFromGit (gitRevFromGit)

gitRev :: Text
gitRev | gitRevEmbed /= zeroRev = gitRevEmbed
       | T.null fromGit         = zeroRev
       | otherwise              = fromGit
    where
  Data . FileEmbed.injectWith . If nothing has been injected ,
        gitRevEmbed :: Text
        gitRevEmbed = decodeUtf8 $(dummySpaceWith "gitrev" 40)

#if defined(arm_HOST_ARCH)
        fromGit = ""
#else
        fromGit = T.strip (T.pack $(gitRevFromGit))
#endif

zeroRev :: Text
zeroRev = "0000000000000000000000000000000000000000"
