From 1ae0cd48961c6340fe16dc62d888096773d57cc0 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 2 Aug 2016 13:34:14 +0200 Subject: Filter gratuitous VC cl.exe and link.exe messages --- build2/cxx/compile.cxx | 49 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) (limited to 'build2/cxx/compile.cxx') diff --git a/build2/cxx/compile.cxx b/build2/cxx/compile.cxx index c737ce7..5e7a1b2 100644 --- a/build2/cxx/compile.cxx +++ b/build2/cxx/compile.cxx @@ -7,6 +7,7 @@ #include #include // numeric_limits #include // exit() +#include // cerr #include @@ -1211,7 +1212,7 @@ namespace build2 // we need to copy the diagnostics for the user to see. // if (!is.eof () && cid == "msvc" && bad_error) - *diag_stream << is.rdbuf (); + cerr << is.rdbuf (); is.close (); @@ -1248,6 +1249,11 @@ namespace build2 } } + // Filter cl.exe noise (msvc.cxx). + // + void + msvc_filter_cl (ifdstream&, const path& src); + target_state compile:: perform_update (action a, target& xt) { @@ -1406,19 +1412,38 @@ namespace build2 try { - // @@ VC prints file name being compiled to stdout as the first - // line, would be good to weed it out (but check if it is - // always printed, for example if the file does not exist). - // Seems always. The same story with link.exe when creating - // the DLL. + // VC cl.exe sends diagnostics to stdout. It also prints the file name + // being compiled as the first line. So for cl.exe we redirect stdout + // to a pipe, filter that noise out, and send the rest to stderr. // - - // VC++ cl.exe sends diagnostics to stdout. To fix this (and any other - // insane compilers that may want to do something like this) we are - // going to always redirect stdout to stderr. For sane compilers this - // should be harmless. + // For other compilers redirect stdout to stderr, in case any of them + // tries to pull off something similar. For sane compilers this should + // be harmless. // - process pr (args.data (), 0, 2); + bool filter (cid == "msvc"); + + process pr (args.data (), 0, (filter ? -1 : 2)); + + if (filter) + { + try + { + ifdstream is (pr.in_ofd, fdstream_mode::text, ifdstream::badbit); + + msvc_filter_cl (is, rels); + + // If anything remains in the stream, send it all to stderr. Note + // that the eos check is important: if the stream is at eos, this + // and all subsequent writes to cerr will fail (and you won't see + // a thing). + // + if (is.peek () != ifdstream::traits_type::eof ()) + cerr << is.rdbuf (); + + is.close (); + } + catch (const ifdstream::failure&) {} // Assume exits with error. + } if (!pr.wait ()) throw failed (); -- cgit v1.1