{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE Trustworthy #-}

-- | This module exports version information about the Futhark
-- compiler.
module Futhark.Version
  ( version,
    versionString,
  )
where

import Data.Version
import Development.GitRev
import qualified Paths_futhark

-- | The version of Futhark that we are using.  This is equivalent to
-- the version defined in the .cabal file.
version :: Version
version :: Version
version = Version
Paths_futhark.version

-- | The version of Futhark that we are using, as a 'String'
versionString :: String
versionString :: [Char]
versionString =
  Version -> [Char]
showVersion Version
version
    [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ if [Char]
used_hash [Char] -> [Char] -> Bool
forall a. Eq a => a -> a -> Bool
/= [Char]
"UNKNOWN"
      then [Char]
"\n" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
gitversion
      else [Char]
""
  where
    used_hash :: [Char]
used_hash = Int -> [Char] -> [Char]
forall a. Int -> [a] -> [a]
take Int
7 $(gitHash)

    gitversion :: [Char]
gitversion =
      [[Char]] -> [Char]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
        [ [Char]
"git: ",
          [Char]
branch,
          [Char]
used_hash,
          [Char]
" (",
          $(gitCommitDate),
          [Char]
")",
          [Char]
dirty
        ]
    branch :: [Char]
branch
      | $(gitBranch) [Char] -> [Char] -> Bool
forall a. Eq a => a -> a -> Bool
== [Char]
"master" = [Char]
""
      | Bool
otherwise = $(gitBranch) [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
" @ "
    dirty :: [Char]
dirty = if $(gitDirtyTracked) then [Char]
" [modified]" else [Char]
""