From 21046b4a3e153754ab8f632c0b65ec1c61f7b828 Mon Sep 17 00:00:00 2001 From: Scott Graham Date: Wed, 19 Sep 2012 17:15:55 -0700 Subject: fix spaces in headers for -t msvc --- src/msvc_helper-win32.cc | 24 ++++++++++++++++++++++++ src/msvc_helper.h | 5 +++++ src/msvc_helper_main-win32.cc | 4 ++-- src/msvc_helper_test.cc | 11 +++++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/msvc_helper-win32.cc b/src/msvc_helper-win32.cc index a9f34aa..e2a121d 100644 --- a/src/msvc_helper-win32.cc +++ b/src/msvc_helper-win32.cc @@ -28,6 +28,22 @@ bool EndsWith(const string& input, const string& needle) { input.substr(input.size() - needle.size()) == needle); } +void Replace(string& in_out, const string& find, const string& replace) { + size_t start_pos = 0; + while ((start_pos = in_out.find(find, start_pos)) != std::string::npos) { + in_out.replace(start_pos, find.length(), replace); + start_pos += replace.length(); + } +} + +string Escape(const string& path) { + string result = path; + // TODO: very strange format, should we escape \ too? + //Replace(result, "\\", "\\\\"); + Replace(result, " ", "\\ "); + return result; +} + } // anonymous namespace // static @@ -162,3 +178,11 @@ int CLWrapper::Run(const string& command, string* extra_output) { return exit_code; } + +vector CLWrapper::GetEscapedResult() { + vector result; + for (set::iterator i = includes_.begin(); i != includes_.end(); ++i) { + result.push_back(Escape(*i)); + } + return result; +} diff --git a/src/msvc_helper.h b/src/msvc_helper.h index c68f631..102201b 100644 --- a/src/msvc_helper.h +++ b/src/msvc_helper.h @@ -14,6 +14,7 @@ #include #include +#include using namespace std; /// Visual Studio's cl.exe requires some massaging to work with Ninja; @@ -49,6 +50,10 @@ struct CLWrapper { /// Exposed for testing. static bool FilterInputFilename(const string& line); + /// Fill a vector with the unique'd headers, escaped for output as a .d + /// file. + vector GetEscapedResult(); + void* env_block_; set includes_; }; diff --git a/src/msvc_helper_main-win32.cc b/src/msvc_helper_main-win32.cc index ed7674c..5e28e6d 100644 --- a/src/msvc_helper_main-win32.cc +++ b/src/msvc_helper_main-win32.cc @@ -105,8 +105,8 @@ int MSVCHelperMain(int argc, char** argv) { Fatal("opening %s: %s", depfile.c_str(), GetLastErrorString().c_str()); } fprintf(output, "%s: ", output_filename); - for (set::iterator i = cl.includes_.begin(); - i != cl.includes_.end(); ++i) { + vector headers = cl.GetEscapedResult(); + for (vector::iterator i = headers.begin(); i != headers.end(); ++i) { fprintf(output, "%s\n", i->c_str()); } fclose(output); diff --git a/src/msvc_helper_test.cc b/src/msvc_helper_test.cc index 85ac039..7730425 100644 --- a/src/msvc_helper_test.cc +++ b/src/msvc_helper_test.cc @@ -105,3 +105,14 @@ TEST(MSVCHelperTest, DuplicatedHeaderPathConverted) { ASSERT_EQ("", output); ASSERT_EQ(2u, cl.includes_.size()); } + +TEST(MSVCHelperTest, SpacesInFilename) { + CLWrapper cl; + string output; + cl.Run("cmd /c \"echo Note: including file: sub\\some sdk\\foo.h", + &output); + ASSERT_EQ("", output); + vector headers = cl.GetEscapedResult(); + ASSERT_EQ(1u, headers.size()); + ASSERT_EQ("sub\\some\\ sdk\\foo.h", headers[0]); +} -- cgit v0.12