diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/msvc_helper-win32.cc | 23 | ||||
-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, 41 insertions, 2 deletions
diff --git a/src/msvc_helper-win32.cc b/src/msvc_helper-win32.cc index e5c47a1..fd9b671 100644 --- a/src/msvc_helper-win32.cc +++ b/src/msvc_helper-win32.cc @@ -29,6 +29,21 @@ bool EndsWith(const string& input, const string& needle) { input.substr(input.size() - needle.size()) == needle); } +string Replace(const string& input, const string& find, const string& replace) { + string result = input; + size_t start_pos = 0; + while ((start_pos = result.find(find, start_pos)) != string::npos) { + result.replace(start_pos, find.length(), replace); + start_pos += replace.length(); + } + return result; +} + +string EscapeForDepfile(const string& path) { + // Depfiles don't escape single \. + return Replace(path, " ", "\\ "); +} + } // anonymous namespace // static @@ -163,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(EscapeForDepfile(*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 78b7f4b..4a4b3c4 100644 --- a/src/msvc_helper_main-win32.cc +++ b/src/msvc_helper_main-win32.cc @@ -106,8 +106,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]); +} |