PDA

View Full Version : How to Get SVN version code in qt pro file



Abel
6th May 2014, 10:39
Hi All,
I want to update the svn code automaticly when build my program by this way:
In my project's pro file, I add following code to get snv code, but it does not work.


SVNVERSION = $$system(svn info -r HEAD ../ | sed -n "/Revision/p" | sed "s/[^0-9]//g")
DEFINES += VER=$${SVNVERSION}


The define in the makefile is not correct:
-DVER=Revision: -DQT_DLL -DQT

I try the sed commad in command window, it works well:
D:\Aic\FirmwareServer\QtProject>svn info -r HEAD ../ | sed -n "/Revision/p" | se
d "s/[^0-9]//g"
471

Is there any suggestion to solve this problem?

anda_skoa
6th May 2014, 11:04
Have you tried putting the shell command sequence into a scrip and calling that script instead?

Cheers,
_

Abel
6th May 2014, 11:28
anda_skoa, thank you for your reply.
I try your idea. But the qmake return both command line and result of the bat file to me!
In my pro file:


SVNVERSION=$$system(GetSvnInfo.bat)
DEFINES += VER=$${SVNVERSION}


command line in the bat file:


svn info -r HEAD ../ | sed -n "/Revision/p" | sed "s/[^0-9]//g"


and output make file as bellow:
-DVER=D:\Aic\FirmwareServer\QtProject\Trunck\AICMon itor>svn -Dinfo -D-r -DHEAD -D../ -D| -Dsed -D-n -D"/Revision/p" -D| -Dsed -D"s/[^0-9]//g" -D474
474 is my svn number. But also get the command line of the bat file which I marked as red color.

anda_skoa
6th May 2014, 11:57
You write bat file which usually indicates a Windows batch execution file, while your content looks like Unix shell tools.

Are you sure the environment of the script is correct?

If you run the script file, does it work?

Cheers,
_

stampede
6th May 2014, 12:04
svn info -r HEAD ../ | sed -n "/Revision/p" | sed "s/[^0-9]//g"
As a side note, "svn info" displays information with (i think) system default locale, so this will work as long as you have english system.
On my system displayed text is in polish, and therefore it doesn't contain the word "Revision" - could be a problem if you have an autobuild server setup in another country ( it happened to me ). More reliable and general version could be to use the "xml" formatting:


svn info --xml

this will always output the info in english, and you can get the revision number via "revision=..." attribute.

Abel
7th May 2014, 03:28
Yes. the sed tools is installed in WIN-AVR2010 package.
So the script can work on windows platform.

ChrisW67
7th May 2014, 04:12
The "^" character has a special meaning to the Windows shell, roughly the same as the backslash escape in C++ or bash shell. It looks like it is being consumed with the result that the command being executed is this:


svn info -r HEAD ../ | sed -n "/Revision/p" | sed "s/[0-9]//g"

which gives the output you complain of by removing the digits. Try:


SVNVERSION = $$system(svn info -r HEAD ../ | sed -n "/Revision/p" | sed "s/[^^0-9]//g")
DEFINES += VER=$${SVNVERSION}
(which is only good on Windows).

Depending on the Subversion command line utilities you have to work with:


SVNVERSION = $$system(svnversion ../)

might also work for you.

If you are using TortoiseSVN then it is possible to script this using its exposed objects.

BTW: This will only extract the version when you run qmake, and not every time you build.

Abel
7th May 2014, 13:16
ChrisW67, Thank you!
It works!
I know it only get version number once by only run qmake once. I just need a version code for the auto building task to track issues, so it is enough for my task.
Also thank you for the svnversion command, it is easier to get version code than svn info + sed.

Added after 4 minutes:

--xml is another good ideal.