summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2012-08-12 23:29:43 (GMT)
committerEvan Martin <martine@danga.com>2012-08-12 23:29:43 (GMT)
commit449b62075c81431c58ab9fef0054d61513d9d656 (patch)
tree2fba32069a42caa65a8d00112ea461a7d129a5fe /src
parentde3f570cfe0bfdd564913a1431dc95fd17ff44eb (diff)
downloadNinja-449b62075c81431c58ab9fef0054d61513d9d656.zip
Ninja-449b62075c81431c58ab9fef0054d61513d9d656.tar.gz
Ninja-449b62075c81431c58ab9fef0054d61513d9d656.tar.bz2
msvc helper: drop system includes
Drop any #includes that look like they're referencing system headers. This reduces the dependency information considerably.
Diffstat (limited to 'src')
-rw-r--r--src/msvc_helper-win32.cc12
-rw-r--r--src/msvc_helper.h7
-rw-r--r--src/msvc_helper_test.cc14
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 <string.h>
#include <windows.h>
+#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 <vector>
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]);
+}