From df1cc5d142e8d0e332341b82eb581e77c328f687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Wed, 1 Mar 2023 21:51:24 +0100 Subject: Version information from git --- src/Version/Git.hs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/Version/Git.hs (limited to 'src/Version') 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