Hi klimek,
The command line argument unescaper now only skips over a backslash if
the next character is a double quote character. This matches the
compilation database spec and the compilation databases generated by
tools like Ninja and CMake.
http://reviews.llvm.org/D6376
Files:
lib/Tooling/JSONCompilationDatabase.cpp
unittests/Tooling/CompilationDatabaseTest.cpp
Index: lib/Tooling/JSONCompilationDatabase.cpp
===================================================================
--- lib/Tooling/JSONCompilationDatabase.cpp
+++ lib/Tooling/JSONCompilationDatabase.cpp
@@ -89,7 +89,9 @@
bool skipEscapeCharacter() {
if (*Position == '\\') {
- return next();
+ if (next() && *Position == '"')
+ return true;
+ --Position;
}
return true;
}
Index: unittests/Tooling/CompilationDatabaseTest.cpp
===================================================================
--- unittests/Tooling/CompilationDatabaseTest.cpp
+++ unittests/Tooling/CompilationDatabaseTest.cpp
@@ -90,10 +90,10 @@
StringRef Directory1("//net/dir1");
StringRef FileName1("file1");
- StringRef Command1("command1");
+ StringRef Command1(R"(command1 -DFOO=\"1\\2\\\" \" -DBAR=\\)");
StringRef Directory2("//net/dir2");
StringRef FileName2("file1");
- StringRef Command2("command1");
+ StringRef Command2(R"(command2 \"with spaces\")");
std::vector<CompileCommand> Commands = getAllCompileCommands(
("[{\"directory\":\"" + Directory1 + "\"," +
@@ -103,13 +103,16 @@
"\"command\":\"" + Command2 + "\","
"\"file\":\"" + FileName2 + "\"}]").str(),
ErrorMessage);
- EXPECT_EQ(2U, Commands.size()) << ErrorMessage;
+ EXPECT_EQ(2u, Commands.size()) << ErrorMessage;
EXPECT_EQ(Directory1, Commands[0].Directory) << ErrorMessage;
- ASSERT_EQ(1u, Commands[0].CommandLine.size());
- EXPECT_EQ(Command1, Commands[0].CommandLine[0]) << ErrorMessage;
+ ASSERT_EQ(3u, Commands[0].CommandLine.size());
+ EXPECT_EQ("command1", Commands[0].CommandLine[0]) << ErrorMessage;
+ EXPECT_EQ(R"(-DFOO=1\2" )", Commands[0].CommandLine[1]) << ErrorMessage;
+ EXPECT_EQ(R"(-DBAR=\)", Commands[0].CommandLine[2]) << ErrorMessage;
EXPECT_EQ(Directory2, Commands[1].Directory) << ErrorMessage;
- ASSERT_EQ(1u, Commands[1].CommandLine.size());
- EXPECT_EQ(Command2, Commands[1].CommandLine[0]) << ErrorMessage;
+ ASSERT_EQ(2u, Commands[1].CommandLine.size());
+ EXPECT_EQ("command2", Commands[1].CommandLine[0]) << ErrorMessage;
+ EXPECT_EQ("with spaces", Commands[1].CommandLine[1]) << ErrorMessage;
}
static CompileCommand findCompileArgsInJsonDatabase(StringRef FileName,
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits