Thread overview
Define enum value at compile time via compiler argument?
Dec 25
Mengu
Dec 25
aliak
December 25
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

December 25
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
December 25
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. :-/
December 25
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");


December 25
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.