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

Method importVcxitems

lib/importproject.cpp:1066–1128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1064}
1065
1066ImportProject::SharedItemsProject ImportProject::importVcxitems(const std::string& filename, const std::vector<std::string>& fileFilters, std::vector<SharedItemsProject> &cache)
1067{
1068 auto isInCacheCheck = [filename](const ImportProject::SharedItemsProject& e) -> bool {
1069 return filename == e.pathToProjectFile;
1070 };
1071 const auto iterator = std::find_if(cache.begin(), cache.end(), isInCacheCheck);
1072 if (iterator != std::end(cache)) {
1073 return *iterator;
1074 }
1075
1076 SharedItemsProject result;
1077 result.pathToProjectFile = filename;
1078
1079 PathMatch filtermatcher(fileFilters, Path::getCurrentPath());
1080
1081 tinyxml2::XMLDocument doc;
1082 const tinyxml2::XMLError error = doc.LoadFile(filename.c_str());
1083 if (error != tinyxml2::XML_SUCCESS) {
1084 errors.emplace_back(std::string("Visual Studio project file is not a valid XML - ") + tinyxml2::XMLDocument::ErrorIDToName(error));
1085 return result;
1086 }
1087 const tinyxml2::XMLElement * const rootnode = doc.FirstChildElement();
1088 if (rootnode == nullptr) {
1089 errors.emplace_back("Visual Studio project file has no XML root node");
1090 return result;
1091 }
1092 for (const tinyxml2::XMLElement *node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) {
1093 if (std::strcmp(node->Name(), "ItemGroup") == 0) {
1094 for (const tinyxml2::XMLElement *e = node->FirstChildElement(); e; e = e->NextSiblingElement()) {
1095 if (std::strcmp(e->Name(), "ClCompile") == 0) {
1096 const char* include = e->Attribute("Include");
1097 if (include && Path::acceptFile(include)) {
1098 std::string file(include);
1099 findAndReplace(file, "$(MSBuildThisFileDirectory)", "./");
1100
1101 // Skip file if it doesn't match the filter
1102 if (!fileFilters.empty() && !filtermatcher.match(file))
1103 continue;
1104
1105 result.sourceFiles.emplace_back(file);
1106 } else {
1107 errors.emplace_back("Could not find shared items source file");
1108 return result;
1109 }
1110 }
1111 }
1112 } else if (std::strcmp(node->Name(), "ItemDefinitionGroup") == 0) {
1113 ItemDefinitionGroup temp(node, "");
1114 for (const auto& includePath : toStringList(temp.additionalIncludePaths)) {
1115 if (includePath == "%(AdditionalIncludeDirectories)")
1116 continue;
1117
1118 std::string toAdd(includePath);
1119 findAndReplace(toAdd, "$(MSBuildThisFileDirectory)", "./");
1120 result.includePaths.emplace_back(toAdd);
1121 }
1122 }
1123 }

Callers

nothing calls this directly

Calls 13

acceptFileFunction · 0.85
findAndReplaceFunction · 0.85
toStringListFunction · 0.85
LoadFileMethod · 0.80
FirstChildElementMethod · 0.80
NextSiblingElementMethod · 0.80
NameMethod · 0.80
AttributeMethod · 0.80
endFunction · 0.70
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected