| 510 | } |
| 511 | |
| 512 | bool 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 | |
| 560 | namespace { |
| 561 | struct ProjectConfiguration { |
nothing calls this directly
no test coverage detected