diff --git a/src/dmd/cparse.d b/src/dmd/cparse.d index 8bcd35e1b621..645957526332 100644 --- a/src/dmd/cparse.d +++ b/src/dmd/cparse.d @@ -4931,6 +4931,10 @@ final class CParser(AST) : Parser!AST /* Append this line to `defines`. * Not canonicalizing it - assume it already is */ +version (Windows) +{ + printf("define: %s\n", n.ident.toChars()); +} defines.writeByte('#'); defines.writestring(n.ident.toString()); skipToNextLine(defines); diff --git a/src/dmd/link.d b/src/dmd/link.d index 020505b771d3..cbcb5849edf1 100644 --- a/src/dmd/link.d +++ b/src/dmd/link.d @@ -1058,7 +1058,7 @@ public int runPreprocessor(const(char)[] cpp, const(char)[] filename, const(char */ OutBuffer buf; buf.writestring(cpp); - buf.printf(" /P /nologo %.*s /FI%s /Fi%.*s", + buf.printf(" /P /PD /Zc:preprocessor /nologo %.*s /FI%s /Fi%.*s", cast(int)filename.length, filename.ptr, importc_h, cast(int)output.length, output.ptr); /* Append preprocessor switches to command line @@ -1077,24 +1077,46 @@ public int runPreprocessor(const(char)[] cpp, const(char)[] filename, const(char ubyte[2048] buffer = void; - bool firstLine = true; + OutBuffer linebuf; // each line from stdout + bool print = false; // print line collected from stdout + + /* Collect text captured from stdout to linebuf[]. + * Then decide to print or discard the contents. + * Discarding lines that consist only of a filename is necessary to pass + * the D test suite which diffs the output. CL's emission of filenames cannot + * be turned off. + */ void sink(ubyte[] data) { - if (firstLine) + foreach (c; data) { - for (size_t i = 0; 1; ++i) + switch (c) { - if (i == data.length) - return; - if (data[i] == '\n') // reached end of first line - { - data = data[i + 1 .. data.length]; - firstLine = false; + case '\r': + break; + + case '\n': + if (print) + printf("%s\n", linebuf.peekChars()); + + // set up for next line + linebuf.setsize(0); + print = false; + break; + + case '\t': + case ';': + case '(': + case '\'': + case '"': // various non-filename characters + print = true; // mean it's not a filename + goto default; + + default: + linebuf.writeByte(c); break; - } } } - printf("%.*s", cast(int)data.length, data.ptr); } // Convert command to wchar @@ -1103,7 +1125,10 @@ public int runPreprocessor(const(char)[] cpp, const(char)[] filename, const(char auto szCommand = toWStringz(buf.peekChars()[0 .. buf.length], smbuf); int exitCode = runProcessCollectStdout(szCommand.ptr, buffer[], &sink); - printf("\n"); + + if (linebuf.length && print) // anything leftover from stdout collection + printf("%s\n", defines.peekChars()); + return exitCode; } else diff --git a/test/compilable/testdefines.c b/test/compilable/imports/defines.c similarity index 59% rename from test/compilable/testdefines.c rename to test/compilable/imports/defines.c index 0e54447e758a..16b314475b7b 100644 --- a/test/compilable/testdefines.c +++ b/test/compilable/imports/defines.c @@ -1,3 +1,2 @@ -// DISABLED: win64 win32mscoff #define GHI 3 _Static_assert(GHI == 3, "1"); diff --git a/test/compilable/testdefines.d b/test/compilable/testdefines.d new file mode 100644 index 000000000000..fad20002f989 --- /dev/null +++ b/test/compilable/testdefines.d @@ -0,0 +1,4 @@ +// EXTRA_FILES: imports/defines.c +import imports.defines; + +static assert(GHI == 3);