Getting the subversion repository number into code

前端 未结 6 378
醉梦人生
醉梦人生 2020-11-30 01:24

I\'d like to implement a way of recording the version of a project within code, so that it can be used when testing and to help track bugs. It seems the best version number

6条回答
  •  独厮守ぢ
    2020-11-30 01:30

    Two ways:

    Embed $Id$ or $Revision$ within the code. Then set svn:keywords="Id Revision" property on the file. This will give you the last modified revision of that source file. Good for smaller projects and scripts.

    Alternatively, use a Makefile driven process and the command line tool svnversion. (Language specific - this should work for C/C++)

    echo -n "#define VERSION 1.0.1-" > version.h
    svnversion -n . >> version.h
    

    Or some more complex build script with sed and version.h.in. Then just #include version.h

    That will give you the repository version number, which will change with every commit / update, and is probably a more appropriate version number for most projects.

    Note: I also used a human readable version string that I manually update. The example would give: Version: 1.0.1-r13445

    ~J

提交回复
热议问题