summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/msvc_helper-win32.cc23
-rw-r--r--src/msvc_helper.h6
-rw-r--r--src/msvc_helper_test.cc18
3 files changed, 47 insertions, 0 deletions
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<string> 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);
+}