From c963c4834d0ab05ce8ecf341c74db6ded379fa8a Mon Sep 17 00:00:00 2001 From: Evan Martin Date: Sun, 12 Aug 2012 15:09:33 -0700 Subject: msvc helper: attempt to filter out when it prints the input filename This is a heuristic but it appears to work for the Chrome build. --- src/msvc_helper-win32.cc | 23 +++++++++++++++++++++++ src/msvc_helper.h | 6 ++++++ src/msvc_helper_test.cc | 18 ++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/src/msvc_helper-win32.cc b/src/msvc_helper-win32.cc index ac957e4..f6b2a22 100644 --- a/src/msvc_helper-win32.cc +++ b/src/msvc_helper-win32.cc @@ -19,6 +19,16 @@ #include "util.h" +namespace { + +/// Return true if \a input ends with \a needle. +bool EndsWith(const string& input, const string& needle) { + return (input.size() >= needle.size() && + input.substr(input.size() - needle.size()) == needle); +} + +} // anonymous namespace + // static string CLWrapper::FilterShowIncludes(const string& line) { static const char kMagicPrefix[] = "Note: including file: "; @@ -35,6 +45,15 @@ string CLWrapper::FilterShowIncludes(const string& line) { return ""; } +// static +bool CLWrapper::FilterInputFilename(const string& line) { + // TODO: other extensions, like .asm? + return EndsWith(line, ".c") || + EndsWith(line, ".cc") || + EndsWith(line, ".cxx") || + EndsWith(line, ".cpp"); +} + int CLWrapper::Run(const string& command, string* extra_output) { SECURITY_ATTRIBUTES security_attributes = {}; security_attributes.nLength = sizeof(SECURITY_ATTRIBUTES); @@ -97,6 +116,10 @@ int CLWrapper::Run(const string& command, string* extra_output) { string include = FilterShowIncludes(line); if (!include.empty()) { includes_.push_back(include); + } else if (FilterInputFilename(line)) { + // Drop it. + // TODO: if we support compiling multiple output files in a single + // cl.exe invocation, we should stash the filename. } else { if (extra_output) { extra_output->append(line); diff --git a/src/msvc_helper.h b/src/msvc_helper.h index 5a657be..5bf9787 100644 --- a/src/msvc_helper.h +++ b/src/msvc_helper.h @@ -34,5 +34,11 @@ struct CLWrapper { /// Exposed for testing. static string FilterShowIncludes(const string& line); + /// Parse a line of cl.exe output and return true if it looks like + /// it's printing an input filename. This is a heuristic but it appears + /// to be the best we can do. + /// Exposed for testing. + static bool FilterInputFilename(const string& line); + vector includes_; }; diff --git a/src/msvc_helper_test.cc b/src/msvc_helper_test.cc index 8db4c69..a0bab90 100644 --- a/src/msvc_helper_test.cc +++ b/src/msvc_helper_test.cc @@ -31,6 +31,16 @@ TEST(MSVCHelperTest, ShowIncludes) { "c:\\initspaces.h")); } +TEST(MSVCHelperTest, FilterInputFilename) { + ASSERT_TRUE(CLWrapper::FilterInputFilename("foobar.cc")); + ASSERT_TRUE(CLWrapper::FilterInputFilename("foo bar.cc")); + ASSERT_TRUE(CLWrapper::FilterInputFilename("baz.c")); + + ASSERT_FALSE(CLWrapper::FilterInputFilename( + "src\\cl_helper.cc(166) : fatal error C1075: end " + "of file found ...")); +} + TEST(MSVCHelperTest, Run) { CLWrapper cl; string output; @@ -40,3 +50,11 @@ TEST(MSVCHelperTest, Run) { ASSERT_EQ(1u, cl.includes_.size()); ASSERT_EQ("foo.h", cl.includes_[0]); } + +TEST(MSVCHelperTest, RunFilenameFilter) { + CLWrapper cl; + string output; + cl.Run("cmd /c \"echo foo.cc&& echo cl: warning\"", + &output); + ASSERT_EQ("cl: warning\n", output); +} -- cgit v0.12