www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Passing revision tag to the compiler

reply Leandro Motta Barros <lmb stackedboxes.org> writes:
Hello,

I'd like to include the version control revision tag in a program. In
the C/C++ world I'd make my build system call the compiler like this:

   g++ -D<MY_REVISION_HERE> .....

so that the revision is available as a preprocessor symbol.

Is there an easy way to achieve the same in D? I can think of
convoluted solutions, like making the build system generate a .d file
containing a constant with the revision tag, but I'd naturally prefer
a simpler solution.

I am using DMD, but a solution that works for other D compilers gets
extra credit :-)

Thanks!

LMB
Mar 30 2013
next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
Leandro Motta Barros:

 I'd like to include the version control revision tag in a 
 program. In
 the C/C++ world I'd make my build system call the compiler like 
 this:

    g++ -D<MY_REVISION_HERE> .....
Take a look at -version=... Bye, bearophile
Mar 30 2013
prev sibling parent reply "Tobias Pankrath" <tobias pankrath.net> writes:
On Sunday, 31 March 2013 at 02:00:46 UTC, Leandro Motta Barros 
wrote:
 Hello,

 I'd like to include the version control revision tag in a 
 program. In
 the C/C++ world I'd make my build system call the compiler like 
 this:

    g++ -D<MY_REVISION_HERE> .....
D has no preprocessor and no way to define global variables via a cmdline switch. The -version switch can be used conditionally compile in blocks of code but wont help you to "import" a value into your program. You can however use import expressions for this. See http://dlang.org/expression.html search import expression. --- immutable Revision = import("revision.data"); --- And tell your VCS to always keep the revision in that file. DMD looks for imports in directories specified by the -J option.
Mar 31 2013
parent Leandro Motta Barros <lmb stackedboxes.org> writes:
On Sun, Mar 31, 2013 at 10:09 AM, Tobias Pankrath <tobias pankrath.net> wrote:
 On Sunday, 31 March 2013 at 02:00:46 UTC, Leandro Motta Barros wrote:
 Hello,


 I'd like to include the version control revision tag in a program. In
 the C/C++ world I'd make my build system call the compiler like this:

    g++ -D<MY_REVISION_HERE> .....
D has no preprocessor and no way to define global variables via a cmdline switch. The -version switch can be used conditionally compile in blocks of code but wont help you to "import" a value into your program. You can however use import expressions for this. See http://dlang.org/expression.html search import expression. --- immutable Revision = import("revision.data"); --- And tell your VCS to always keep the revision in that file. DMD looks for imports in directories specified by the -J option.
Hello Tobias, I have (miss)used import expressions before, but I forgot I could use them here. Thanks a lot! LMB
Mar 31 2013