Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
March 07, 2007 Finding the D compiler programatically. | ||||
---|---|---|---|---|
| ||||
My program needs to call DMD / GDC to compile a generated class. So, how can I find where the user installed it's dmd.exe / gdc on windows and linux? Right now I'm checking the following paths to see if it exists: C:\dmd\bin\dmd.exe C:\Program Files\dmd\bin\dmd.exe any folder in %PATH% and similar algorithm for GDC on linux but it doesn't seems like a very good idea to check all those paths. Is there a better way? Thanks. |
March 07, 2007 Re: Finding the D compiler programatically. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nathan Petrelli | Nathan Petrelli wrote:
> My program needs to call DMD / GDC to compile a generated class. So, how can I find where the user installed it's dmd.exe / gdc on windows and linux?
>
> Right now I'm checking the following paths to see if it exists:
>
> C:\dmd\bin\dmd.exe
> C:\Program Files\dmd\bin\dmd.exe
> any folder in %PATH%
>
> and similar algorithm for GDC on linux but it doesn't seems like a very good idea to check all those paths.
>
> Is there a better way?
>
> Thanks.
>
I think searching path on windows is a good idea, you could do the same on linux, or 'which dmd' should report it ?
Charlie
|
March 07, 2007 Re: Finding the D compiler programatically. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nathan Petrelli | Searching %PATH% is your only option, but even that theoretically doesn't suffice, for all you know, the user could have his dmd renamed to dlang.exe dcomp.exe or something not even remotely related to d, like euiDEfpD3dW.exe :)
or, maybe dmd.exe isn't even in %PATH%; maybe the user has a python script that he invokes to compile his projects (in this case, the script will be the one that knows the real path to dmd).
Nathan Petrelli wrote:
> My program needs to call DMD / GDC to compile a generated class. So, how can I find where the user installed it's dmd.exe / gdc on windows and linux?
>
> Right now I'm checking the following paths to see if it exists:
>
> C:\dmd\bin\dmd.exe
> C:\Program Files\dmd\bin\dmd.exe
> any folder in %PATH%
>
> and similar algorithm for GDC on linux but it doesn't seems like a very good idea to check all those paths.
>
> Is there a better way?
>
> Thanks.
>
|
March 07, 2007 Re: Finding the D compiler programatically. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nathan Petrelli | Nathan Petrelli wrote:
> My program needs to call DMD / GDC to compile a generated class. So, how can I find where the user installed it's dmd.exe / gdc on windows and linux?
>
> Right now I'm checking the following paths to see if it exists:
>
> C:\dmd\bin\dmd.exe
> C:\Program Files\dmd\bin\dmd.exe
> any folder in %PATH%
>
> and similar algorithm for GDC on linux but it doesn't seems like a very good idea to check all those paths.
>
> Is there a better way?
>
> Thanks.
The standard method is to not look in hardcoded places, but instead in $PATH and then in the $DMD_HOME variable that your documentation publishes.
Andrei
|
March 07, 2007 Re: Finding the D compiler programatically. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu (See Website For Email) | Andrei Alexandrescu (See Website For Email) wrote:
> Nathan Petrelli wrote:
>> My program needs to call DMD / GDC to compile a generated class. So, how can I find where the user installed it's dmd.exe / gdc on windows and linux?
>>
>> Right now I'm checking the following paths to see if it exists:
>>
>> C:\dmd\bin\dmd.exe
>> C:\Program Files\dmd\bin\dmd.exe
>> any folder in %PATH%
>>
>> and similar algorithm for GDC on linux but it doesn't seems like a very good idea to check all those paths.
>>
>> Is there a better way?
>>
>> Thanks.
>
> The standard method is to not look in hardcoded places, but instead in $PATH and then in the $DMD_HOME variable that your documentation publishes.
Speaking of which, can we have a community consensus on what to call DMD_HOME (and what it should point to)?
I use DMDDIR currently and set it so that $DMDDIR\dmd\bin\dmd.exe works.
I think I started using ***DIR for environment variables at some point in the past because I saw other projects using it. I can't remember which now, but at least I think that's what Qt uses (QTDIR).
Anyway, I don't care what it is, as long as it's a community standard and I can badger anyone who uses a different environment variable.
--bb
|
Copyright © 1999-2021 by the D Language Foundation