1919#include " importproject.h"
2020
2121#include " path.h"
22+ #include " pathmatch.h"
2223#include " settings.h"
2324#include " standards.h"
2425#include " suppressions.h"
4243
4344#include " json.h"
4445
45- // TODO: align the exclusion logic with PathMatch
46- // TODO: PathMatch lacks glob support
4746void ImportProject::ignorePaths (const std::vector<std::string> &ipaths, bool debug)
4847{
48+ PathMatch matcher (ipaths, Path::getCurrentPath ());
4949 for (auto it = fileSettings.cbegin (); it != fileSettings.cend ();) {
50- bool ignore = false ;
51- for (std::string i : ipaths) {
52- if (it->filename ().size () > i.size () && it->filename ().compare (0 ,i.size (),i)==0 ) {
53- ignore = true ;
54- break ;
55- }
56- if (isValidGlobPattern (i) && matchglob (i, it->filename ())) {
57- ignore = true ;
58- break ;
59- }
60- if (!Path::isAbsolute (i)) {
61- i = mPath + i;
62- if (it->filename ().size () > i.size () && it->filename ().compare (0 ,i.size (),i)==0 ) {
63- ignore = true ;
64- break ;
65- }
66- }
67- }
68- if (ignore) {
50+ if (matcher.match (it->filename ())) {
6951 if (debug)
7052 std::cout << " ignored path: " << it->filename () << std::endl;
7153 it = fileSettings.erase (it);
@@ -858,8 +840,9 @@ bool ImportProject::importVcxproj(const std::string &filename, const tinyxml2::X
858840 }
859841
860842 // Project files
843+ PathMatch filtermatcher (fileFilters, Path::getCurrentPath ());
861844 for (const std::string &cfilename : compileList) {
862- if (!fileFilters.empty () && !matchglobs (fileFilters, cfilename))
845+ if (!fileFilters.empty () && !filtermatcher. match ( cfilename))
863846 continue ;
864847
865848 for (const ProjectConfiguration &p : projectConfigurationList) {
@@ -937,6 +920,8 @@ ImportProject::SharedItemsProject ImportProject::importVcxitems(const std::strin
937920 SharedItemsProject result;
938921 result.pathToProjectFile = filename;
939922
923+ PathMatch filtermatcher (fileFilters, Path::getCurrentPath ());
924+
940925 tinyxml2::XMLDocument doc;
941926 const tinyxml2::XMLError error = doc.LoadFile (filename.c_str ());
942927 if (error != tinyxml2::XML_SUCCESS) {
@@ -957,8 +942,8 @@ ImportProject::SharedItemsProject ImportProject::importVcxitems(const std::strin
957942 std::string file (include);
958943 findAndReplace (file, " $(MSBuildThisFileDirectory)" , " ./" );
959944
960- // Don't include file if it matches the filter
961- if (!fileFilters.empty () && !matchglobs (fileFilters, file))
945+ // Skip file if it doesn't match the filter
946+ if (!fileFilters.empty () && !filtermatcher. match ( file))
962947 continue ;
963948
964949 result.sourceFiles .emplace_back (file);
@@ -1269,7 +1254,20 @@ static std::list<std::string> readXmlStringList(const tinyxml2::XMLElement *node
12691254 continue ;
12701255 const char *attr = attribute ? child->Attribute (attribute) : child->GetText ();
12711256 if (attr)
1272- ret.push_back (joinRelativePath (path, attr));
1257+ ret.emplace_back (joinRelativePath (path, attr));
1258+ }
1259+ return ret;
1260+ }
1261+
1262+ static std::list<std::string> readXmlPathMatchList (const tinyxml2::XMLElement *node, const std::string &path, const char name[], const char attribute[])
1263+ {
1264+ std::list<std::string> ret;
1265+ for (const tinyxml2::XMLElement *child = node->FirstChildElement (); child; child = child->NextSiblingElement ()) {
1266+ if (strcmp (child->Name (), name) != 0 )
1267+ continue ;
1268+ const char *attr = attribute ? child->Attribute (attribute) : child->GetText ();
1269+ if (attr)
1270+ ret.emplace_back (PathMatch::joinRelativePattern (path, attr));
12731271 }
12741272 return ret;
12751273}
@@ -1339,13 +1337,13 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings &setti
13391337 else if (strcmp (name, CppcheckXml::PathsElementName) == 0 )
13401338 paths = readXmlStringList (node, path, CppcheckXml::PathName, CppcheckXml::PathNameAttrib);
13411339 else if (strcmp (name, CppcheckXml::ExcludeElementName) == 0 )
1342- guiProject.excludedPaths = readXmlStringList (node, " " , CppcheckXml::ExcludePathName, CppcheckXml::ExcludePathNameAttrib); // TODO: append instead of overwrite
1340+ guiProject.excludedPaths = readXmlPathMatchList (node, path , CppcheckXml::ExcludePathName, CppcheckXml::ExcludePathNameAttrib); // TODO: append instead of overwrite
13431341 else if (strcmp (name, CppcheckXml::FunctionContracts) == 0 )
13441342 ;
13451343 else if (strcmp (name, CppcheckXml::VariableContractsElementName) == 0 )
13461344 ;
13471345 else if (strcmp (name, CppcheckXml::IgnoreElementName) == 0 )
1348- guiProject.excludedPaths = readXmlStringList (node, " " , CppcheckXml::IgnorePathName, CppcheckXml::IgnorePathNameAttrib); // TODO: append instead of overwrite
1346+ guiProject.excludedPaths = readXmlPathMatchList (node, path , CppcheckXml::IgnorePathName, CppcheckXml::IgnorePathNameAttrib); // TODO: append instead of overwrite
13491347 else if (strcmp (name, CppcheckXml::LibrariesElementName) == 0 )
13501348 guiProject.libraries = readXmlStringList (node, " " , CppcheckXml::LibraryElementName, nullptr ); // TODO: append instead of overwrite
13511349 else if (strcmp (name, CppcheckXml::SuppressionsElementName) == 0 ) {
0 commit comments