| 1444 | } |
| 1445 | |
| 1446 | bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings &settings, Suppressions &supprs) |
| 1447 | { |
| 1448 | tinyxml2::XMLDocument doc; |
| 1449 | const std::string xmldata = istream_to_string(istr); |
| 1450 | const tinyxml2::XMLError error = doc.Parse(xmldata.data(), xmldata.size()); |
| 1451 | if (error != tinyxml2::XML_SUCCESS) { |
| 1452 | errors.emplace_back(std::string("Cppcheck GUI project file is not a valid XML - ") + tinyxml2::XMLDocument::ErrorIDToName(error)); |
| 1453 | return false; |
| 1454 | } |
| 1455 | const tinyxml2::XMLElement * const rootnode = doc.FirstChildElement(); |
| 1456 | if (rootnode == nullptr || strcmp(rootnode->Name(), CppcheckXml::ProjectElementName) != 0) { |
| 1457 | errors.emplace_back("Cppcheck GUI project file has no XML root node"); |
| 1458 | return false; |
| 1459 | } |
| 1460 | |
| 1461 | const std::string &path = mPath; |
| 1462 | |
| 1463 | std::list<std::string> paths; |
| 1464 | std::list<SuppressionList::Suppression> suppressions; |
| 1465 | Settings temp; |
| 1466 | |
| 1467 | // default to --check-level=normal for import for now |
| 1468 | temp.setCheckLevel(Settings::CheckLevel::normal); |
| 1469 | |
| 1470 | // TODO: this should support all available command-line options |
| 1471 | for (const tinyxml2::XMLElement *node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) { |
| 1472 | const char* name = node->Name(); |
| 1473 | if (strcmp(name, CppcheckXml::RootPathName) == 0) { |
| 1474 | const char* attr = node->Attribute(CppcheckXml::RootPathNameAttrib); |
| 1475 | if (attr) { |
| 1476 | temp.basePaths.push_back(Path::fromNativeSeparators(joinRelativePath(path, attr))); |
| 1477 | temp.relativePaths = true; |
| 1478 | } |
| 1479 | } else if (strcmp(name, CppcheckXml::BuildDirElementName) == 0) |
| 1480 | temp.buildDir = joinRelativePath(path, empty_if_null(node->GetText())); |
| 1481 | else if (strcmp(name, CppcheckXml::IncludeDirElementName) == 0) |
| 1482 | temp.includePaths = readXmlStringList(node, path, CppcheckXml::DirElementName, CppcheckXml::DirNameAttrib); // TODO: append instead of overwrite |
| 1483 | else if (strcmp(name, CppcheckXml::DefinesElementName) == 0) |
| 1484 | temp.userDefines = join(readXmlStringList(node, "", CppcheckXml::DefineName, CppcheckXml::DefineNameAttrib), ";"); // TODO: append instead of overwrite |
| 1485 | else if (strcmp(name, CppcheckXml::UndefinesElementName) == 0) { |
| 1486 | for (const std::string &u : readXmlStringList(node, "", CppcheckXml::UndefineName, nullptr)) |
| 1487 | temp.userUndefs.insert(u); |
| 1488 | } else if (strcmp(name, CppcheckXml::UserIncludeElementName) == 0) { |
| 1489 | const char* i = node->GetText(); |
| 1490 | if (i) |
| 1491 | temp.userIncludes.emplace_back(i); |
| 1492 | } else if (strcmp(name, CppcheckXml::ImportProjectElementName) == 0) { |
| 1493 | const std::string t_str = empty_if_null(node->GetText()); |
| 1494 | if (!t_str.empty()) |
| 1495 | guiProject.projectFile = path + t_str; |
| 1496 | } |
| 1497 | else if (strcmp(name, CppcheckXml::PathsElementName) == 0) |
| 1498 | paths = readXmlStringList(node, path, CppcheckXml::PathName, CppcheckXml::PathNameAttrib); |
| 1499 | else if (strcmp(name, CppcheckXml::ExcludeElementName) == 0) |
| 1500 | guiProject.excludedPaths = readXmlPathMatchList(node, path, CppcheckXml::ExcludePathName, CppcheckXml::ExcludePathNameAttrib); // TODO: append instead of overwrite |
| 1501 | else if (strcmp(name, CppcheckXml::FunctionContracts) == 0) |
| 1502 | ; |
| 1503 | else if (strcmp(name, CppcheckXml::VariableContractsElementName) == 0) |
nothing calls this directly
no test coverage detected