如果一个可执行文件能输出版本信息,会带来非常大的便利,本文就是介绍一种自动添加svn版本信息的方法。
Svn keywords可以实现自动更新,比如ID, Version, Author等,可以利用这些svn关键词来实现。主要的keywords如下所示:
svn:keywords - Keywords to be expanded. Valid keywords are:
URL,HeadURL - The URL for the head version of the object.
Author, LastChangedBy - The last person to modify the file.
Date, LastChangedDate - The date/time the object was lastmodified.
Rev, Revision, -The last revision the object changed.
LastChangedRevision - last revision
Id - A compressed summary of the previous 4 keywords.
Header - Similar to Id but includes the full URL.
我在自己机器上试了一下,好像并非上述的每个关键词都能工作。
首先在.subversion/config文件中添加以下信息
enable-auto-props = yes
[auto-props]
* = svn:keywords=Rev Author URL Date LastChangedRevision Id Header
我们可以这么实现,比如新建一个文件叫Conifg.h,内容如下
string version = "
$Rev$: Revision of last commit
$Author$: Author of last commit";
Svn check in以后会自动更新成如下内容:
$Rev:8466 $: Revision of last commit
$Author:zhangle $: Author of last commit
这样我们就可以把它include到main.cpp文件中,每次提交代码后就可以自动生成你指定的信息。代码中可以解析该string,获取当前的版本信息。
现在还有一个问题是需要Conifg.h的内容发生改变时,关键词才能自动扩展,所以还需要思考以下如何才能更加自动化。
————————————————
版权声明:本文为CSDN博主「zhanglehes」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zhanglehes/article/details/38065097