Development version numbers

Posted on May 27, 2012, under Kapow Punch Clock, Programming

Now that I am switching to release branches I am finally going to also tackle something that has always bothered me but I’ve never taken the time to solve: the development source code has the same version number as the most recent release. I have always wanted it to be some sort of automated number, but I wasn’t sure what I wanted it to be. And I didn’t want to have to update it myself with every single commit.

At first I had wondered about a number that gets incremented every time you compile the project, but I quickly realized that was a pointless thing to track. I may build a project 5,000 times and have a huge build number, but someone else might download the source and compile it only twice. Same source code, different version number. That’s frankly pretty silly.

Instead, I got inspired by the idea of using the git revision ID. It is obviously unique for each commit, and it identifies the specific source code for everyone. Of course, you can’t embed the revision ID because it is a hash that is created of the source code that you’re trying to embed it in. A hash that contains itself? Impossible! Of course, all you have to do instead is simply ask git for the revision ID, and pass that as a definition to the compiler:

VERSION = $$system(git rev-parse --short HEAD)
DEFINES += VERSIONSTR=\\\"git.$${VERSION}\\\"

The source code also needs to make use of the new compiler definition:

QCoreApplication::setApplicationVersion(VERSIONSTR);

This means that I finally have an automated version number for the development source code. I’ve only updated Kapow so far, but I am going to make this change to all of my projects.

2 comments

LWC says:

May 28, 2012 at 5:21 am

Congrats! While on the subject of source code vs. official version, how about a daily/nightly build. Does your tracker allow something like this? This would allow beta tests without using a compiler.

Either that or clear instructions on how to use Qt’s compiler to quickly build the program.

What do you think?

Graeme says:

May 28, 2012 at 11:34 am

Git is a source tracker, not a build system. I have to compile the Mac and Windows releases myself, and there is unfortunately no way I have time for daily/nightly builds. The development source is also not intended for use in a production environment, and I make no promises that it won’t eat your data.

That said, it’s actually pretty easy to build my projects. I include an INSTALL file that tells you what to do. All you need is a C++ compiler, an implementation of make, and the Qt libraries and header files. I use MinGW for compiling my programs in Windows, and the Qt SDK to get Qt for Windows.

Categories