{-# 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 :: String
versionString =
  Version -> String
showVersion Version
version
    String -> String -> String
forall a. [a] -> [a] -> [a]
++ if String
used_hash String -> String -> Bool
forall a. Eq a => a -> a -> Bool
/= String
"UNKNOWN"
      then String
"\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
gitversion
      else String
""
  where
    used_hash :: String
used_hash = Int -> String -> String
forall a. Int -> [a] -> [a]
take Int
7 $(String
gitHash)

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