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

后端 未结 2 1179
生来不讨喜
生来不讨喜 2020-12-20 16:48

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 (

相关标签:
2条回答
  • 2020-12-20 17:41

    We use a macro for this

    #define CVS(a) static const volatile char *rcsid = a;
    
    ....
    CVS("$Id$")
    

    CVS automagically expands $Id$. I assume this is what mercurial tags work as well.

    Then we can use the strings command to find the exact version of each file in the executable / library etc.

    You could use something similar.

    static const volatile char *rcsid = "$Id"; //or whatever mercurial tag you want
    
    int main() {
    
        .....
        std::cout << "Version is " << rcsid << std::endl;
    }
    
    0 讨论(0)
  • 2020-12-20 17:43

    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.

    0 讨论(0)
提交回复
热议问题