sunLoadingImage
whowedImag
decoration left 1
decoration left 2
transhome
transprojects
transgallery
transarticles
decoration rigth
English

Show/Hide search bar
black cat logo variable logo
[09 Nov 2012]

How to add revision number to source code?

For each release build of my previous projects I was manually updating special #define values in my source code. These defines contained actual version of application and date of release, and they were displayed during loading (on splash screen) and in About app dialog. I was using Subversion and was wondering if it's possible to automatically take revision number from working copy of my project and write it to file with defines (as usually I was forgeting to change version number for some buildsW).

After short search I have found a nice utility for Windows OS that can automatically create file with revision number and move it to my project. It's SubWCRev. SubWCRev is console application that can read status from Subversion working copy (development folder), substitute keywords in a template file and put processed template file to your project.

How to use SubWCRev.exe?

SubWCRev is very easy to use. It has following input arguments:

  • Path to working copy (file or folder)
  • Path to template file
  • Path of destination file (where to put result)
  • Other secondary arguments that allow to alert about not updated code, not commited code, partial update of working copy, etc.

    Call to utility can be like the following console command: SubWCRev "../workingCopy" "template.h" "../workingCopy/defines.h"

    SubWCRev can return errors. For example error "2" means: failed to find file or folder.

    Template file

    Template file can contain a lot of different keywords that will be substituted by SubWCRev. Here are most useful keywords:

  • $WCREV$ latest revision number from working copy folder or file.
  • $WCDATE$ date of the latest commit revision.
  • $WCMOD$ indicates if code contains local modifications (not commited changes).
  • $WCNOW$ current date of the system.
  • $WCRANGE$ range of revisions (if code contains different revisions)

    For example your template file can be like this (template.h): #define REVISION_FROM_SVN $
    #define DATE_OF_REVISION $

    After substitution it will be like this (../workingCopy/defines.h): #define REVISION_FROM_SVN 113
    #define DATE_OF_REVISION 2012/11/8 13:14:08

    You should commit SubWCRev.exe and template file, but generated defines.h must be marked as ignored. Otherwise with each new build it will treated as local modification.

    SubWCRev with Visual Studio

    You can use SubWCRev with Visual Studio in the following way: Create .bat file for automatic call of SubWCRev.exe (svn_reader.bat): SubWCRev.exe "../workingCopy" "template.h" "../workingCopy/defines.h"

    Then in Visual Studio add build event (Project > Properties > Build Events > Pre-Build Event -> Command line): cd "$(SolutionDir)/pathToSubWCRev/"
    svn_reader.bat

    SubWCRev with Qt

    Or you can use SubWCRev in QT. Add new build step:

  • Projects -> Build -> BuildSteps -> Add Build Step
  • In Command field specify path to SubWCRev.exe
  • And appropriate working directory (folder with SubWCRev, or another)
  • Move build step to higher position

    That's all. Now your projects will always contain actual version number.




  • Sun and Black Cat- Igor Dykhta (igor dykhta email) 2007-2014