Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I embed Mercurial tags into my C/C++ code?

I would like to know if there is a way to embed Mercurial tags into my C/C++ code.

Basically I would like the tag string, which will end up being a release number (major.minor.rev), to be automatically inserted in a determined location of my C code as a static string.

The overall objective is that the application could be queried about its version number when executed with say a '-v' command line argument. Any alternative approach that doesn't involve trying to embed a Mercurial tag will be also welcomed as an answer.

I am using Code::Blocks on a Linux environment, so the solution can not rely on Visual Studio features.

like image 382
Diego10 Avatar asked Feb 12 '10 18:02

Diego10


1 Answers

You will need the keyword extension to allow expansion of keyword entries, it is bundled with mercurial.

For instance to get support for $Id$ you could edit hgrc for you repo (.hg/hgrc) and add:

[extensions]
keyword =

[keyword]
# Enable expansion for the specific files
myfile.cpp =
# Enable for all .h files
**.h =

Then run

hg kwexpand

to expand keywords the relevant files, or

hg kwshrink

to shrink keywords. You can even create your own keywords by adding the [keywordmaps] entry, e.g.

[keywordmaps]
User = {author|user}

Note: This disables the builtin keywords

More details on the extension can be found in the wiki.

like image 180
amos Avatar answered Sep 20 '22 23:09

amos