Import project: Speed up if --file-filter has been provided

This commit is contained in:
Daniel Marjamäki 2020-05-24 21:23:49 +02:00
parent ff17cc2e8f
commit e448cc68b5
2 changed files with 12 additions and 8 deletions

View File

@ -200,11 +200,11 @@ ImportProject::Type ImportProject::import(const std::string &filename, Settings
importCompileCommands(fin); importCompileCommands(fin);
return ImportProject::Type::COMPILE_DB; return ImportProject::Type::COMPILE_DB;
} else if (endsWith(filename, ".sln", 4)) { } else if (endsWith(filename, ".sln", 4)) {
importSln(fin,mPath); importSln(fin, mPath, settings->fileFilter);
return ImportProject::Type::VS_SLN; return ImportProject::Type::VS_SLN;
} else if (endsWith(filename, ".vcxproj", 8)) { } else if (endsWith(filename, ".vcxproj", 8)) {
std::map<std::string, std::string, cppcheck::stricmp> variables; std::map<std::string, std::string, cppcheck::stricmp> variables;
importVcxproj(filename, variables, emptyString); importVcxproj(filename, variables, emptyString, settings->fileFilter);
return ImportProject::Type::VS_VCXPROJ; return ImportProject::Type::VS_VCXPROJ;
} else if (endsWith(filename, ".bpr", 4)) { } else if (endsWith(filename, ".bpr", 4)) {
importBcb6Prj(filename); importBcb6Prj(filename);
@ -401,7 +401,7 @@ void ImportProject::importCompileCommands(std::istream &istr)
} }
} }
void ImportProject::importSln(std::istream &istr, const std::string &path) void ImportProject::importSln(std::istream &istr, const std::string &path, const std::string &fileFilter)
{ {
std::map<std::string,std::string,cppcheck::stricmp> variables; std::map<std::string,std::string,cppcheck::stricmp> variables;
variables["SolutionDir"] = path; variables["SolutionDir"] = path;
@ -419,7 +419,7 @@ void ImportProject::importSln(std::istream &istr, const std::string &path)
std::string vcxproj(line.substr(pos1+1, pos-pos1+7)); std::string vcxproj(line.substr(pos1+1, pos-pos1+7));
if (!Path::isAbsolute(vcxproj)) if (!Path::isAbsolute(vcxproj))
vcxproj = path + vcxproj; vcxproj = path + vcxproj;
importVcxproj(Path::fromNativeSeparators(vcxproj), variables, emptyString); importVcxproj(Path::fromNativeSeparators(vcxproj), variables, emptyString, fileFilter);
} }
} }
@ -602,7 +602,7 @@ static void loadVisualStudioProperties(const std::string &props, std::map<std::s
} }
} }
void ImportProject::importVcxproj(const std::string &filename, std::map<std::string, std::string, cppcheck::stricmp> &variables, const std::string &additionalIncludeDirectories) void ImportProject::importVcxproj(const std::string &filename, std::map<std::string, std::string, cppcheck::stricmp> &variables, const std::string &additionalIncludeDirectories, const std::string &fileFilter)
{ {
variables["ProjectDir"] = Path::simplifyPath(Path::getPathFromFilename(filename)); variables["ProjectDir"] = Path::simplifyPath(Path::getPathFromFilename(filename));
@ -661,6 +661,10 @@ void ImportProject::importVcxproj(const std::string &filename, std::map<std::str
} }
for (const std::string &c : compileList) { for (const std::string &c : compileList) {
const std::string cfilename = Path::simplifyPath(Path::isAbsolute(c) ? c : Path::getPathFromFilename(filename) + c);
if (!fileFilter.empty() && !matchglob(fileFilter, cfilename))
continue;
for (const ProjectConfiguration &p : projectConfigurationList) { for (const ProjectConfiguration &p : projectConfigurationList) {
if (!guiProject.checkVsConfigs.empty()) { if (!guiProject.checkVsConfigs.empty()) {
@ -675,7 +679,7 @@ void ImportProject::importVcxproj(const std::string &filename, std::map<std::str
} }
FileSettings fs; FileSettings fs;
fs.filename = Path::simplifyPath(Path::isAbsolute(c) ? c : Path::getPathFromFilename(filename) + c); fs.filename = cfilename;
fs.cfg = p.name; fs.cfg = p.name;
fs.msc = true; fs.msc = true;
fs.useMfc = useOfMfc; fs.useMfc = useOfMfc;

View File

@ -109,8 +109,8 @@ protected:
void importCompileCommands(std::istream &istr); void importCompileCommands(std::istream &istr);
bool importCppcheckGuiProject(std::istream &istr, Settings *settings); bool importCppcheckGuiProject(std::istream &istr, Settings *settings);
private: private:
void importSln(std::istream &istr, const std::string &path); void importSln(std::istream &istr, const std::string &path, const std::string &fileFilter);
void importVcxproj(const std::string &filename, std::map<std::string, std::string, cppcheck::stricmp> &variables, const std::string &additionalIncludeDirectories); void importVcxproj(const std::string &filename, std::map<std::string, std::string, cppcheck::stricmp> &variables, const std::string &additionalIncludeDirectories, const std::string &fileFilter);
void importBcb6Prj(const std::string &projectFilename); void importBcb6Prj(const std::string &projectFilename);
std::string mPath; std::string mPath;