[Lazarus] embed git version info

Lukasz Sokol el.es.cr at gmail.com
Wed Mar 27 16:05:18 CET 2013


On 27/03/2013 14:18, Xiangrong Fang wrote:
>     > How can I embed git version info AUTOMATICALLY while I compile my program
> 
>     > in lazarus, just like {$I %DATE%} ?
> 
>     Use a pre-compile script (Project Options|Compiler
>     Options|Compilation|Execute Before) in combination with a include file.
> 
> 
> Thanks.
> 
> 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 :-(
> 
> Anyway, I tested with the simplest pre-build script:
> 
> git describe --always > REVISION.INC
> 
> 
> Then in my program I added:
> 
> msgs.Lines.Add('GIT HASH: ' + {$I REVISION.INC});  
> 
> Unfortunately, it does not compile, the error I got is:
> 
> unit1.pas(831,50) Error: Identifier not found "c25d546"
> 
> It seems that this directive does not load the include file as simple string??
>  
> 
maybe have your script do :

echo "constgithashfrominc : string = \'" > REVISION.INC
git describe --always >> REVISION.INC
echo "\';" >> REVISION.INC

at the implementation section, under const directive do:

{$I REVISION.INC}

and then 

msgs.Lines.Add('Git HASH: '+constgithashfrominc);


(i.e. so that you are going to have
const githashfrominc : string = 'whatever';
)

Or have it as resource string (it was mentioned on this list once upon a time).

L.






More information about the Lazarus mailing list