www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Finding the D compiler programatically.

reply Nathan Petrelli <npetrelly klassmaster.com> writes:
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.
Mar 06 2007
next sibling parent Charlie <charlie.fats gmail.com> writes:
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
Mar 06 2007
prev sibling next sibling parent Hasan Aljudy <hasan.aljudy gmail.com> writes:
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.
 
Mar 06 2007
prev sibling parent reply "Andrei Alexandrescu (See Website For Email)" <SeeWebsiteForEmail erdani.org> writes:
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
Mar 06 2007
parent Bill Baxter <dnewsgroup billbaxter.com> writes:
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
Mar 06 2007