diff --git a/rdmd.d b/rdmd.d index fda6304d24..8df8118d54 100755 --- a/rdmd.d +++ b/rdmd.d @@ -231,7 +231,8 @@ int main(string[] args) } // Compute the object directory and ensure it exists - immutable workDir = getWorkPath(root, compilerFlags); + auto environmentFlags = environment.get("DFLAGS", "").split(" "); + immutable workDir = getWorkPath(root, compilerFlags ~ environmentFlags); lockWorkPath(workDir); // will be released by the OS on process exit string objDir = buildPath(workDir, "objs"); Filesystem.mkdirRecurseIfLive(objDir); diff --git a/rdmd_test.d b/rdmd_test.d index 1ee42d8da7..e8a7002bcd 100755 --- a/rdmd_test.d +++ b/rdmd_test.d @@ -637,6 +637,27 @@ SHELL = %s assert(res.status == 0, res.output); assert(std.file.read(textOutput) == "hello world\n"); } + + // https://issues.dlang.org/show_bug.cgi?id=18423 + // rdmd ignores changes in DFLAGS + { + string srcName = tempDir().buildPath("force_rebuild_dflags.d"); + std.file.write(srcName, `void main() { import std.stdio; version(Foo) {"foo".writeln;} else { "bar".writeln; }}`); + + res = execute(rdmdArgs ~ [srcName]); + assert(res.status == 0, res.output); + assert(res.output.canFind("bar")); + + environment["DFLAGS"] = "-version=Foo"; + res = execute(rdmdArgs ~ [srcName]); + assert(res.status == 0, res.output); + assert(res.output.canFind("foo"), res.output); + + environment.remove("DFLAGS"); + res = execute(rdmdArgs ~ [srcName]); + assert(res.status == 0, res.output); + assert(res.output.canFind("bar")); + } } void runConcurrencyTest(string rdmdApp, string compiler, string model)