FreeOrion

Forums for the FreeOrion project
It is currently Sat May 25, 2013 12:09 am

All times are UTC




Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Include SVN revision in Version.cpp?
PostPosted: Thu Jun 14, 2012 9:17 pm 
Offline
Space Floater
User avatar

Joined: Tue May 29, 2012 9:15 pm
Posts: 23
As ever, I don't know whether this has been tried in the past, apologies if so

Might it be possible/sensible to use the subversion
$Version: $
or similar keyword, to automatically include the current SVN repository version in the application window title?
I know its a pain remembering to update the version string manually at each significant commit
On the other hand its a pain maintaining and selecting between multiple built versions, when they all look the same when you fire them up

_________________
--Steaker--


Top
 Profile  
 
 Post subject: Re: Include SVN revision in Version.cpp?
PostPosted: Thu Jun 14, 2012 9:47 pm 
Offline
Programming, Design, and De Facto Lead
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 7898
Location: Vancouver, BC
Steaker wrote:
Might it be possible/sensible to use the subversion
$Version: $
or similar keyword...
I'm not aware of any such functionality provided by subversion, and it sounds like you aren't either...


Top
 Profile  
 
 Post subject: Re: Include SVN revision in Version.cpp?
PostPosted: Thu Jun 14, 2012 10:04 pm 
Offline
Space Floater
User avatar

Joined: Tue May 29, 2012 9:15 pm
Posts: 23
On the contrary, I know it can be done, I'm not exactly sure whether it could be easily achieved with the SF repository

http://stackoverflow.com/questions/9262 ... -code?lq=1

2nd answer refers on to
http://tortoisesvn.net/docs/release/Tor ... wcrev.html

which might be a decent alternative, all be it only for Tortoise users

_________________
--Steaker--


Top
 Profile  
 
 Post subject: Re: Include SVN revision in Version.cpp?
PostPosted: Thu Jun 14, 2012 11:00 pm 
Offline
Programming, Design, and De Facto Lead
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 7898
Location: Vancouver, BC
From my skim over it, there appears to be a mechanism for substituting in the last revision in which a particular file was itself modified, but not for the latest revision of the whole repository.


Top
 Profile  
 
 Post subject: Re: Include SVN revision in Version.cpp?
PostPosted: Thu Dec 13, 2012 1:48 am 
Offline
Space Krill

Joined: Thu Dec 13, 2012 1:14 am
Posts: 1
If you are using TortiseSVN and Visual Studio this is how I have set it up.

  1. Right-click on your project common
  2. Select Properties
  3. Click Build Events
  4. Click Pre-Build Event
  5. In the Configuration drop-down, select All Configurations
  6. In the Command Line field, enter:
    SubWCRev.exe $(SolutionDir).. $(ProjectDir)..\src\Version.template $(ProjectDir)..\src\Version.cpp
  7. In the Description field, add a comment such as:
    Generate SVN revision number

Create template Version.template in ...\FreeOrion\msvc2010\src folder
Code:
#include "../../util/Version.h"

namespace {
    static const std::string retval = "v0.4.1+ [SVN $WCREV$] MSVC 2010";
}

const std::string& FreeOrionVersionString()
{ return retval; }

Optional: add Version.cpp to Ingnore list.

Attached is patch with all these changes including adding the pre-build to the Common.vcxproj file.


Attachments:
File comment: Patch for Visual Studio automatic creation of SVN revison number using TortiseSVN SubWCRev.exe command
SVN Revision for VS.patch [1.94 KiB]
Downloaded 2 times
Top
 Profile  
 
 Post subject: Re: Include SVN revision in Version.cpp?
PostPosted: Sat Dec 15, 2012 9:03 pm 
Offline
Programming, Design, and De Facto Lead
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 7898
Location: Vancouver, BC
WonderDog wrote:
If you are using TortiseSVN and Visual Studio this is how I have set it up.
I don't what to do anything that requires a particular SVN client to work.


Top
 Profile  
 
 Post subject: Re: Include SVN revision in Version.cpp?
PostPosted: Wed Dec 26, 2012 10:58 am 
Offline
Programmer and Packager
User avatar

Joined: Wed Nov 16, 2011 12:56 pm
Posts: 769
Location: Sol III
Geoff the Medio wrote:
I don't what to do anything that requires a particular SVN client to work.
I've just implemented something very similar to WonderDog's suggestion for the Xcode project on OSX, using an extra build phase that runs a python script. This script utilizes the "svn info" command from the standard subversion command line client to get the revision of the working copy and a template file to generate a Version.cpp with the revision number inserted in the version string. Seems to work perfectly fine so far.

As the standard subversion command line tools are available for Windows, that should be doable on Windows in a similar way (instead of a python script you might want to use something else that's readily available on Windows). Maybe you're more comfortable with the standard SVN client...?


Top
 Profile  
 
 Post subject: Re: Include SVN revision in Version.cpp?
PostPosted: Wed Dec 26, 2012 3:50 pm 
Offline
Programming, Design, and De Facto Lead
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 7898
Location: Vancouver, BC
Vezzra wrote:
As the standard subversion command line tools are available for Windows, that should be doable on Windows in a similar way (instead of a python script you might want to use something else that's readily available on Windows.
I'm not sure how to reliably access the SVN command line programs on Windows. "svn info" doesn't work from cmd.exe with TortoiseSVN installed, and I don't want to require anything else (ie. command-line SVN or TortoiseSVN) be installed separately; it needs to work with just the compiler and SDK. If it could be set up to only do the SVN build step if SVN programs are installed, that would be acceptable, but I'm not sure how the custom build step stuff works in Visual C++ or how this specifically would be set up.


Top
 Profile  
 
 Post subject: Re: Include SVN revision in Version.cpp?
PostPosted: Wed Dec 26, 2012 5:28 pm 
Offline
Space Dragon
User avatar

Joined: Sun Sep 25, 2011 2:51 pm
Posts: 264
Geoff the Medio wrote:
I'm not sure how to reliably access the SVN command line programs on Windows. "svn info" doesn't work from cmd.exe with TortoiseSVN installed, and I don't want to require anything else (ie. command-line SVN or TortoiseSVN) be installed separately; it needs to work with just the compiler and SDK. If it could be set up to only do the SVN build step if SVN programs are installed, that would be acceptable, but I'm not sure how the custom build step stuff works in Visual C++ or how this specifically would be set up.

Yeah, installing Tortoise doesn't put it into PATH.

_________________
[...] for Man has earned his right to hold this planet against all comers, by virtue of occasionally producing someone totally batshit insane. - xkcd


Top
 Profile  
 
 Post subject: Re: Include SVN revision in Version.cpp?
PostPosted: Wed Dec 26, 2012 6:01 pm 
Offline
Programmer and Packager
User avatar

Joined: Wed Nov 16, 2011 12:56 pm
Posts: 769
Location: Sol III
Geoff the Medio wrote:
...it needs to work with just the compiler and SDK.
Unfortunately Windows doesn't come with Subversion preinstalled...
Quote:
If it could be set up to only do the SVN build step if SVN programs are installed, that would be acceptable
Hm, setting up a custom build step/phase launching a python script that takes care of all that would be a possibility, but then you need to install Python first, so we are back at square one... unless there is some other scripting system that ships with Windows that is capable of doing all that stuff.


Top
 Profile  
 
 Post subject: Re: Include SVN revision in Version.cpp?
PostPosted: Wed Dec 26, 2012 7:57 pm 
Offline
Programming, Design, and De Facto Lead
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 7898
Location: Vancouver, BC
Vezzra wrote:
unless there is some other scripting system that ships with Windows that is capable of doing all that stuff.
.bat files probably still work.


Top
 Profile  
 
 Post subject: Re: Include SVN revision in Version.cpp?
PostPosted: Thu Dec 27, 2012 2:53 pm 
Offline
Programmer and Packager
User avatar

Joined: Wed Nov 16, 2011 12:56 pm
Posts: 769
Location: Sol III
Geoff the Medio wrote:
Vezzra wrote:
unless there is some other scripting system that ships with Windows that is capable of doing all that stuff.
.bat files probably still work.
I'm not an expert when it comes to the scripting capabilities of the Windows command line shell, but AFAIK these capabilities are quite limited. To automatically update the SVN revision number in Version.cpp you need to be able to run the "svn info" command (no problem of course), capture and parse it's output to get the revision number, and finally read the contents of a file containing the template for Version.cpp, replace the placeholder string in this template with the revision number and save the result in Version.cpp. With Python that's a piece of cake.

AFAIK, with .bat files you'll already hit the wall when it comes to capturing the output of the "svn info" command, not to mention the other steps...


Top
 Profile  
 
 Post subject: Re: Include SVN revision in Version.cpp?
PostPosted: Thu Dec 27, 2012 10:14 pm 
Offline
Programmer
User avatar

Joined: Sat Sep 22, 2012 6:25 pm
Posts: 982
Vezzra wrote:
... but then you need to install Python first, so we are back at square one...
Maybe I'm not properly understanding the context here -- I would think that anyone looking to compile FO could be expected to install python.

_________________
If I provided any code here, it's released under GPL 2.0


Top
 Profile  
 
 Post subject: Re: Include SVN revision in Version.cpp?
PostPosted: Fri Dec 28, 2012 12:07 am 
Offline
Creative Contributor

Joined: Thu Aug 30, 2012 12:32 am
Posts: 419
Dilvish wrote:
Vezzra wrote:
... but then you need to install Python first, so we are back at square one...
Maybe I'm not properly understanding the context here -- I would think that anyone looking to compile FO could be expected to install python.


Boo Divlish!

:)

_________________
Code released under GPL 2.0. Content released under GPL 2.0 and Creative Commons Attribution-ShareAlike 3.0.


Top
 Profile  
 
 Post subject: Re: Include SVN revision in Version.cpp?
PostPosted: Fri Dec 28, 2012 3:40 pm 
Offline
Programmer and Packager
User avatar

Joined: Wed Nov 16, 2011 12:56 pm
Posts: 769
Location: Sol III
Dilvish wrote:
Vezzra wrote:
... but then you need to install Python first, so we are back at square one...
Maybe I'm not properly understanding the context here -- I would think that anyone looking to compile FO could be expected to install python.
Not necessarily. Python isn't required to build FO, and you don't even need a python installation on your computer to run it, because FO ships with it's own python package. This python package of course is included with the SDK, but it's not set up in a way you can use this python environment from within the MSVC IDE.

This problem can be solved by copying a proper python.exe into the project's root directory. You can then set up a custom build event that executes a python script using this python.exe. It will use the python package included with the FO SDK as it's execution context, so the entire python standard library is at your disposal. So in theory the only thing that needs to be done is include the python.exe for python 2.7.3 in the SDK, set up a proper python script and template for version.cpp and you're done.

BUT: I tried that, and the problem I ran into (with my extremly limited knowledge of the MSVC IDE) was that I failed to set up a custom build step or build event in a way that it was triggered every time you start the build process. What I came up with would only work when source files of the "Common" project (to which Version.cpp belongs) had been modified. As soon as you have a new revision that has no file modified that belong to the "Common" project, "Common" is considered up-to-date and it's not being rebuild (and with that no custom build steps or build events are triggered).

Adding the custom build step/event to the "FreeOrion" project was even worse, as it resulted in "Common" being built before any custom build steps/events for the "FreeOrion" project fired. I tried several things, but nothing worked. And I found no way to add execution of a custom script on the solution level, but that's exactly what would be required. Maybe someone more knowledgeable of the MSVC IDE can help with that.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group