Commits

Yuri Bochkarev committed 78b1152

[*] implement correct way to show version during cabal build

  • Participants
  • Parent commits 86725ab

Comments (0)

Files changed (4)

 DEBUG_TARGET=imp.debug
 RELEASE_TARGET=imp.release
 TEST_TARGET=imp.tests
-GHC_OPTIONS=-odir ${O_DIR} -hidir ${HI_DIR} -i${SRC_DIR} -cpp
+DEFINES=-DGHC
+GHC_OPTIONS=-odir ${O_DIR} -hidir ${HI_DIR} -i${SRC_DIR} -cpp ${DEFINES}
 DEBUG_OPTIONS=-prof -auto-all -rtsopts=all -DIMAGEPASTE_DEBUG
 
 all: debug release
                        network,
                        mtl,
                        transformers,
+                       template-haskell,
 
                        regex-posix,
                        tagsoup,
                        HTTP,
-                       json
+                       json,
+
+                       vcs-revision
   
   hs-source-dirs:      src
 
     ("imm",      (EngineImm.config,      EngineImm.handler))]
 
 usage :: String
-usage = "imp v" ++ Version.version ++ " (changeset " ++ Version.changeset ++ ")"
+usage = "imp v" ++ Version.fullVersion
         ++ "\r\nusage: program [engine] <image-file>\r\nengines: "
         ++ Engine.engineNames engineConfigs
 
-module Version (version, changeset) where
+{-# LANGUAGE TemplateHaskell #-}
+module Version (fullVersion) where
+
+#ifdef GHC
+-- Makefile (ghc --make) build
+
+fullVersion = "0.2.0.0-alpha 119:86725ab7343e"
+
+#else
+-- cabal build
+
+import Distribution.VcsRevision.Mercurial
+import Language.Haskell.TH.Syntax
+import Paths_imagepaste (version)
+import Data.Version  (showVersion)
+
+main = showVersion version
+
+showHgVersion :: String
+showHgVersion = $(do
+    v <- qRunIO getRevision
+    lift $ case v of
+        Nothing            -> "<none>"
+        Just (hash, True)  -> hash ++ " (with local modifications)"
+        Just (hash, False) -> hash)
+
 
 -- | Version
 
-version = "0.2.0.0-alpha"
-changeset = "76a1f42e28a4+"
+fullVersion = (showVersion version) ++ " " ++ showHgVersion
+
+#endif
+-- GHC