Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions changelog/rdmdMakefiles.dd
Original file line number Diff line number Diff line change
@@ -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 changes: 5 additions & 3 deletions rdmd.d
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Superstar64 FYI: I fixed the style here. DStyle is to use whitespace before/after binary operators.

{
return i + 1;
return i;
}
}

Expand Down
23 changes: 23 additions & 0 deletions rdmd_test.d
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down