From f7e6f4ed925f6a8f97b4c0f02cfce2620489357a Mon Sep 17 00:00:00 2001 From: Joakim Date: Wed, 12 Jul 2017 14:44:19 +0530 Subject: [PATCH] Fix Issue 11997 - rdmd should search it's binary path for the compiler --- changelog/b11997.dd | 13 +++++++++++++ rdmd.d | 6 ++++++ rdmd_test.d | 10 ++++++++++ 3 files changed, 29 insertions(+) create mode 100644 changelog/b11997.dd diff --git a/changelog/b11997.dd b/changelog/b11997.dd new file mode 100644 index 0000000000..57a370cc49 --- /dev/null +++ b/changelog/b11997.dd @@ -0,0 +1,13 @@ +rdmd now checks for a D compiler binary in the directory it's in first + +If you downloaded a zip/tar file with the compiler before +and ran `rdmd`, it would invoke the D compiler from the system +`PATH` rather than the compiler right next to it, failing if +there wasn't one in the `PATH`. `rdmd` will now try to use +the D compiler next to it first, and only fall back to the +`PATH` if there isn't one adjacent. If you want rdmd to run a +specific compiler, add the `--compiler` flag to force it, as +always. + +To restore the old behaviour of only using the compiler from +your `PATH`, add `--compiler=dmd` (or `ldmd2` or `gdmd`). diff --git a/rdmd.d b/rdmd.d index af68846fdb..06f46d72a4 100755 --- a/rdmd.d +++ b/rdmd.d @@ -59,6 +59,12 @@ version(unittest) {} else int main(string[] args) { //writeln("Invoked with: ", args); + // Look for the D compiler rdmd invokes automatically in the same directory as rdmd + // and fall back to using the one in your path otherwise. + string compilerPath = buildPath(dirName(thisExePath()), defaultCompiler); + if (compilerPath.exists && compilerPath.isFile) + compiler = compilerPath; + if (args.length > 1 && args[1].startsWith("--shebang ", "--shebang=")) { // multiple options wrapped in one diff --git a/rdmd_test.d b/rdmd_test.d index 8cd2c65fe2..34bfa78ecf 100755 --- a/rdmd_test.d +++ b/rdmd_test.d @@ -310,6 +310,16 @@ void runTests() assert(res.status == -SIGSEGV, format("%s", res)); } + /* https://issues.dlang.org/show_bug.cgi?id=11997- rdmd should search its + binary path for the compiler */ + string localDMD = buildPath(tempDir(), baseName(compiler)); + std.file.write(localDMD, "empty shell"); + scope(exit) std.file.remove(localDMD); + + res = execute(rdmdApp ~ [modelSwitch, "--force", "--chatty", "--eval=writeln(`Compiler found.`);"]); + assert(res.status == 1, res.output); + assert(res.output.canFind(`spawn ["` ~ localDMD ~ `",`)); + /* -of doesn't append .exe on Windows: https://d.puremagic.com/issues/show_bug.cgi?id=12149 */ version (Windows)