On Wednesday, 10 July 2013 at 12:58:41 UTC, Iain Buclaw wrote:
On 10 July 2013 13:14, eles <e...@eles.com> wrote:
On Wednesday, 10 July 2013 at 12:03:06 UTC, eles wrote:
Quick and unportable (Linux-only) drop-in replacement:
Christ on a bike. What's wrong with:
import std.file;
import std.process : environment;
auto binpaths = environment.get("PATH");
foreach (path; binpaths.split(<delimiter>)
{
auto exe = path ~ <dirsep> ~ "gdc";
if (exists (exe)) {
// found
}
}
Almost nothing (just a bracket). So, to make Teoh's life easier:
diff --git a/gdmd.d b/gdmd.d
index 6607ce2..12c610f 100644
--- a/gdmd.d
+++ b/gdmd.d
@@ -141,13 +141,19 @@ string findScriptPath(string argv0)
/**
* Finds GDC.
*/
-string findGDC(string argv0)
+string findGDC()
{
- // FIXME: this does not work 100% of the time.
- auto c = match(baseName(argv0),
`^(.*-)?g?dmd(-.*)?$`).captures;
- auto targetPrefix = c[1];
- auto gdcDir = absolutePath(dirName(argv0));
- return buildNormalizedPath(gdcDir, targetPrefix ~ "gdc" ~
c[2]);
+ auto binpaths = environment.get("PATH");
+
+ foreach (path; binpaths.split(pathSeparator))
+ {
+ auto exe = path ~ dirSeparator ~ "gdc";
+ if (exists (exe)) {
+ return exe;
+ }
+ }
+
+ return "";
}
/**
@@ -262,7 +268,7 @@ Config init(string[] args)
{
auto cfg = new Config();
cfg.scriptPath = findScriptPath(args[0]);
- cfg.gdc = findGDC(args[0]);
+ cfg.gdc = findGDC();
cfg.linker = cfg.gdc;
readDmdConf(cfg);