Permalink
Browse files

Merge pull request #422 from sgraham/fix-dupe-includes

don't emit duplicate headers for msvc helper
  • Loading branch information...
2 parents d95fcb0 + 0adc699 commit 75f1b00cc3b1685e7c530208d0e328c3f80a4c9b @evmar evmar committed Sep 17, 2012
Showing with 30 additions and 6 deletions.
  1. +1 −1 src/msvc_helper-win32.cc
  2. +2 −2 src/msvc_helper.h
  3. +1 −1 src/msvc_helper_main-win32.cc
  4. +26 −2 src/msvc_helper_test.cc
View
@@ -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
View
@@ -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_;
};
@@ -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());
}
View
@@ -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());
+}

0 comments on commit 75f1b00

Please sign in to comment.