dtools-llvm/autodetect.diff
Михаил Страшун e827ef953c upgpkg: 2.072.1-1
2.072.1+ dtools - uses non-tagged commit because of important bug fixes tag misses
2016-12-05 18:40:43 +00:00

48 lines
1.4 KiB
Diff

diff --git a/rdmd.d b/rdmd.d
index bd82637..390d533 100644
--- a/rdmd.d
+++ b/rdmd.d
@@ -52,7 +52,32 @@ else version (LDC)
else
static assert(false, "Unknown compiler");
-private string compiler = defaultCompiler;
+private string compiler;
+
+void chooseCompiler(ref string compiler)
+{
+ import std.stdio;
+
+ // if compiler is set explicitly, don't interefer
+ // otherwise find one that exists in PATH
+ if (!compiler.length)
+ {
+ import std.process : executeShell;
+ auto compilers = [ defaultCompiler, "dmd", "ldmd2", "gdmd2", "ldmd", "gdmd" ];
+
+ foreach (candidate; compilers)
+ {
+ // dirty hack, no-arg dmd invocation will return 1
+ if (executeShell(candidate ~ "| grep Usage").status == 0)
+ {
+ compiler = candidate;
+ return;
+ }
+ }
+
+ throw new Exception("Couldn't find any D compiler");
+ }
+}
version(unittest) {} else
int main(string[] args)
@@ -153,6 +178,8 @@ int main(string[] args)
if (bailout) return 0;
if (dryRun) chatty = true; // dry-run implies chatty
+ chooseCompiler(compiler);
+
/* Only -of is supported because Make is very susceptible to file names, and
* it doesn't do a good job resolving them. One option would be to use
* std.path.buildNormalizedPath(), but some corner cases will break, so it