Skip to content

Commit

Permalink
don't emit duplicate headers for msvc helper
Browse files Browse the repository at this point in the history
  • Loading branch information
sgraham committed Sep 17, 2012
1 parent d95fcb0 commit 0adc699
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/msvc_helper-win32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/msvc_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,5 +50,5 @@ struct CLWrapper {
static bool FilterInputFilename(const string& line);

void* env_block_;
vector<string> includes_;
set<string> includes_;
};
2 changes: 1 addition & 1 deletion src/msvc_helper_main-win32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
28 changes: 26 additions & 2 deletions src/msvc_helper_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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 0adc699

Please sign in to comment.