Skip to content

Commit

Permalink
Better at printing
Browse files Browse the repository at this point in the history
  • Loading branch information
atilaneves committed May 27, 2024
1 parent eb30e81 commit 29c65fc
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 86 deletions.
14 changes: 9 additions & 5 deletions src/reggae/reggae.d
Original file line number Diff line number Diff line change
Expand Up @@ -486,11 +486,6 @@ private void buildBinary(T)(auto ref T output, in Options options, in Binary bin
: "";
output.log("Compiling metabuild binary ", bin.name, extraInfo);


import std.file;
import std.stdio;
dirEntries(reggaeSrcDirName(options), SpanMode.depth).writeln;

// std.process.execute has a bug where using workDir and a relative path
// don't work (https://issues.dlang.org/show_bug.cgi?id=15915)
// so executeShell is used instead
Expand All @@ -502,6 +497,15 @@ private void buildBinary(T)(auto ref T output, in Options options, in Binary bin
"\n", "bin.name: ", bin.name, ", bin.cmd: ", bin.cmd.join(" ")));
if(options.verbose)
output.log(res.output);
if(res.status != 0) {
import std.file;
import std.stdio;
import std.string;
import core.stdc.stdio: printf;
printf((dirEntries(reggaeSrcDirName(options), SpanMode.depth).text ~ "\n").toStringz);
}


}

private string[] importPaths(const Options options) @safe nothrow {
Expand Down
20 changes: 11 additions & 9 deletions tests/it/buildgen/outputs_in_project_path.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import tests.it;
import std.file;


static foreach (backend; ["ninja", "make", "binary"])
@("lorem (" ~ backend ~ ")")
@Tags(backend)
unittest {
enum module_ = "outputs_in_project_path.reggaefile";
auto options = testProjectOptions!module_(backend);
version(Posix) {
static foreach (backend; ["ninja", "make", "binary"])
@("lorem (" ~ backend ~ ")")
@Tags(backend)
unittest {
enum module_ = "outputs_in_project_path.reggaefile";
auto options = testProjectOptions!module_(backend);

doTestBuildFor!module_(options);
inPath(options, "generated/release/64/linux/copy.txt").exists.shouldBeTrue;
}
doTestBuildFor!module_(options);
inPath(options, "generated/release/64/linux/copy.txt").exists.shouldBeTrue;
}
}
43 changes: 23 additions & 20 deletions tests/it/runtime/dub/proper.d
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,17 @@ unittest {
}


@("postbuild")
@Tags(["dub", "ninja", "posix"])
unittest {
with(immutable ReggaeSandbox("dub_postbuild")) {
runReggae("-b", "ninja");
shouldNotExist("foo.txt");
ninja.shouldExecuteOk;
shouldExist("foo.txt");
shouldSucceed("postbuild");
version(Posix) {
@("postbuild")
@Tags(["dub", "ninja", "posix"])
unittest {
with(immutable ReggaeSandbox("dub_postbuild")) {
runReggae("-b", "ninja");
shouldNotExist("foo.txt");
ninja.shouldExecuteOk;
shouldExist("foo.txt");
shouldSucceed("postbuild");
}
}
}

Expand Down Expand Up @@ -244,7 +246,7 @@ version(DigitalMars) {
extern(C) int lebaz() { return 42; }
});

["dmd", "-c", "baz.d"].shouldExecuteOk;
["dmd", "-c", inSandboxPath("baz.d")].shouldExecuteOk;

runReggae("-b", "ninja");
ninja.shouldExecuteOk;
Expand Down Expand Up @@ -438,19 +440,20 @@ unittest {
}


@("depends on package with prebuild")
// fails for CI with DMD on Windows - the path to dub-generated dub_test_root.d is just over 260 chars
@Tags(["dub", "ninja", "fails-on-windows-with-dmd"])
unittest {
version(Posix) {
@("depends on package with prebuild")
@Tags(["dub", "ninja"])
unittest {

with(immutable ReggaeSandbox("dub_depends_on_prebuild")) {
with(immutable ReggaeSandbox("dub_depends_on_prebuild")) {

copyProject("dub_prebuild", buildPath("../dub_prebuild"));
copyProject("dub_prebuild", buildPath("../dub_prebuild"));

runReggae("-b", "ninja");
ninja.shouldExecuteOk;
shouldSucceed("app");
shouldExist(inSandboxPath("../dub_prebuild/el_prebuildo.txt"));
runReggae("-b", "ninja");
ninja.shouldExecuteOk;
shouldSucceed("app");
shouldExist(inSandboxPath("../dub_prebuild/el_prebuildo.txt"));
}
}
}

Expand Down
108 changes: 56 additions & 52 deletions tests/it/runtime/regressions.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,65 +5,69 @@ import tests.it.runtime;
import reggae.reggae;


@("Issue 14: builddir not expanded")
@Tags(["ninja", "regressions", "posix"])
unittest {
version(Posix) {
@("Issue 14: builddir not expanded")
@Tags(["ninja", "regressions", "posix"])
unittest {

with(immutable ReggaeSandbox()) {
writeFile("reggaefile.d", q{
import reggae;
enum ao = objectFile!(SourceFile("a.c"));
enum liba = Target("$builddir/liba.a", "ar rcs $out $in", [ao]);
mixin build!(liba);
});
with(immutable ReggaeSandbox()) {
writeFile("reggaefile.d", q{
import reggae;
enum ao = objectFile!(SourceFile("a.c"));
enum liba = Target("$builddir/liba.a", "ar rcs $out $in", [ao]);
mixin build!(liba);
});

writeFile("a.c");
writeFile("a.c");

runReggae("-b", "ninja");
ninja.shouldExecuteOk;
runReggae("-b", "ninja");
ninja.shouldExecuteOk;
}
}
}

@("Issue 12: can't set executable as a dependency")
@Tags(["ninja", "regressions"])
unittest {

with(immutable ReggaeSandbox()) {
writeFile("reggaefile.d", q{
import reggae;
alias app = scriptlike!(App(SourceFileName("main.d"),
BinaryFileName("$builddir/myapp")),
Flags(),
ImportPaths(["/path/to/imports"])
);
alias code_gen = target!("out.c", "./myapp $in $out", target!"in.txt", app);
mixin build!(code_gen);
});

writeFile("main.d", q{
import std.stdio;
import std.algorithm;
import std.conv;
void main(string[] args) {
auto inFileName = args[1];
auto outFileName = args[2];
auto lines = File(inFileName, `r`).byLine.
map!(a => a.to!string).
map!(a => a ~ ` ` ~ a);
auto outFile = File(outFileName, `w`);
foreach(line; lines) outFile.writeln(line);
}
});

writeFile("in.txt", ["foo", "bar", "baz"]);
version(Posix) {
@("Issue 12: can't set executable as a dependency")
@Tags(["ninja", "regressions"])
unittest {

runReggae("-b", "ninja");
ninja.shouldExecuteOk;
["cat", "out.c"].shouldExecuteOk;
shouldEqualLines("out.c",
["foo foo",
"bar bar",
"baz baz"]);
with(immutable ReggaeSandbox()) {
writeFile("reggaefile.d", q{
import reggae;
alias app = scriptlike!(App(SourceFileName("main.d"),
BinaryFileName("$builddir/myapp")),
Flags(),
ImportPaths(["/path/to/imports"])
);
alias code_gen = target!("out.c", "./myapp $in $out", target!"in.txt", app);
mixin build!(code_gen);
});

writeFile("main.d", q{
import std.stdio;
import std.algorithm;
import std.conv;
void main(string[] args) {
auto inFileName = args[1];
auto outFileName = args[2];
auto lines = File(inFileName, `r`).byLine.
map!(a => a.to!string).
map!(a => a ~ ` ` ~ a);
auto outFile = File(outFileName, `w`);
foreach(line; lines) outFile.writeln(line);
}
});

writeFile("in.txt", ["foo", "bar", "baz"]);

runReggae("-b", "ninja");
ninja.shouldExecuteOk;
["cat", "out.c"].shouldExecuteOk;
shouldEqualLines("out.c",
["foo foo",
"bar bar",
"baz baz"]);
}
}
}

Expand Down

0 comments on commit 29c65fc

Please sign in to comment.