MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / importSlnx

Method importSlnx

lib/importproject.cpp:512–558  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

510}
511
512bool ImportProject::importSlnx(const std::string& filename, const std::vector<std::string>& fileFilters)
513{
514 tinyxml2::XMLDocument doc;
515 const tinyxml2::XMLError error = doc.LoadFile(filename.c_str());
516 if (error != tinyxml2::XML_SUCCESS) {
517 errors.emplace_back(std::string("Visual Studio solution file is not a valid XML - ") + tinyxml2::XMLDocument::ErrorIDToName(error));
518 return false;
519 }
520
521 const tinyxml2::XMLElement* const rootnode = doc.FirstChildElement();
522 if (rootnode == nullptr) {
523 errors.emplace_back("Visual Studio solution file has no XML root node");
524 return false;
525 }
526
527 std::map<std::string, std::string, cppcheck::stricmp> variables;
528 variables["SolutionDir"] = Path::simplifyPath(Path::getPathFromFilename(filename));
529
530 bool found = false;
531 std::vector<SharedItemsProject> sharedItemsProjects;
532
533 for (const tinyxml2::XMLElement* node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) {
534 const char* name = node->Name();
535 if (std::strcmp(name, "Project") == 0) {
536 const char* labelAttribute = node->Attribute("Path");
537 if (labelAttribute) {
538 std::string vcxproj(labelAttribute);
539 vcxproj = Path::toNativeSeparators(std::move(vcxproj));
540 if (!Path::isAbsolute(vcxproj))
541 vcxproj = variables["SolutionDir"] + vcxproj;
542 vcxproj = Path::fromNativeSeparators(std::move(vcxproj));
543 if (!importVcxproj(vcxproj, variables, "", fileFilters, sharedItemsProjects)) {
544 errors.emplace_back("failed to load '" + vcxproj + "' from Visual Studio solution");
545 return false;
546 }
547 found = true;
548 }
549 }
550 }
551
552 if (!found) {
553 errors.emplace_back("no projects found in Visual Studio solution file");
554 return false;
555 }
556
557 return true;
558}
559
560namespace {
561 struct ProjectConfiguration {

Callers

nothing calls this directly

Calls 6

simplifyPathFunction · 0.85
LoadFileMethod · 0.80
FirstChildElementMethod · 0.80
NextSiblingElementMethod · 0.80
NameMethod · 0.80
AttributeMethod · 0.80

Tested by

no test coverage detected