开发者

Automatic version numbering

开发者 https://www.devze.com 2023-01-29 06:59 出处:网络
I\'m adding a functionality to my executable to run it with --version argument. The project is very big and uses multiple classes. I开发者_运维问答\'d like to print out the versions of all of the clas

I'm adding a functionality to my executable to run it with --version argument. The project is very big and uses multiple classes. I开发者_运维问答'd like to print out the versions of all of the classes.

Right now each of my classes has a function static void print_info() { cout << "information here" << endl; } and the file with a main() calls print_info of each class.

Question: Is there a way to upkeep the version number automatically with changes?

Additional information: I and my team use NetBeans for development. We also use Subversion (svn) and I know that it keeps revision numbers. Problem is only tangently related to the revision number. I want to be able to distribute an executable that will print the version number without accessing subversion server.

I'll be glad to provide more information if this is somewhat vague. Thanks!

P.S. I don't care what the version value is. Weather is an arbitrary number generated by NetBeans, or the corresponding subversion revision number, or just the date when the last modification was made.


You could use a subversion Revision property on the source file which activates the $Revision$ keyword substitution within the file.

string version = "$Revision:$";

http://svnbook.red-bean.com/en/1.4/svn.advanced.props.special.keywords.html


First off, I recommend you do something other than your print_info() approach, since it's not very flexible - what if you want to actually use the version rather than simple print it to STDOUT, or what if you wish to report the version in an error message to STDERR? A static method returning a const char string would be more versatile.

Regarding the choice of version number, you can certainly use SVN keywords, which can be substituted into the body of your code. For instance (following one the examples given in the link provided), if you have the line

char[] versionString = "commit revision $Rev$";

and have enable the corresponding keyword substitution svn propset svn:keywords "Rev" file.cpp, the next time you perform an update your SVN client will update the text to something like

char[] versionString = "commit revision $Rev: 12 $";

and the next time you commit it the string will be overwritten to the new correct string, such as

char[] versionString = "commit revision $Rev: 13 $";

If you use SVN well you should be branching and tagging, in which case the branch and tag info (which form part of $URL$ keyword) are useful things to include in your version string. $Revision$ is also useful for giving you a value that changes between updates. Remember, though, that keywords are only updated when you perform an update (checkout, commit, etc.). If you make changes to your code and then compile it, the reported $Revision$ will be the same as when you originally checked out the code. As far as I know, the only way to avoid being caught out by this is to adopt a procedure of performing a commit of your code before compiling a new release of you software - this works well if you combine it with a process of tagging releases within SVN.


If you want to do that like that I would go for a #define at the begging of each source file and update it with a last-modification date of a file (either using $Date:$ or updating this with your own script). You can then use the defined constant in print_info() very easily.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号