diff options
author | Evan Martin <martine@danga.com> | 2012-09-20 21:47:32 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2012-09-20 21:47:32 (GMT) |
commit | d0ac9ded9d577c9a9e6fffd3921c6100c8a20b6b (patch) | |
tree | e50ef9863b205c0f1daa8d0f103c7bfac6a86545 /src | |
parent | e6c8bd91c22b64374aa7a1c84ae0a462f4fe2896 (diff) | |
parent | 490934575c475b8e6f6453136cacb0bac633ccfb (diff) | |
download | Ninja-d0ac9ded9d577c9a9e6fffd3921c6100c8a20b6b.zip Ninja-d0ac9ded9d577c9a9e6fffd3921c6100c8a20b6b.tar.gz Ninja-d0ac9ded9d577c9a9e6fffd3921c6100c8a20b6b.tar.bz2 |
Merge pull request #426 from sgraham/spaces-in-headers-2
fix spaces in headers for -t msvc
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 a9f34aa..ee260ab 100644 --- a/src/msvc_helper-win32.cc +++ b/src/msvc_helper-win32.cc @@ -28,6 +28,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 @@ -162,3 +177,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 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]); +} |