diff options
-rw-r--r-- | src/msvc_helper-win32.cc | 24 | ||||
-rw-r--r-- | src/msvc_helper.h | 5 | ||||
-rw-r--r-- | src/msvc_helper_main-win32.cc | 4 | ||||
-rw-r--r-- | 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<string> CLWrapper::GetEscapedResult() { + vector<string> result; + for (set<string>::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 <string> #include <set> +#include <vector> 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<string> GetEscapedResult(); + void* env_block_; set<string> 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<string>::iterator i = cl.includes_.begin(); - i != cl.includes_.end(); ++i) { + vector<string> headers = cl.GetEscapedResult(); + for (vector<string>::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<string> headers = cl.GetEscapedResult(); + ASSERT_EQ(1u, headers.size()); + ASSERT_EQ("sub\\some\\ sdk\\foo.h", headers[0]); +} |