Skip to content

Commit

Permalink
Merge pull request dlang#443 from rikkimax/master
Browse files Browse the repository at this point in the history
Add environment arguments support to choosing compiler in rdmd. $RDMD_DMD

Signed-off-by: Vladimir Panteleev <[email protected]>
Signed-off-by: Nicholas Wilson <[email protected]>
Merged-on-behalf-of: Nicholas Wilson <[email protected]>
  • Loading branch information
dlang-bot authored Feb 23, 2022
2 parents c46aebf + d67cca6 commit ae7a611
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
3 changes: 3 additions & 0 deletions changelog/rdmd-environment-args.dd
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 6 additions & 0 deletions man/man1/rdmd.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 20 additions & 8 deletions rdmd.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -142,6 +135,7 @@ int main(string[] args)
string[] eval; // set by --eval
bool makeDepend;
string makeDepFile;

try
{
getopt(argsBeforeProgram,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ae7a611

Please sign in to comment.