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

Eugene Kirpichov ekirpichov at gmail.com
Wed Feb 22 09:43:57 CET 2012


Whoa, I didn't think about using Template Haskell here. Thanks.
Perhaps this should be abstracted into a library.

On Wed, Feb 22, 2012 at 12:40 PM, Michael Snoyman <michael at snoyman.com>wrote:

> I have a project at work that embeds the Mercurial version in the
> final executable. I use Template Haskell to call the hg executable and
> parse its output. Here's the relevant code snippet:
>
>            putStrLn $ "Mercurial commit: " ++ $(do
>                let getChangeset s =
>                        let (k, v') = break (== ':') s
>                            v = dropWhile isSpace $ drop 1 v'
>                         in if k == "changeset" then Just v else Nothing
>                res <- qRunIO $ readProcess "hg" ["heads"] ""
>                let cs = mapMaybe getChangeset $ lines res
>                lift $ case cs of
>                    x:_ -> x
>                    [] -> "unknown")
>
> On Wed, Feb 22, 2012 at 10:37 AM, Eugene Kirpichov <ekirpichov at gmail.com>
> wrote:
> > Thanks, this is exactly what I was looking for!
> >
> > I might look some more into exposing VCS tags too, however.
> >
> >
> > On Wed, Feb 22, 2012 at 12:25 PM, Roel van Dijk <vandijk.roel at gmail.com>
> > wrote:
> >>
> >> For each package "myPackage" Cabal generates a module containing,
> >> among other things, the package's version as a Haskell value:
> >>
> >> > import Paths_myPackage ( version )
> >> > import Data.Version  ( showVersion )
> >> > main = showVersion version
> >>
> >> See also "Accessing data files from package code" in
> >> http://www.haskell.org/cabal/users-guide/
> >>
> >> I do not now how to expose information from the VCS.
> >>
> >> 2012/2/22 Eugene Kirpichov <ekirpichov at gmail.com>:
> >> > Hi,
> >> >
> >> > 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.
> >> >
> >> > Can Cabal expose the version as a preprocessor macro by default, or
> do I
> >> > have to use Build-Type: Custom and add a preprocessing step of my own?
> >
> >
> >
> >
> > --
> > Eugene Kirpichov
> > Principal Engineer, Mirantis Inc. http://www.mirantis.com/
> > Editor, http://fprog.ru/
> >
> > _______________________________________________
> > Haskell-Cafe mailing list
> > Haskell-Cafe at haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
> >
>



-- 
Eugene Kirpichov
Principal Engineer, Mirantis Inc. http://www.mirantis.com/
Editor, http://fprog.ru/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120222/91152a5c/attachment.htm>


More information about the Haskell-Cafe mailing list