Fixed #10887 (compile database: include path with space is not handled)

This commit is contained in:
Daniel Marjamäki 2022-03-23 21:13:51 +01:00
parent 92316b07c8
commit 3bcbba598d
2 changed files with 26 additions and 2 deletions

View File

@ -414,7 +414,10 @@ bool ImportProject::importCompileCommands(std::istream &istr)
if (obj["arguments"].is<picojson::array>()) { if (obj["arguments"].is<picojson::array>()) {
for (const picojson::value& arg : obj["arguments"].get<picojson::array>()) { for (const picojson::value& arg : obj["arguments"].get<picojson::array>()) {
if (arg.is<std::string>()) { if (arg.is<std::string>()) {
command += arg.get<std::string>() + " "; std::string str = arg.get<std::string>();
if (str.find(" ") != std::string::npos)
str = "\"" + str + "\"";
command += str + " ";
} }
} }
} else { } else {

View File

@ -58,6 +58,7 @@ private:
TEST_CASE(importCompileCommands7); // linux: "/home/danielm/cppcheck 2" TEST_CASE(importCompileCommands7); // linux: "/home/danielm/cppcheck 2"
TEST_CASE(importCompileCommands8); // Windows: "C:\Users\danielm\cppcheck" TEST_CASE(importCompileCommands8); // Windows: "C:\Users\danielm\cppcheck"
TEST_CASE(importCompileCommands9); TEST_CASE(importCompileCommands9);
TEST_CASE(importCompileCommands10); // #10887: include path with space
TEST_CASE(importCompileCommandsArgumentsSection); // Handle arguments section TEST_CASE(importCompileCommandsArgumentsSection); // Handle arguments section
TEST_CASE(importCompileCommandsNoCommandSection); // gracefully handles malformed json TEST_CASE(importCompileCommandsNoCommandSection); // gracefully handles malformed json
TEST_CASE(importCppcheckGuiProject); TEST_CASE(importCppcheckGuiProject);
@ -254,13 +255,33 @@ private:
"powershell.exe -WindowStyle Hidden -NoProfile -ExecutionPolicy Bypass -File d:\\Projekte\\xyz\\firmware\\app\\xyz-lib\\build.ps1 -IAR -COMPILER_PATH \"c:\\Program Files (x86)\\IAR Systems\\Embedded Workbench 9.0\" -CONTROLLER CC1310F128 -LIB LIB_PERMANENT -COMPILER_DEFINES \"CC1310_HFXO_FREQ=24000000 DEBUG\"" "powershell.exe -WindowStyle Hidden -NoProfile -ExecutionPolicy Bypass -File d:\\Projekte\\xyz\\firmware\\app\\xyz-lib\\build.ps1 -IAR -COMPILER_PATH \"c:\\Program Files (x86)\\IAR Systems\\Embedded Workbench 9.0\" -CONTROLLER CC1310F128 -LIB LIB_PERMANENT -COMPILER_DEFINES \"CC1310_HFXO_FREQ=24000000 DEBUG\""
], ],
"directory" : "d:\\Projekte\\xyz\\firmware\\app", "directory" : "d:\\Projekte\\xyz\\firmware\\app",
"type" : "PRE" "type" : "PRE",
"file": "1.c"
}])"; }])";
std::istringstream istr(json); std::istringstream istr(json);
TestImporter importer; TestImporter importer;
ASSERT_EQUALS(true, importer.importCompileCommands(istr)); ASSERT_EQUALS(true, importer.importCompileCommands(istr));
} }
void importCompileCommands10() const { // #10887
const char json[] =
R"([{
"file": "/home/danielm/cppcheck/1/test folder/1.c" ,
"directory": "",
"arguments": [
"iccavr.exe",
"-I",
"/home/danielm/cppcheck/test folder"
]
}])";
std::istringstream istr(json);
TestImporter importer;
ASSERT_EQUALS(true, importer.importCompileCommands(istr));
ASSERT_EQUALS(1, importer.fileSettings.size());
const ImportProject::FileSettings &fs = importer.fileSettings.front();
ASSERT_EQUALS("/home/danielm/cppcheck/test folder/", fs.includePaths.front());
}
void importCompileCommandsArgumentsSection() const { void importCompileCommandsArgumentsSection() const {
const char json[] = "[ { \"directory\": \"/tmp/\"," const char json[] = "[ { \"directory\": \"/tmp/\","
"\"arguments\": [\"gcc\", \"-c\", \"src.c\"]," "\"arguments\": [\"gcc\", \"-c\", \"src.c\"],"