Skip to content

Commit

Permalink
Fix Issue 11997 - rdmd should search it's binary path for the compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
joakim-noah committed Jul 16, 2017
1 parent e7df171 commit f7e6f4e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
13 changes: 13 additions & 0 deletions changelog/b11997.dd
Original file line number Diff line number Diff line change
@@ -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`).
6 changes: 6 additions & 0 deletions rdmd.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions rdmd_test.d
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f7e6f4e

Please sign in to comment.