Passing revision tag to the compiler

Tobias Pankrath tobias at pankrath.net
Sun Mar 31 06:09:46 PDT 2013


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.


More information about the Digitalmars-d-learn mailing list