From ab978916ef5d3a8f876953697c6eb9cdeedbc998 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 20 Sep 2021 10:51:12 +0200 Subject: Improve MSVC /showIncludes output handling --- libbuild2/cc/compile-rule.cxx | 48 +++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 13 deletions(-) (limited to 'libbuild2') diff --git a/libbuild2/cc/compile-rule.cxx b/libbuild2/cc/compile-rule.cxx index df7be87..278f0cc 100644 --- a/libbuild2/cc/compile-rule.cxx +++ b/libbuild2/cc/compile-rule.cxx @@ -4403,11 +4403,16 @@ namespace build2 ifdstream::badbit); size_t skip (skip_count); - string l; // Reuse. + string l, l2; // Reuse. for (bool first (true), second (false); !restart; ) { if (eof (getline (is, l))) + { + if (bad_error && !l2.empty ()) + text << l2; + break; + } l6 ([&]{trace << "header dependency line '" << l << "'";}); @@ -4418,20 +4423,31 @@ namespace build2 case compiler_class::msvc: { // The first line should be the file we are compiling, - // unless this is clang-cl. If it is not, then something - // went wrong even before we could compile anything - // (e.g., file does not exist). In this case the first - // line (and everything after it) is presumably - // diagnostics. + // unless this is clang-cl. + // + // If it is not, then we have several possibilities: // - // It can, however, be a command line warning, for - // example: + // First, it can be a command line warning, for example: // // cl : Command line warning D9025 : overriding '/W3' with '/W4' // // So we try to detect and skip them assuming they will // also show up during the compilation proper. // + // Another possibility is a mis-spelled option that is + // treated as another file to compile, for example: + // + // cl junk /nologo /P /showIncluses /TP foo.cxx + // junk + // foo.cxx + // c1xx: fatal error C1083: Cannot open source file: 'junk': No such file or directory + // + // Yet another possibility is that something went wrong + // even before we could compile anything. + // + // So the plan is to keep going (in the hope of C1083) + // but print the last line if there is no more input. + // if (first) { if (cvariant != "clang") @@ -4442,12 +4458,18 @@ namespace build2 // size_t p (msvc_sense_diag (l, 'D').first); if (p != string::npos && l[p] == '9') - continue; - - text << l; - bad_error = true; - break; + ; // Skip. + else + { + l2 = l; + bad_error = true; + } + + continue; } + + l2.clear (); + // Fall through. } -- cgit v1.1