diff --git a/changelog/rdmd-environment-args.dd b/changelog/rdmd-environment-args.dd new file mode 100644 index 0000000000..d224253f8a --- /dev/null +++ b/changelog/rdmd-environment-args.dd @@ -0,0 +1,3 @@ +rdmd now supports specifying the D compiler using the `RDMD_DMD` environment variable + +rdmd now uses the `RDMD_DMD` environment variable, if it is present in the environment, to choose the D compiler to use. As with the `--compiler` option, the variable's value must specify the name or path of a compiler with a DMD-like command line syntax, such as `gdmd` or `ldmd2`. The variable overrides the default (which is decided at the time `rdmd` was built), but can still be overridden by the `--compiler` option. \ No newline at end of file diff --git a/man/man1/rdmd.1 b/man/man1/rdmd.1 index 40fa117f68..96316a19e4 100644 --- a/man/man1/rdmd.1 +++ b/man/man1/rdmd.1 @@ -89,6 +89,12 @@ of the options. Specify directory to store cached program and other temporaries [default = as per \fIhttp://dlang.org/phobos/std_file.html#.tempDir\fR] +.SH ENVIRONMENT +.TP +.B RDMD_DMD +Specifies the D compiler to use, in the same way as \fB--compiler\fR, when \fB--compiler\fR is not specified. +.PP + .SH NOTES .B dmd or diff --git a/rdmd.d b/rdmd.d index 51df6ee7a0..f5567029a5 100755 --- a/rdmd.d +++ b/rdmd.d @@ -64,18 +64,11 @@ else version (LDC) private enum defaultCompiler = "ldmd2"; else static assert(false, "Unknown compiler"); - -private string compiler = defaultCompiler; +private string compiler = null; version(unittest) {} else int main(string[] 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 ~ binExt); - if (Filesystem.existsAsFile(compilerPath)) - compiler = compilerPath; - if (args.length > 1 && args[1].startsWith("--shebang ", "--shebang=")) { // multiple options wrapped in one @@ -142,6 +135,7 @@ int main(string[] args) string[] eval; // set by --eval bool makeDepend; string makeDepFile; + try { getopt(argsBeforeProgram, @@ -173,6 +167,24 @@ int main(string[] args) if (bailout) return 0; if (dryRun) chatty = true; // dry-run implies chatty + // If we don't have a known compiler specified by the user, + // then we need to look to see if it was specified via an environmental argument. + // We need to do this due to rdmd being used as the execution engine for shebang files. + // This was originally tested with both $DMD, and $DC variable support. + // It was removed due to the current test suites being fragile enough that it broke them. + if (!compiler) + compiler = environment.get("RDMD_DMD", null); + if (!compiler) + { + compiler = defaultCompiler; + + // 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()), compiler ~ binExt); + if (Filesystem.existsAsFile(compilerPath)) + compiler = compilerPath; + } + /* 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