Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into sym-2.107
Browse files Browse the repository at this point in the history
  • Loading branch information
kinke committed Feb 20, 2024
2 parents 2a57670 + cc9ec99 commit 5461343
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 22 deletions.
11 changes: 8 additions & 3 deletions payload/reggae/backend/make.d
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ struct Makefile {
//includes rerunning reggae
string output() @safe {

import std.array: join;
import std.array: join, replace;
import std.range: chain;
import std.algorithm: sort, uniq, map;

auto ret = simpleOutput;

Expand All @@ -85,8 +86,12 @@ struct Makefile {
} else {
// add a dependency on the Makefile to reggae itself and the build description,
// but only if not exporting a build
ret ~= fileName() ~ ": " ~ chain(options.reggaeFileDependencies, _srcDirs).join(" ") ~ "\n";
ret ~= "\t" ~ options.rerunArgs.join(" ") ~ "\n";
auto srcDirs = _srcDirs.sort.uniq;
const rerunLine = "\t" ~ options.rerunArgs.join(" ") ~ "\n";

ret ~= fileName() ~ ": " ~ chain(options.reggaeFileDependencies, srcDirs.save).join(" ") ~ "\n";
ret ~= rerunLine;
ret ~= "\n" ~ srcDirs.save.map!(d => d ~ ":" ~ "\n" ~ rerunLine).join("\n");
}

return replaceEnvVars(ret);
Expand Down
33 changes: 25 additions & 8 deletions payload/reggae/backend/ninja.d
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,33 @@ struct Ninja {

//includes rerunning reggae
const(NinjaEntry)[] allBuildEntries() @safe {
import std.array: array;
import std.algorithm: sort, uniq;
import std.range: chain;
import std.array: array, replace;
import std.algorithm: sort, uniq, map;
import std.range: chain, only;

auto srcDirs = _srcDirs.sort.uniq;
const files = flattenEntriesInBuildLine(
chain(_options.reggaeFileDependencies, _srcDirs.sort.uniq).array
chain(_options.reggaeFileDependencies, srcDirs).array
);
auto paramLines = _options.oldNinja ? [] : ["pool = console"];

const(NinjaEntry)[] rerunEntries() {
// if exporting the build system, don't include rerunning reggae
return _options.export_
? []
: [NinjaEntry("build build.ninja: _rerun | " ~ files, paramLines)];
if(_options.export_)
return [];
auto rerun = NinjaEntry("build build.ninja: _rerun | " ~ files, paramLines);
// the reason this is needed is because source directories
// can be deleted or renamed. If they are, ninja will
// complain about the missing directories since they are a
// dependency of the build.ninja file for rerunning
// reggae. So we consider them phony targets with no
// dependencies to make that not happen and ninja will
// rerun reggae and change the list of source directories
// accordingly.
auto phonySrcDirs = srcDirs
.map!(a => NinjaEntry("build " ~ a.escapeBuildLine ~ ": phony"))
;
return chain(rerun.only, phonySrcDirs).array;
}

const defaultOutputs = _build.defaultTargetsOutputs(_projectPath);
Expand Down Expand Up @@ -364,7 +377,7 @@ private:
import std.algorithm: map;
import std.array: join, replace;
return entries
.map!(e => e.replace(":", "$:").replace(" ", "$ "))
.map!escapeBuildLine
.join(" ");
}

Expand Down Expand Up @@ -392,6 +405,10 @@ private:
}
}

private string escapeBuildLine(in string line) @safe pure {
import std.array: replace;
return line.replace(":", "$:").replace(" ", "$ ");
}

struct NinjaEntry {
string mainLine;
Expand Down
23 changes: 15 additions & 8 deletions src/reggae/reggae.d
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ private string[] getJsonOutputArgs(in Options options) @safe {
private void createBuild(T)(auto ref T output, in Options options) {

import reggae.io: log;
import std.process: spawnProcess, wait;

enforce(options.reggaeFilePath.exists, text("Could not find ", options.reggaeFilePath));

Expand All @@ -204,12 +205,10 @@ private void createBuild(T)(auto ref T output, in Options options) {

//actually run the build generator
output.log("Running the created binary to generate the build");
immutable retRunBuildgen = execute([buildPath(hiddenDirAbsPath(options), buildGenName)]);
enforce(retRunBuildgen.status == 0,
text("Couldn't execute the produced ", buildGenName, " binary:\n", retRunBuildgen.output));
immutable buildgenStatus = spawnProcess([buildPath(hiddenDirAbsPath(options), buildGenName)]).wait();
enforce(buildgenStatus == 0,
text("Executing the produced ", buildGenName, " binary failed"));
output.log("Build generated");

if(retRunBuildgen.output.length) output.log(retRunBuildgen.output);
}


Expand Down Expand Up @@ -290,7 +289,7 @@ private Binary buildReggaefileDub(O)(
import std.path: buildPath;
import std.algorithm: map, joiner;
import std.range: chain, only;
import std.array: replace;
import std.array: replace, join;

// calculates .dep so getReggaeFileDependenciesDlang works below
calculateReggaeFileDeps(output, options);
Expand Down Expand Up @@ -318,13 +317,21 @@ private Binary buildReggaefileDub(O)(
const dubRecipeDir = hiddenDirAbsPath(options);
const dubRecipePath = buildPath(dubRecipeDir, "dub.sdl");

const linesIfBinary = [
`targetPath ".."`,
`targetName "build"`,
];
const extraLines = options.backend == Backend.binary
? linesIfBinary
: [];

writeIfDiffers(
output,
dubRecipePath,
reggaeFileDubSdl.format(
userSourceFilesForDubSdl,
importPathsForDubSdl,
),
) ~ extraLines.join("\n"),
);

writeIfDiffers(
Expand Down Expand Up @@ -499,7 +506,7 @@ private string getBuildGenName(in Options options) @safe pure nothrow {
import reggae.rules.common: exeExt;

const baseName = options.backend == Backend.binary
? buildPath("../build")
? "../build"
: "buildgen";
return baseName ~ exeExt;
}
Expand Down
47 changes: 44 additions & 3 deletions tests/it/runtime/issues.d
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,7 @@ version(Posix) {
]
);
runReggae("-b", "ninja").shouldThrowWithMessage(
"Couldn't execute the produced buildgen binary:\n" ~
"Cannot have a custom rule with no $in or $out: " ~
"use `phony` or explicit $in/$out instead.\n");
"Executing the produced buildgen binary failed");
}
}
}
Expand Down Expand Up @@ -481,3 +479,46 @@ unittest {
shouldExist("dub_objs");
}
}

version(DigitalMars) {
static foreach(backend; ["ninja", "make"]) {
@("rerun.deleted.dir." ~ backend)
@Tags(backend)
unittest {
import std.file: rmdirRecurse;

with(immutable ReggaeSandbox()) {

writeFile(
"reggaefile.d",
q{
import reggae;
alias lib = staticLibrary!(
"mylib",
Sources!("source")
);
mixin build!lib;
}
);
writeFile("source/maths/foo.d", "int twice (int i) { return i * 2; }");
writeFile("source/maths/bar.d", "int thrice(int i) { return i * 3; }");
writeFile("source/util/baz.d", "void baz() {}");

runReggae("-b", backend, "--verbose");
mixin(backend).shouldExecuteOk;

// delete the source directory and make sure reggae gets rerun
rmdirRecurse(inSandboxPath("source/util"));

static if(backend == "ninja")
enum msg = "missing and no known rule";
else static if(backend == "make")
enum msg = "No rule to make target";
else
static assert(false, "unknown backend");

mixin(backend).shouldFailToExecute.shouldNotContain(msg);
}
}
}
}
20 changes: 20 additions & 0 deletions tests/it/runtime/regressions.d
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,23 @@ unittest {
ninja.shouldFailToExecute(testPath);
}
}

@("buildgen.binary")
@Tags("binary")
unittest {
import reggae.rules.common: exeExt;
with(immutable ReggaeSandbox()) {
writeFile(
"reggaefile.d",
q{
import reggae;
alias lib = staticLibrary!("mylib", Sources!("src"));
mixin build!lib;
}
);

writeFile("src/foo.d", "void foo() {}");
runReggae("-b", "binary");
shouldExist("build" ~ exeExt);
}
}

0 comments on commit 5461343

Please sign in to comment.