views:

345

answers:

4

I'm busy automating our builds to include the svn revision number. We're using Delphi 2010. I added a pre-build event calling a batch file that injects the the svn revision number (read from the entries file in the .svn directory) and a specified version number into aVersionInfo.rc that is compiled with my project. The pre-build event looks like this:

call SetVersionInfo.bat 6 5 4

...and the batch file (hope someone finds this useful)...

@ECHO OFF
SETLOCAL
setLocal EnableDelayedExpansion

SET _myVar=0
FOR /F %%G in (.svn\entries.) DO (
IF !_myVar! LSS 3 SET /A _myVar+=1 & SET _svn_dir_rev=%%G
)

ECHO 1 VERSIONINFO > aVersionInfo.rc
ECHO. FILEVERSION %1,%2,%3,%_svn_dir_rev%   >> aVersionInfo.rc
ECHO. PRODUCTVERSION 1   >> aVersionInfo.rc
ECHO. FILEOS VOS__WINDOWS32   >> aVersionInfo.rc
ECHO. FILETYPE VFT_APP   >> aVersionInfo.rc
ECHO. BEGIN   >> aVersionInfo.rc
ECHO.   BLOCK "StringFileInfo"   >> aVersionInfo.rc
ECHO.   BEGIN   >> aVersionInfo.rc
ECHO.     BLOCK "080904b0"   >> aVersionInfo.rc
ECHO.     BEGIN   >> aVersionInfo.rc
ECHO.       VALUE "CompanyName","COMPANY\000"   >> aVersionInfo.rc
ECHO.       VALUE "FileDescription","APP\000"   >> aVersionInfo.rc
ECHO.       VALUE "FileVersion","%1.%2.%3.%_svn_dir_rev%\000"   >> aVersionInfo.rc
ECHO.       VALUE "InternalName","APP\000"   >> aVersionInfo.rc
ECHO.       VALUE "LegalCopyright","Copyright APP\000"   >> aVersionInfo.rc
ECHO.       VALUE "LegalTrademarks","APP\000"   >> aVersionInfo.rc
ECHO.       VALUE "OriginalFilename","APP.exe\000"   >> aVersionInfo.rc
ECHO.       VALUE "ProductName","APP\000"   >> aVersionInfo.rc
ECHO.       VALUE "ProductVersion,"1\000"   >> aVersionInfo.rc
ECHO.       VALUE "Comments","Compiled on %date% by %username%\000"   >> aVersionInfo.rc
ECHO.     END   >> aVersionInfo.rc
ECHO.   END   >> aVersionInfo.rc
ECHO.   BLOCK "VarFileInfo"   >> aVersionInfo.rc
ECHO.   BEGIN   >> aVersionInfo.rc
ECHO.     VALUE "Translation", 0x0809 1200   >> aVersionInfo.rc
ECHO.   END   >> aVersionInfo.rc
ECHO. END   >> aVersionInfo.rc
ENDLOCAL

The batch file does execute as part of a compile, aVersionInfo.rc is updated, aVersionInfo.res is recompiled, but for some reason the new res file is not used to compile the exe. It is, however, updated during a clean build or if I compile a second time. It seems the check for changes to the rc files takes place before the "pre"-build events are called. Which actually makes it a mid-build event. Or am I missing something?

I did try deleting the aVersionInfo.res file as another pre-build event, but then the compiler complains that this file is missing. Could it be that the

{$R 'aVersionInfo.res' 'aVersionInfo.rc'}

line is in the wrong place?

+1  A: 
Luca Guzzon
Sorry, my mistake: The " is included in the original, it just got lost when I removed company specific info. Well done for spotting it though!
Jaco Briers
+3  A: 

Try using

{$R aVersionInfo.res}

and calling brcc32 aVersionInfo.rc manually from your batch file (after you're done with creating the .rc file). That way your .res file should be excluded from the normal IDE build.

TOndrej
Thanks, works like a charm
Jaco Briers
+1  A: 

Add a line to your batch file that modifies the Delphi source file that includes the resource:

touch VersionInfo.pas

Then the source file should get recompiled. If the source file isn't modified, then there's no reason for the compiler to re-link that portion of the program, and so the updated resource file won't be noticed.

Rob Kennedy
The resource is included in my .dpr file. If I touch the dpr file it only picks up the change after the compile and two messages pop up asking if I want to reload the .dproj file and .rc file. The version info from the old res file is still used.
Jaco Briers
A: 

You could call brcc32 inside the batch file so it will always update the .res file. I do something similar and it works in a compile as well as a build.

dummzeuch