From 780fc8894379f28af0f03bc27c3a41aca8c95b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Tue, 25 Apr 2023 22:17:58 +0200 Subject: Command-line option to report version --- src/Version/Git.hs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/Version/Git.hs (limited to 'src/Version/Git.hs') diff --git a/src/Version/Git.hs b/src/Version/Git.hs new file mode 100644 index 0000000..fcd54a0 --- /dev/null +++ b/src/Version/Git.hs @@ -0,0 +1,32 @@ +module Version.Git ( + tGitVersion, +) where + +import Language.Haskell.TH +import Language.Haskell.TH.Syntax +import Language.Haskell.TH.Syntax.Compat + +import System.Directory +import System.Exit +import System.Process + +tGitVersion :: SpliceQ (Maybe String) +tGitVersion = unsafeSpliceCoerce $ do + let git args = do + (ExitSuccess, out, _) <- readCreateProcessWithExitCode + (proc "git" $ [ "--git-dir=./.git", "--work-tree=." ] ++ args) "" + return $ lines out + + mbver <- runIO $ do + doesPathExist "./.git" >>= \case + False -> return Nothing + True -> do + desc:_ <- git [ "describe", "--always", "--dirty= (dirty)" ] + files <- git [ "ls-files" ] + return $ Just (desc, files) + + case mbver of + Just (_, files) -> mapM_ addDependentFile files + Nothing -> return () + + lift (fst <$> mbver :: Maybe String) -- cgit v1.2.3