[Haskell-cafe] Inject cabal version or VCS version as a CPP macro

Herbert Valerio Riedel hvr at gnu.org
Wed Feb 22 11:57:44 CET 2012

Eugene Kirpichov <ekirpichov at gmail.com> writes:

> It can be used like this:
> {-# LANGUAGE TemplateHaskell #-}
>  import Distribution.VcsRevision.Git
>  import Language.Haskell.TH.Syntax
>  showMyGitVersion :: String
>  showMyGitVersion = $(do
>    v <- qRunIO getRevision
>    lift $ case v of
>      Nothing           -> "<none>"
>      Just (hash,True)  -> hash ++ " (with local modifications)"
>      Just (hash,False) -> hash)

Btw, I'm wondering (haven't tried myself), when using TH to generate the
version string, does GHC's and/or cabal's dependency tracking

 a) reliably refresh the generated hash so that you can be sure it's
    the git-commit id compiled into the binary is reliable, and

 b) avoid re-generating the TH file and redundant recompilation if the
    git commit-id hasn't changed?


More information about the Haskell-Cafe mailing list