I've read too many articles talking about subversion keywords and many other details like anchors and anchor signs, but none of them are talking c++.
I am using QT creator and I would like c++ to read the svn-version and pass it through my code as a value or string (or whatever data-type).
So, how can I do that?
How to get the output of system() command qt c++?
Like the accepted answer says, you can run the command through the system terminal using QProcess, wait for it to finish and then get the text of the command.
The text from the SVNBook is probably relevant here:
New users are often confused by how the $Rev$ keyword works. Since the repository has a single, globally increasing revision number, many people assume that it is this number that is reflected by the $Rev$ keyword's value. But $Rev$ expands to show the last revision in which the file changed, not the last revision to which it was updated. Understanding this clears the confusion, but frustration often remains—without the support of a Subversion keyword to do so, how can you automatically get the global revision number into your files?
To do this, you need external processing. Subversion ships with a tool called svnversion, which was designed for just this purpose. It crawls your working copy and generates as output the revision(s) it finds. You can use this program, plus some additional tooling, to embed that revision information into your files. For more information on svnversion, see the section called “svnversion”.
In my project we ended up not using svnversion, primarily because our source tree is huge and this command seemed to take an inordinate amount of time. But we did end up with something similar to get the revision number into our software. The configure script executes the following command
svn info . > svn_revision
This assumes the command is executed from a directory where that was checked out from the svn repository. To parse this data, I have a Makefile that greps various strings into constants
SVN_REV = $(shell cat svn_revision | grep "Last Changed Rev" | cut -f4 -d\ )
This is fed through a template file I call version.cc.template, there's a Makefile rule to turn it into a .cc file
version.cc: version.cc.template /svn_revision
sed -e "s/REVISION/$(SVN_REV)/" version.cc.template > $@
so I end up with something like this
version.h
namespace project {
extern const char* Revision;
extern const unsigned int SvnRevision;
}
version.cc
namespace project {
const char* Revision = "1234";
const unsigned int SvnRevision = 1234;
}
The version.cc file may not be needed in your case, the constants can be defined in the header as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With