From 449b62075c81431c58ab9fef0054d61513d9d656 Mon Sep 17 00:00:00 2001 From: Evan Martin Date: Sun, 12 Aug 2012 16:29:43 -0700 Subject: msvc helper: drop system includes Drop any #includes that look like they're referencing system headers. This reduces the dependency information considerably. --- src/msvc_helper-win32.cc | 12 +++++++++++- src/msvc_helper.h | 7 +++++-- src/msvc_helper_test.cc | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/msvc_helper-win32.cc b/src/msvc_helper-win32.cc index f6b2a22..624bc2d 100644 --- a/src/msvc_helper-win32.cc +++ b/src/msvc_helper-win32.cc @@ -17,6 +17,7 @@ #include #include +#include "includes_normalize.h" #include "util.h" namespace { @@ -46,6 +47,13 @@ string CLWrapper::FilterShowIncludes(const string& line) { } // static +bool CLWrapper::IsSystemInclude(const string& path) { + // TODO: this is a heuristic, perhaps there's a better way? + return (path.find("program files") != string::npos || + path.find("microsoft visual studio") != string::npos); +} + +// static bool CLWrapper::FilterInputFilename(const string& line) { // TODO: other extensions, like .asm? return EndsWith(line, ".c") || @@ -115,7 +123,9 @@ int CLWrapper::Run(const string& command, string* extra_output) { string include = FilterShowIncludes(line); if (!include.empty()) { - includes_.push_back(include); + include = IncludesNormalize::Normalize(include, NULL); + if (!IsSystemInclude(include)) + includes_.push_back(include); } else if (FilterInputFilename(line)) { // Drop it. // TODO: if we support compiling multiple output files in a single diff --git a/src/msvc_helper.h b/src/msvc_helper.h index 5bf9787..41b9f9b 100644 --- a/src/msvc_helper.h +++ b/src/msvc_helper.h @@ -16,8 +16,6 @@ #include using namespace std; -struct StringPiece; - /// Visual Studio's cl.exe requires some massaging to work with Ninja; /// for example, it emits include information on stderr in a funny /// format when building with /showIncludes. This class wraps a CL @@ -34,6 +32,11 @@ struct CLWrapper { /// Exposed for testing. static string FilterShowIncludes(const string& line); + /// Return true if a mentioned include file is a system path. + /// Expects the path to already by normalized (including lower case). + /// Filtering these out reduces dependency information considerably. + static bool IsSystemInclude(const string& path); + /// 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. diff --git a/src/msvc_helper_test.cc b/src/msvc_helper_test.cc index a0bab90..b65d66f 100644 --- a/src/msvc_helper_test.cc +++ b/src/msvc_helper_test.cc @@ -58,3 +58,17 @@ TEST(MSVCHelperTest, RunFilenameFilter) { &output); ASSERT_EQ("cl: warning\n", output); } + +TEST(MSVCHelperTest, RunSystemInclude) { + CLWrapper cl; + string output; + cl.Run("cmd /c \"echo Note: including file: c:\\Program Files\\foo.h&&" + "echo Note: including file: d:\\Microsoft Visual Studio\\bar.h&&" + "echo Note: including file: path.h\"", + &output); + // We should have dropped the first two includes because they look like + // system headers. + ASSERT_EQ("", output); + ASSERT_EQ(1u, cl.includes_.size()); + ASSERT_EQ("path.h", cl.includes_[0]); +} -- cgit v0.12