Extends the `defaultCompiler` selection s.t. custom defaults can be
selected at compile time via `-version=DefaultCompiler_XXX` (where `XXX`
is either `DMD`, `LDC` or `GDC`).
This allows the `rdmd` bundled with DMD to be built with LDC while still
defaulting to DMD.
By checking only `value[0]`, the `dashOh` callback used to parse `-o...`
flags would give false positives (e.g. for `-o-foo` or `-opbar`). This
patch fixes the discrepancy by requiring exact comparison to `value`.
A few test cases have been added to `rdmd_test` to cover these failures.
Thanks to @CyberShadow for spotting the bug and proposing the fix.
This fixes a discrepancy between `rdmd` and `dmd` in terms of the output
flags they support: `dmd` now requests `-of=...` and `-od=...` in help
output but still supports the old `-of...` and `-od...` style, while
`rdmd` was still supporting only the older variant.
Thanks to @CyberShadow for suggesting the `skipOver`-based solution.
Extra test cases have been added to `rdmd_test` to cover this, although
the way this has been done is a little bit cheeky (it turns out the only
place where `-of` and `-od` are really tested rigorously is in tests for
the case where the output file is a library in a subdirectory). At some
point it would be a good idea to add some more rigorous test cases for
the `-o...` flags, but in the short term the tests added in this patch
should validate the changes to `rdmd` itself.
File types are split into more than just directories and files. In this case, fullExe must be a regular file, so checking isFile removes any question about whether or not it is actually a file. The current implementation uses !isDir which could still be true even if fullExe is not a regular file, which is not the logic we want here.
This patch replaces the old ad-hoc generation of `--eval` or `--loop`
program code with calls to the new `makeEvalCode` function. Besides
improving separation of concerns, this also ensures that the generated
code will never have a trailing blank statement (i.e. two `;` separated
at most by whitespace). This should prevent issues when using `--eval`
or `--loop` with a `--compiler` choice that is fussy about such things;
see https://github.com/dlang/tools/pull/297#issuecomment-362447334 for
an example.
The `--eval` and `--loop` flags allow the user to specify small snippets
of code that are placed inside the body of an auto-generated `main` that
is written to a file and evaluated.
The existing implementation uses two separate string concatenations for
the two different cases. Besides the code duplication, this means that
the resulting code generation cannot be tested.
A further more subtle issue arises from the existing implementation's
insistence on adding a closing `;` to the generated code. While this
takes care of the careless user who forgets to write one themselves, it
means that if the user does close their statements correctly, we end up
with an empty statement on the end of the code to be evaluated. While
some D compilers don't care about this, some object:
https://github.com/dlang/tools/pull/297#issuecomment-362447334
... meaning that `rdmd` will fail to successfully evaluate the code.
This patch therefore implements two new code functions to generate the
required code. The first, `innerEvalCode`, takes care of the innermost
code (the body of either the `main` function for `--eval`, or the loop
for `--loop`), adding a terminating `;` if one is not present, but not
doing so if one is already in place.
The second, `makeEvalCode`, takes two parameters: the `string[]` of code
snippets to be evaluated, and a boolean `Flag` indicating whether or not
this is the body of a loop (in other words, whether this code should be
generated for the `--eval` flag or the `--loop` flag).
Unittests have been provided with both to ensure that they produce the
expected outcomes.
Note, this doesn't affect linux, only windows. The problem is that the inner/outer loops for searching for a program in the `which` function is in the wrong order. You should go through each PATH, in in each one search for a program matching every extension in PATHEXT.