diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2023-03-01 21:51:24 +0100 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2023-03-01 21:51:24 +0100 |
commit | df1cc5d142e8d0e332341b82eb581e77c328f687 (patch) | |
tree | 218aad7a946574b794a4658c36dbef59019e1c29 /src/Version | |
parent | 8f4bb4eddb4dabf20a9256d406a1b9823a54879b (diff) |
Version information from git
Diffstat (limited to 'src/Version')
-rw-r--r-- | src/Version/Git.hs | 32 |
1 files changed, 32 insertions, 0 deletions
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) |