www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Define enum value at compile time via compiler argument?

reply Thomas Mader <thomas.mader gmail.com> writes:
Hello,

I would like to set the path to a directory at compile time but 
it doesn't seem to be possible yet.

I tried it with a -version=CustomPath argument and inside the 
version statement in the code I tried to read the value from the 
environment. Sadly this doesn't work because getenv can not be 
interpreted at compile time because it has no available source.

Now my question is if this is somehow possible and I just don't 
see it or would it be possible to add that somehow?

Thanks in advance.

Thomas
Dec 25 2017
parent reply Mengu <mengukagan gmail.com> writes:
On Monday, 25 December 2017 at 16:13:48 UTC, Thomas Mader wrote:
 Hello,

 I would like to set the path to a directory at compile time but 
 it doesn't seem to be possible yet.

 I tried it with a -version=CustomPath argument and inside the 
 version statement in the code I tried to read the value from 
 the environment. Sadly this doesn't work because getenv can not 
 be interpreted at compile time because it has no available 
 source.

 Now my question is if this is somehow possible and I just don't 
 see it or would it be possible to add that somehow?

 Thanks in advance.

 Thomas
is it a relative path? if so: pragma(msg, __FILE_FULL_PATH__.split("/")[0..$-1].join("/")); https://run.dlang.io/is/gRUAD6
Dec 25 2017
parent reply Thomas Mader <thomas.mader gmail.com> writes:
On Monday, 25 December 2017 at 16:22:11 UTC, Mengu wrote:
 is it a relative path? if so:

     pragma(msg, 
 __FILE_FULL_PATH__.split("/")[0..$-1].join("/"));


 https://run.dlang.io/is/gRUAD6
Nice idea but it is an absolute path. :-/
Dec 25 2017
parent reply aliak <something something.com> writes:
On Monday, 25 December 2017 at 16:38:32 UTC, Thomas Mader wrote:
 On Monday, 25 December 2017 at 16:22:11 UTC, Mengu wrote:
 is it a relative path? if so:

     pragma(msg, 
 __FILE_FULL_PATH__.split("/")[0..$-1].join("/"));


 https://run.dlang.io/is/gRUAD6
Nice idea but it is an absolute path. :-/
Can you use the -J compiler flag to define a string import file? Then you can: string data = import("file.txt");
Dec 25 2017
parent Thomas Mader <thomas.mader gmail.com> writes:
On Monday, 25 December 2017 at 17:46:05 UTC, aliak wrote:
 On Monday, 25 December 2017 at 16:38:32 UTC, Thomas Mader wrote:
 On Monday, 25 December 2017 at 16:22:11 UTC, Mengu wrote:
 is it a relative path? if so:

     pragma(msg, 
 __FILE_FULL_PATH__.split("/")[0..$-1].join("/"));


 https://run.dlang.io/is/gRUAD6
Nice idea but it is an absolute path. :-/
Can you use the -J compiler flag to define a string import file? Then you can: string data = import("file.txt");
A little complicated but it works. Thank you guys for your help.
Dec 25 2017