19
19
#include " importproject.h"
20
20
21
21
#include " path.h"
22
+ #include " pathmatch.h"
22
23
#include " settings.h"
23
24
#include " standards.h"
24
25
#include " suppressions.h"
42
43
43
44
#include " json.h"
44
45
45
- // TODO: align the exclusion logic with PathMatch
46
- // TODO: PathMatch lacks glob support
47
46
void ImportProject::ignorePaths (const std::vector<std::string> &ipaths, bool debug)
48
47
{
48
+ PathMatch matcher (ipaths, Path::getCurrentPath ());
49
49
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 ())) {
69
51
if (debug)
70
52
std::cout << " ignored path: " << it->filename () << std::endl;
71
53
it = fileSettings.erase (it);
@@ -858,8 +840,9 @@ bool ImportProject::importVcxproj(const std::string &filename, const tinyxml2::X
858
840
}
859
841
860
842
// Project files
843
+ PathMatch filtermatcher (fileFilters, Path::getCurrentPath ());
861
844
for (const std::string &cfilename : compileList) {
862
- if (!fileFilters.empty () && !matchglobs (fileFilters, cfilename))
845
+ if (!fileFilters.empty () && !filtermatcher. match ( cfilename))
863
846
continue ;
864
847
865
848
for (const ProjectConfiguration &p : projectConfigurationList) {
@@ -937,6 +920,8 @@ ImportProject::SharedItemsProject ImportProject::importVcxitems(const std::strin
937
920
SharedItemsProject result;
938
921
result.pathToProjectFile = filename;
939
922
923
+ PathMatch filtermatcher (fileFilters, Path::getCurrentPath ());
924
+
940
925
tinyxml2::XMLDocument doc;
941
926
const tinyxml2::XMLError error = doc.LoadFile (filename.c_str ());
942
927
if (error != tinyxml2::XML_SUCCESS) {
@@ -957,8 +942,8 @@ ImportProject::SharedItemsProject ImportProject::importVcxitems(const std::strin
957
942
std::string file (include);
958
943
findAndReplace (file, " $(MSBuildThisFileDirectory)" , " ./" );
959
944
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))
962
947
continue ;
963
948
964
949
result.sourceFiles .emplace_back (file);
@@ -1269,7 +1254,20 @@ static std::list<std::string> readXmlStringList(const tinyxml2::XMLElement *node
1269
1254
continue ;
1270
1255
const char *attr = attribute ? child->Attribute (attribute) : child->GetText ();
1271
1256
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));
1273
1271
}
1274
1272
return ret;
1275
1273
}
@@ -1339,13 +1337,13 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings &setti
1339
1337
else if (strcmp (name, CppcheckXml::PathsElementName) == 0 )
1340
1338
paths = readXmlStringList (node, path, CppcheckXml::PathName, CppcheckXml::PathNameAttrib);
1341
1339
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
1343
1341
else if (strcmp (name, CppcheckXml::FunctionContracts) == 0 )
1344
1342
;
1345
1343
else if (strcmp (name, CppcheckXml::VariableContractsElementName) == 0 )
1346
1344
;
1347
1345
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
1349
1347
else if (strcmp (name, CppcheckXml::LibrariesElementName) == 0 )
1350
1348
guiProject.libraries = readXmlStringList (node, " " , CppcheckXml::LibraryElementName, nullptr ); // TODO: append instead of overwrite
1351
1349
else if (strcmp (name, CppcheckXml::SuppressionsElementName) == 0 ) {
0 commit comments