[Lazarus] embed git version info

Graeme Geldenhuys graeme at geldenhuys.co.uk
Wed Mar 27 16:26:07 CET 2013


On 2013-03-27 14:18, Xiangrong Fang wrote:
> 
> I realized that this may not work for me. Because I need to compile the
> project under both Linux and Windows, and then I need 2 scripts in the same
> place :-(

Yeah, compared to MSEide, Lazarus project build settings are a bit
historic or limited.

To get around problems with scripts vs batch files for cross-platform
use, I found it is better to implement my "scripts" as FPC console
applications. Then simply execute the console application where I would
have used a script. I found that creating such console apps are actually
a lot more powerful that batch files or bash scripts, because I have
full use of the Free Pascal RTL, FCL and whatever else I need.


> Anyway, I tested with the simplest pre-build script:
> 
> git describe --always > REVISION.INC

If you run the 'git describe' from the command line, you would see the
output is simply the "version information" (no constant definition or
string quotes). So you need to place it in your source code with an
identifier as the Pascal language requires. So you need to do something
like the following in your code.

const
  cGitRevision = '{$revision.inc}';


Then in your program, use the constant instead.

  msgs.Lines.Add('GIT HASH: ' + cGitRevision);



Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/





More information about the Lazarus mailing list