don't emit duplicate headers for msvc helper
authorScott Graham <scottmg@chromium.org>
Mon, 17 Sep 2012 22:46:55 +0000 (15:46 -0700)
committerScott Graham <scottmg@chromium.org>
Mon, 17 Sep 2012 22:46:55 +0000 (15:46 -0700)
src/msvc_helper-win32.cc
src/msvc_helper.h
src/msvc_helper_main-win32.cc
src/msvc_helper_test.cc

index 8e440fe18064fd6cd4143603c73533ee3b34bfdb..a9f34aa5e9b08c8cb2f542e5a5f43060218d5b50 100644 (file)
@@ -125,7 +125,7 @@ int CLWrapper::Run(const string& command, string* extra_output) {
       if (!include.empty()) {
         include = IncludesNormalize::Normalize(include, NULL);
         if (!IsSystemInclude(include))
-          includes_.push_back(include);
+          includes_.insert(include);
       } else if (FilterInputFilename(line)) {
         // Drop it.
         // TODO: if we support compiling multiple output files in a single
index f623520fa75e4ef736132b5fba898184adc8e9fb..c68f63122947ebf630d5b9e03f2bbfd4bc993afd 100644 (file)
@@ -13,7 +13,7 @@
 // limitations under the License.
 
 #include <string>
-#include <vector>
+#include <set>
 using namespace std;
 
 /// Visual Studio's cl.exe requires some massaging to work with Ninja;
@@ -50,5 +50,5 @@ struct CLWrapper {
   static bool FilterInputFilename(const string& line);
 
   void* env_block_;
-  vector<string> includes_;
+  set<string> includes_;
 };
index 0c8db370daf5282445c4b10daefe36e0de2d7cb8..ed7674cc789ee72aeb9473d07c5e2d62a5857de2 100644 (file)
@@ -105,7 +105,7 @@ int MSVCHelperMain(int argc, char** argv) {
     Fatal("opening %s: %s", depfile.c_str(), GetLastErrorString().c_str());
   }
   fprintf(output, "%s: ", output_filename);
-  for (vector<string>::iterator i = cl.includes_.begin();
+  for (set<string>::iterator i = cl.includes_.begin();
        i != cl.includes_.end(); ++i) {
     fprintf(output, "%s\n", i->c_str());
   }
index 29fefd452ce54b4f81599a65c67d0fd26439a845..85ac039c8a8ec627e052aaf499182f37c76d90ef 100644 (file)
@@ -48,7 +48,7 @@ TEST(MSVCHelperTest, Run) {
          &output);
   ASSERT_EQ("foo\nbar\n", output);
   ASSERT_EQ(1u, cl.includes_.size());
-  ASSERT_EQ("foo.h", cl.includes_[0]);
+  ASSERT_EQ("foo.h", *cl.includes_.begin());
 }
 
 TEST(MSVCHelperTest, RunFilenameFilter) {
@@ -70,7 +70,7 @@ TEST(MSVCHelperTest, RunSystemInclude) {
   // system headers.
   ASSERT_EQ("", output);
   ASSERT_EQ(1u, cl.includes_.size());
-  ASSERT_EQ("path.h", cl.includes_[0]);
+  ASSERT_EQ("path.h", *cl.includes_.begin());
 }
 
 TEST(MSVCHelperTest, EnvBlock) {
@@ -81,3 +81,27 @@ TEST(MSVCHelperTest, EnvBlock) {
   cl.Run("cmd /c \"echo foo is %foo%", &output);
   ASSERT_EQ("foo is bar\n", output);
 }
+
+TEST(MSVCHelperTest, DuplicatedHeader) {
+  CLWrapper cl;
+  string output;
+  cl.Run("cmd /c \"echo Note: including file: foo.h&&"
+         "echo Note: including file: bar.h&&"
+         "echo Note: including file: foo.h\"",
+         &output);
+  // We should have dropped one copy of foo.h.
+  ASSERT_EQ("", output);
+  ASSERT_EQ(2u, cl.includes_.size());
+}
+
+TEST(MSVCHelperTest, DuplicatedHeaderPathConverted) {
+  CLWrapper cl;
+  string output;
+  cl.Run("cmd /c \"echo Note: including file: sub/foo.h&&"
+         "echo Note: including file: bar.h&&"
+         "echo Note: including file: sub\\foo.h\"",
+         &output);
+  // We should have dropped one copy of foo.h.
+  ASSERT_EQ("", output);
+  ASSERT_EQ(2u, cl.includes_.size());
+}