summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Graham <scottmg@chromium.org>2012-09-17 22:46:55 (GMT)
committerScott Graham <scottmg@chromium.org>2012-09-17 22:46:55 (GMT)
commit0adc69945cb9a0d6b7d150b409ddcc7194552b93 (patch)
tree9927c97a8118c6a7332df6a96d7b6a10ccab7c78
parentd95fcb0cdc816e2585ce9a65676320d71af78c7f (diff)
downloadNinja-0adc69945cb9a0d6b7d150b409ddcc7194552b93.zip
Ninja-0adc69945cb9a0d6b7d150b409ddcc7194552b93.tar.gz
Ninja-0adc69945cb9a0d6b7d150b409ddcc7194552b93.tar.bz2
don't emit duplicate headers for msvc helper
-rw-r--r--src/msvc_helper-win32.cc2
-rw-r--r--src/msvc_helper.h4
-rw-r--r--src/msvc_helper_main-win32.cc2
-rw-r--r--src/msvc_helper_test.cc28
4 files changed, 30 insertions, 6 deletions
diff --git a/src/msvc_helper-win32.cc b/src/msvc_helper-win32.cc
index 8e440fe..a9f34aa 100644
--- a/src/msvc_helper-win32.cc
+++ b/src/msvc_helper-win32.cc
@@ -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
diff --git a/src/msvc_helper.h b/src/msvc_helper.h
index f623520..c68f631 100644
--- a/src/msvc_helper.h
+++ b/src/msvc_helper.h
@@ -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_;
};
diff --git a/src/msvc_helper_main-win32.cc b/src/msvc_helper_main-win32.cc
index 0c8db37..ed7674c 100644
--- a/src/msvc_helper_main-win32.cc
+++ b/src/msvc_helper_main-win32.cc
@@ -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());
}
diff --git a/src/msvc_helper_test.cc b/src/msvc_helper_test.cc
index 29fefd4..85ac039 100644
--- a/src/msvc_helper_test.cc
+++ b/src/msvc_helper_test.cc
@@ -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());
+}