Skip to content

Commit

Permalink
feat(ltl): Make version command output the git commit
Browse files Browse the repository at this point in the history
  • Loading branch information
symbiont-daniel-gustafsson committed Mar 26, 2021
1 parent a7b9057 commit 3eb9909
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/ltl/app/GitHash.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module GitHash where

import Control.Exception (throwIO)
import Language.Haskell.TH.Syntax (Exp, Q, runIO, lift)
import System.Environment (getEnv)
import System.IO.Error (catchIOError, isDoesNotExistError)

getVersionFromEnv :: IO String
getVersionFromEnv = do
getEnv "DETSYS_LTL_VERSION"
`catchIOError` \e ->
if isDoesNotExistError e
then return "unknown"
else throwIO e

tGetGitInfo :: Q Exp
tGetGitInfo = do
s <- runIO getVersionFromEnv
lift s
10 changes: 8 additions & 2 deletions src/ltl/app/Main.hs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where

import qualified Data.Aeson as Aeson
import qualified Data.Aeson.Text as AesonText
import qualified Data.Text.Lazy.IO as TextIO
import Options.Generic

import GitHash (tGetGitInfo)

import Ltl
import Ltl.Json
import qualified Ltl.Storage as Storage
Expand All @@ -26,11 +29,14 @@ data Config

instance ParseRecord Config

gitVersion :: String
gitVersion = $tGetGitInfo

main :: IO ()
main = do
(cfg, help) <- getWithHelp "LTL checker"
case cfg of
Version -> putStrLn "<GIT VERSION NOT IMPLEMENTED>"
Version -> putStrLn gitVersion
Check{..} -> do
trace <- Storage.sqliteLoad (unHelpful testId) (unHelpful runId)
testFormula <- case parse (unHelpful formula) of
Expand Down
3 changes: 3 additions & 0 deletions src/ltl/ltl.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ executable detsys-ltl
, ltl
, optparse-generic
, text
, template-haskell
other-modules:
GitHash

default-language: Haskell2010

Expand Down

0 comments on commit 3eb9909

Please sign in to comment.