December 27, 2013 Re: getting __DIR__ and __TIME__ of compilation? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Friday, 27 December 2013 at 15:15:31 UTC, Jacob Carlborg wrote:
> You can use this ugly hack:
>
> Create a shell script with the following content.
>
> #!/bin/bash
> echo `pwd` > dir.txt
> dmd main.d -J.
>
> And the D source code:
>
> module main;
>
> enum compilePath = import("dir.txt");
> pragma(msg, compilePath);
>
> Run the shell script to compile the D code.
I end up using something similar to your 'hack',
made a tiny wrapper in D that accepts the parameters that is supposed to go to dmd, get the absolute path of the compiled sourcecode using std.path.absolutePath(), save it inside a new <stuffs>.d file, the wrapper then calls the dmd compiler with <stuffs>.d added to the list of compiled files.
Bit of a stretch, but it'll do for now.
-Ravn-
|
December 27, 2013 Re: getting __DIR__ and __TIME__ of compilation? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ravn | On 2013-12-27 19:14, Ravn wrote: > I need the absolute path __FILE__ during compile time, > so far the only way I know to get absolute paths is by using > std.path.absolutePath (which uses getcwd() as its base) and getcwd() > itself (which doesn't seem to work during compile time). > > Is there any alternative on how to get the absolute path for a file > during compile time besides using these functions? __FILE__ will return the full path (absolute path) of the file currently compiling. But that is not the same thing as getting the path to where the compilation was made. I would guess you could use __FILE__ with dirName, but that currently does not compile. -- /Jacob Carlborg |
December 27, 2013 Re: getting __DIR__ and __TIME__ of compilation? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Friday, 27 December 2013 at 19:35:23 UTC, Jacob Carlborg wrote: > On 2013-12-27 19:14, Ravn wrote: > __FILE__ will return the full path (absolute path) of the file currently compiling. But that is not the same thing as getting the path to where the compilation was made. Eh, it does? :-? It prints a relative path when I used writeln(__FILE__), I'm on windows 7. On Friday, 27 December 2013 at 19:35:23 UTC, Jacob Carlborg wrote: > On 2013-12-27 19:14, Ravn wrote: > I would guess you could use __FILE__ with dirName, but that currently does not compile. Tried enum path = dirName(__FILE__), compiles normally, no error from the compiler, but it still returns a relative path instead of a fullpath in my machine. |
December 28, 2013 Re: getting __DIR__ and __TIME__ of compilation? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ravn | Am Fri, 27 Dec 2013 20:14:00 +0000 schrieb "Ravn" <ravndust@gmail.com>: > Tried enum path = dirName(__FILE__), compiles normally, no error from the compiler, but it still returns a relative path instead of a fullpath in my machine. Too bad :-/ I hoped it would use absolute paths. -- Marco |
December 28, 2013 Re: getting __DIR__ and __TIME__ of compilation? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ravn | On 2013-12-27 21:14, Ravn wrote: > Eh, it does? :-? > It prints a relative path when I used writeln(__FILE__), I'm on windows 7. Hmm, ok. It prints the full path when I run it via my text editor. But it prints the relative path when I run it via the command line. > Tried enum path = dirName(__FILE__), compiles normally, no error from > the compiler, but it still returns a relative path instead of a fullpath > in my machine. Yes, same here, don't know why it didn't compile the first time I tried it. Perhaps this deserves an enhancement request. I really though __FILE__ would give the full path. -- /Jacob Carlborg |
Copyright © 1999-2021 by the D Language Foundation