Commit 44054a1e authored by Joey Scarr's avatar Joey Scarr Committed by Commit Bot

Fix quoting when writing defines on Windows.

For the following string-valued define:
 defines = [ "CR_CLANG_REVISION=\"$clang_revision\"" ]
this was outputting the following on Windows:
 -D"CR_CLANG_REVISION=\"332838-1\""
The Windows shell can't handle the extra quotes, and so the following
macro was being written:
 #define "CR_CLANG_REVISION "332838-1""
This change moves the first quote to before the -D, allowing Windows to
correctly handle the define parameter.

R=brettw@chromium.org

Bug: 396230
Change-Id: I4f6f70acf775577ff9b3077eba9ebf7f8d002da1
Reviewed-on: https://chromium-review.googlesource.com/1071274Reviewed-by: default avatarBrett Wilson <brettw@chromium.org>
Commit-Queue: Joey Scarr <jsca@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565117}
parent 7cebf831
...@@ -60,8 +60,8 @@ struct DefineWriter { ...@@ -60,8 +60,8 @@ struct DefineWriter {
} }
void operator()(const std::string& s, std::ostream& out) const { void operator()(const std::string& s, std::ostream& out) const {
out << " -D"; out << " ";
EscapeStringToStream(out, s, options); EscapeStringToStream(out, "-D" + s, options);
} }
EscapeOptions options; EscapeOptions options;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <sstream> #include <sstream>
#include <utility> #include <utility>
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "tools/gn/config.h" #include "tools/gn/config.h"
#include "tools/gn/scheduler.h" #include "tools/gn/scheduler.h"
...@@ -150,6 +151,30 @@ TEST_F(NinjaBinaryTargetWriterTest, SourceSet) { ...@@ -150,6 +151,30 @@ TEST_F(NinjaBinaryTargetWriterTest, SourceSet) {
} }
} }
TEST_F(NinjaBinaryTargetWriterTest, EscapeDefines) {
TestWithScope setup;
Err err;
TestTarget target(setup, "//foo:bar", Target::STATIC_LIBRARY);
target.config_values().defines().push_back("BOOL_DEF");
target.config_values().defines().push_back("INT_DEF=123");
target.config_values().defines().push_back("STR_DEF=\"ABCD-1\"");
ASSERT_TRUE(target.OnResolved(&err));
std::ostringstream out;
NinjaBinaryTargetWriter writer(&target, out);
writer.Run();
const char expectedSubstr[] =
#if defined(OS_WIN)
"defines = -DBOOL_DEF -DINT_DEF=123 \"-DSTR_DEF=\\\"ABCD-1\\\"\"";
#else
"defines = -DBOOL_DEF -DINT_DEF=123 -DSTR_DEF=\\\"ABCD-1\\\"";
#endif
std::string out_str = out.str();
EXPECT_PRED_FORMAT2(testing::IsSubstring, expectedSubstr, out_str);
}
TEST_F(NinjaBinaryTargetWriterTest, StaticLibrary) { TEST_F(NinjaBinaryTargetWriterTest, StaticLibrary) {
TestWithScope setup; TestWithScope setup;
Err err; Err err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment