rdmd: support --eval <arg> to make it Makefile friendly

This commit is contained in:
Superstar64 2018-03-19 06:53:39 -04:00 committed by Sebastian Wilzbach
parent 9d414d2e30
commit e88c44d181
4 changed files with 49 additions and 5 deletions

View file

@ -0,0 +1,12 @@
rdmd can now be used as a shell in makefiles
With gnu make(3.82 or higher), rdmd can now be used in makefiles.
This is accomplished by setting the SHELL and .SHELLFLAGS to /usr/bin/rdmd and --eval respectively.
---
.ONESHELL:
SHELL = /usr/bin/rdmd
.SHELLFLAGS = --eval
hello.txt:
$(TAB)import std.file;
$(TAB)write("$@","hello world\n");
---

8
rdmd.d
View file

@ -329,12 +329,14 @@ int main(string[] args)
size_t indexOfProgram(string[] args)
{
foreach(i, arg; args[1 .. $])
foreach(i; 1 .. args.length)
{
auto arg = args[i];
if (!arg.startsWith('-', '@') &&
!arg.endsWith(".obj", ".o", ".lib", ".a", ".def", ".map", ".res"))
!arg.endsWith(".obj", ".o", ".lib", ".a", ".def", ".map", ".res") &&
args[i - 1] != "--eval")
{
return i + 1;
return i;
}
}

View file

@ -614,6 +614,29 @@ void runTests(string rdmdApp, string compiler, string model)
res = execute(rdmdArgs ~ [src1]);
assert(res.status == 1, res.output);
}
{
import std.format : format;
auto textOutput = tempDir().buildPath("rdmd_makefile_test.txt");
if (exists(textOutput))
{
remove(textOutput);
}
enum makefileFormatter = `.ONESHELL:
SHELL = %s
.SHELLFLAGS = %-(%s %) --eval
%s:
import std.file;
write("$@","hello world\n");`;
string makefileString = format!makefileFormatter(rdmdArgs[0], rdmdArgs[1 .. $], textOutput);
auto makefilePath = tempDir().buildPath("rdmd_makefile_test.mak");
std.file.write(makefilePath, makefileString);
auto make = environment.get("MAKE") is null ? "make" : environment.get("MAKE");
res = execute([make, "-f", makefilePath]);
assert(res.status == 0, res.output);
assert(std.file.read(textOutput) == "hello world\n");
}
}
void runConcurrencyTest(string rdmdApp, string compiler, string model)

View file

@ -10,8 +10,15 @@ set -uexo pipefail
GDMD=$(find ~/dlang -type f -name "gdmd")
LDMD2=$(find ~/dlang -type f -name "ldmd2")
make -f posix.mak all DMD="$(which dmd)"
make -f posix.mak test DMD="$(which dmd)" \
curl https://ftp.gnu.org/gnu/make/make-4.2.tar.gz | tar -xz
cd make-4.2
./configure
./build.sh
cd ..
export MAKE=$(pwd)/make-4.2/make
$MAKE -f posix.mak all DMD="$(which dmd)"
$MAKE -f posix.mak test DMD="$(which dmd)" \
RDMD_TEST_COMPILERS=dmd,"$GDMD","$LDMD2" \
VERBOSE_RDMD_TEST=1