summaryrefslogtreecommitdiff
path: root/main/Version
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2024-02-14 21:44:45 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2024-02-14 21:46:21 +0100
commit0ed3f76533cde17322cf04018713d70c2f78d490 (patch)
treeee54fc7b27502ac0b9faf2ba54be13408aff7643 /main/Version
parent8105c4ba4636c58b85f0235d2d1b53a0682b1a6a (diff)
Version information from git
Changelog: Added -V switch to show version
Diffstat (limited to 'main/Version')
-rw-r--r--main/Version/Git.hs31
1 files changed, 31 insertions, 0 deletions
diff --git a/main/Version/Git.hs b/main/Version/Git.hs
new file mode 100644
index 0000000..2aae6e3
--- /dev/null
+++ b/main/Version/Git.hs
@@ -0,0 +1,31 @@
+module Version.Git (
+ tGitVersion,
+) where
+
+import Language.Haskell.TH
+import Language.Haskell.TH.Syntax
+
+import System.Directory
+import System.Exit
+import System.Process
+
+tGitVersion :: Code Q (Maybe String)
+tGitVersion = unsafeCodeCoerce $ 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)