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

Herbert Valerio Riedel hvr at gnu.org
Wed Feb 22 11:26:45 CET 2012


Eugene Kirpichov <ekirpichov at gmail.com> writes:

> I'd like my program to print something like "this is $program 1.0.4 git
> 45fea6b" when invoked with --version, or at least just the 1.0.4 part.

Here's some proof-of-concept code we use slightly modified in production
here for over a year now successfully:


The primary goal was to have a reliable version number (allowing to find
the exact corresponding git-commit in the source-code repository), and
to be able to detect when that version number is unreliable (there's
nothing more annoying than wasting time debugging the wrong

The idea is to dynamically infer and overwrite cabal's version when
building from the git repository, and have it accessible via the cabal's
auto-generated "Paths_<pkg-name>" module Data.Version...

...and when creating a source-dist, via "runghc Setup.hs sdist" the
current dynamic git-version string is embedded into the generated
.tar.gz's .cabal file, so that the source-distribution is just a plain
simple .cabal project (that could be uploaded to hackage)


More information about the Haskell-Cafe mailing list