Automatic version numbering

I am adding functionality for my executable to run it with the -version argument. The project is very large and uses several classes. I would like to print versions of all classes.

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

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

Additional Information: My team and I use NetBeans for development. We also use Subversion (svn), and I know that it contains revision numbers. The problem is only indirectly related to the revision number. I want to be able to distribute an executable that will print the version number without access to the subversion server.

I will be happy to provide additional information if this is somewhat vague. Thank!

PS I don't care what the meaning of the version is. Weather is an arbitrary number generated by NetBeans, or the corresponding revision number of the jurisdiction, or simply the date when the last modification was made.

+3
source share
3 answers

Firstly, I recommend that you do something different than your approach print_info(), since it is not very flexible - that if you want to actually use the version, and not just print it in STDOUT, or that if you want to tell the versions in a message error message for STDERR? The method staticreturning the string const char will be more universal.

, SVN, . ( ),

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

svn propset svn:keywords "Rev" file.cpp, SVN- -

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

, , ,

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

SVN, , ( $URL$) . $Revision$ , . , , (, ..). , $Revision$ , . , , - , SVN.

+1

subversion Revision, $Revision$ .

string version = "$Revision:$";

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

+3

If you want to do this, I would go on #definebegging each source file and update it with the date the file was last modified (using $ Date: $ or updating it using your own script). You can use a specific constant in print_info () very easily.

0
source

Source: https://habr.com/ru/post/1778438/


All Articles