Import Project: Fix problem with define value with space

This commit is contained in:
Daniel Marjamäki 2022-04-15 14:16:17 +02:00
parent ef8a499c8d
commit 392741715b
2 changed files with 23 additions and 1 deletions

View File

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

View File

@ -61,6 +61,7 @@ private:
TEST_CASE(importCompileCommands9);
TEST_CASE(importCompileCommands10); // #10887: include path with space
TEST_CASE(importCompileCommands11); // include path order
TEST_CASE(importCompileCommands12); // defines
TEST_CASE(importCompileCommandsArgumentsSection); // Handle arguments section
TEST_CASE(importCompileCommandsNoCommandSection); // gracefully handles malformed json
TEST_CASE(importCppcheckGuiProject);
@ -307,6 +308,27 @@ private:
ASSERT_EQUALS("/x/abc/", fs.includePaths.back());
}
void importCompileCommands12() const { // define
const char json[] =
R"([{
"file": "1.c" ,
"directory": "/x",
"arguments": [
"cc",
"-D",
"X=1",
"-D",
"__VERSION__=\"IAR C/C++ Compiler V6.40.2.748 for Atmel AVR\""
]
}])";
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("X=1;__VERSION__=IAR C/C++ Compiler V6.40.2.748 for Atmel AVR", fs.defines);
}
void importCompileCommandsArgumentsSection() const {
const char json[] = "[ { \"directory\": \"/tmp/\","
"\"arguments\": [\"gcc\", \"-c\", \"src.c\"],"