Skip to content

Commit a0dc43e

Browse files
committed
rdmd.d: Capture stderr when calculating dependencies
When invoking the compiler to calculate dependencies capture both stdout and stderr since gdc's verbose output goes to stderr. Signed-off-by: Andrei Horodniceanu <a.horodniceanu@proton.me>
1 parent 1a8c1a9 commit a0dc43e

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

rdmd.d

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ int main(string[] args)
140140
string[] eval; // set by --eval
141141
bool makeDepend;
142142
string makeDepFile;
143-
143+
144144
try
145145
{
146146
getopt(argsBeforeProgram,
@@ -182,7 +182,7 @@ int main(string[] args)
182182
if (!compiler)
183183
{
184184
compiler = defaultCompiler;
185-
185+
186186
// Look for the D compiler rdmd invokes automatically in the same directory as rdmd
187187
// and fall back to using the one in your path otherwise.
188188
string compilerPath = buildPath(dirName(thisExePath()), compiler ~ binExt);
@@ -576,7 +576,7 @@ private int rebuild(string root, string fullExe,
576576
// Run a program optionally writing the command line first
577577
// If "replace" is true and the OS supports it, replace the current process.
578578

579-
private int run(string[] args, string output = null, bool replace = false)
579+
private int run(string[] args, string output = null, bool replace = false, bool captureStderr = false)
580580
{
581581
import std.conv;
582582
yap(replace ? "exec " : "spawn ", args.text);
@@ -599,7 +599,12 @@ private int run(string[] args, string output = null, bool replace = false)
599599
outputFile = File(output, "wb");
600600
else
601601
outputFile = stdout;
602-
auto process = spawnProcess(args, stdin, outputFile);
602+
File stderrFile;
603+
if (captureStderr)
604+
stderrFile = outputFile;
605+
else
606+
stderrFile = stderr;
607+
auto process = spawnProcess(args, stdin, outputFile, stderrFile);
603608
return process.wait();
604609
}
605610

@@ -744,7 +749,9 @@ private string[string] getDependencies(string rootModule, string workDir,
744749
collectException(Filesystem.remove(depsFilename));
745750
}
746751

747-
immutable depsExitCode = run(depsGetter, depsFilename);
752+
// gdc prints -v on stderr, ldc2 and dmd use stdout
753+
immutable depsExitCode = run(depsGetter, depsFilename,
754+
/*replace=*/false, /*captureStderr=*/true);
748755
if (depsExitCode)
749756
{
750757
stderr.writefln("Failed: %s", depsGetter);

0 commit comments

Comments
 (0)