From b6588cd6ba15a700e13c1176fc838fb32dcd46cc Mon Sep 17 00:00:00 2001 From: mlangkabel Date: Fri, 15 Jun 2018 18:33:04 +0200 Subject: [PATCH] logic: added exclude filters for cbp sourcegroups --- .../SourceGroupSettingsCxxCodeblocks.cpp | 3 ++ .../SourceGroupSettingsCxxCodeblocks.h | 2 + .../project/SourceGroupCxxCodeblocks.cpp | 38 +++++++++++++++++-- src/lib_cxx/project/SourceGroupCxxEmpty.cpp | 2 - .../utility/codeblocks/CodeblocksProject.cpp | 24 +++++++----- .../utility/codeblocks/CodeblocksProject.h | 4 +- .../project_wizzard/QtProjectWizzard.cpp | 4 ++ .../QtProjectWizzardContentPaths.cpp | 2 +- 8 files changed, 62 insertions(+), 17 deletions(-) diff --git a/src/lib/settings/SourceGroupSettingsCxxCodeblocks.cpp b/src/lib/settings/SourceGroupSettingsCxxCodeblocks.cpp index e32e65cf..4a7804bf 100644 --- a/src/lib/settings/SourceGroupSettingsCxxCodeblocks.cpp +++ b/src/lib/settings/SourceGroupSettingsCxxCodeblocks.cpp @@ -16,6 +16,7 @@ void SourceGroupSettingsCxxCodeblocks::load(std::shared_ptr SourceGroupSettingsWithCppStandard::load(config, key); SourceGroupSettingsWithCStandard::load(config, key); + SourceGroupSettingsWithExcludeFilters::load(config, key); SourceGroupSettingsWithIndexedHeaderPaths::load(config, key); SourceGroupSettingsWithSourceExtensions::load(config, key); @@ -30,6 +31,7 @@ void SourceGroupSettingsCxxCodeblocks::save(std::shared_ptr confi SourceGroupSettingsWithCppStandard::save(config, key); SourceGroupSettingsWithCStandard::save(config, key); + SourceGroupSettingsWithExcludeFilters::save(config, key); SourceGroupSettingsWithIndexedHeaderPaths::save(config, key); SourceGroupSettingsWithSourceExtensions::save(config, key); @@ -45,6 +47,7 @@ bool SourceGroupSettingsCxxCodeblocks::equals(std::shared_ptrm_codeblocksProjectPath diff --git a/src/lib/settings/SourceGroupSettingsCxxCodeblocks.h b/src/lib/settings/SourceGroupSettingsCxxCodeblocks.h index e89df64b..7f70795f 100644 --- a/src/lib/settings/SourceGroupSettingsCxxCodeblocks.h +++ b/src/lib/settings/SourceGroupSettingsCxxCodeblocks.h @@ -4,6 +4,7 @@ #include "settings/SourceGroupSettingsCxx.h" #include "settings/SourceGroupSettingsWithCppStandard.h" #include "settings/SourceGroupSettingsWithCStandard.h" +#include "settings/SourceGroupSettingsWithExcludeFilters.h" #include "settings/SourceGroupSettingsWithIndexedHeaderPaths.h" #include "settings/SourceGroupSettingsWithSourceExtensions.h" @@ -11,6 +12,7 @@ class SourceGroupSettingsCxxCodeblocks : public SourceGroupSettingsCxx , public SourceGroupSettingsWithCppStandard , public SourceGroupSettingsWithCStandard + , public SourceGroupSettingsWithExcludeFilters , public SourceGroupSettingsWithIndexedHeaderPaths , public SourceGroupSettingsWithSourceExtensions { diff --git a/src/lib_cxx/project/SourceGroupCxxCodeblocks.cpp b/src/lib_cxx/project/SourceGroupCxxCodeblocks.cpp index 2a9c6d28..aac61e7a 100644 --- a/src/lib_cxx/project/SourceGroupCxxCodeblocks.cpp +++ b/src/lib_cxx/project/SourceGroupCxxCodeblocks.cpp @@ -44,16 +44,36 @@ std::set SourceGroupCxxCodeblocks::filterToContainedFilePaths(const st utility::toSet(m_settings->getIndexedHeaderPathsExpandedAndAbsolute()) ); + const std::vector excludeFilters = m_settings->getExcludeFiltersExpandedAndAbsolute(); + for (const FilePath& filePath : filePaths) { + bool isInIndexedPaths = false; for (const FilePath& indexedPath : indexedPaths) { if (indexedPath == filePath || indexedPath.contains(filePath)) { - containedFilePaths.insert(filePath); + isInIndexedPaths = true; break; } } + + if (isInIndexedPaths) + { + for (const FilePathFilter& excludeFilter : excludeFilters) + { + if (excludeFilter.isMatching(filePath)) + { + isInIndexedPaths = false; + break; + } + } + } + + if (isInIndexedPaths) + { + containedFilePaths.insert(filePath); + } } return containedFilePaths; @@ -66,9 +86,21 @@ std::set SourceGroupCxxCodeblocks::getAllSourceFilePaths() const m_settings->getCodeblocksProjectPathExpandedAndAbsolute() )) { - for (const FilePath& filePath : project->getAllSourceFilePathsCanonical(m_settings)) + const std::vector excludeFilters = m_settings->getExcludeFiltersExpandedAndAbsolute(); + + for (const FilePath& filePath : project->getAllSourceFilePathsCanonical(m_settings->getSourceExtensions())) { - if (filePath.exists()) + bool isExcluded = false; + for (const FilePathFilter& excludeFilter : excludeFilters) + { + if (excludeFilter.isMatching(filePath)) + { + isExcluded = true; + break; + } + } + + if (!isExcluded && filePath.exists()) { sourceFilePaths.insert(filePath); } diff --git a/src/lib_cxx/project/SourceGroupCxxEmpty.cpp b/src/lib_cxx/project/SourceGroupCxxEmpty.cpp index 04b03024..b24cef73 100644 --- a/src/lib_cxx/project/SourceGroupCxxEmpty.cpp +++ b/src/lib_cxx/project/SourceGroupCxxEmpty.cpp @@ -18,8 +18,6 @@ std::set SourceGroupCxxEmpty::filterToContainedFilePaths(const std::se { std::set containedFilePaths; - const std::set allSourceFilePaths = getAllSourceFilePaths(); - std::vector indexedPaths; std::vector excludeFilters; if (std::shared_ptr settings = diff --git a/src/lib_cxx/utility/codeblocks/CodeblocksProject.cpp b/src/lib_cxx/utility/codeblocks/CodeblocksProject.cpp index d5b0f133..da4deea6 100644 --- a/src/lib_cxx/utility/codeblocks/CodeblocksProject.cpp +++ b/src/lib_cxx/utility/codeblocks/CodeblocksProject.cpp @@ -126,18 +126,18 @@ namespace Codeblocks } std::set Project::getAllSourceFilePathsCanonical( - std::shared_ptr sourceGroupSettings + const std::vector& sourceExtensions ) const { - return utility::convert(getAllSourceFilePaths(sourceGroupSettings), [](const FilePath& path) { return path.getCanonical(); }); + return utility::convert(getAllSourceFilePaths(sourceExtensions), [](const FilePath& path) { return path.getCanonical(); }); } std::set Project::getAllSourceFilePaths( - std::shared_ptr sourceGroupSettings + const std::vector& sourceExtensions ) const { - const std::set sourceExtensions = utility::toSet(utility::convert( - sourceGroupSettings->getSourceExtensions(), + const std::set lowerSourceExtensions = utility::toSet(utility::convert( + sourceExtensions, [](const std::wstring& e) { return utility::toLowerCase(e); } )); @@ -147,7 +147,7 @@ namespace Codeblocks if (unit && unit->getCompile()) { FilePath filePath(unit->getFilename()); - if (sourceExtensions.find(filePath.getLowerCase().extension()) != sourceExtensions.end()) + if (lowerSourceExtensions.find(filePath.getLowerCase().extension()) != lowerSourceExtensions.end()) { filePaths.insert(filePath); } @@ -196,10 +196,16 @@ namespace Codeblocks std::shared_ptr sourceGroupSettings, std::shared_ptr appSettings) const { - const std::set sourceExtensions = utility::toSet(sourceGroupSettings->getSourceExtensions()); + + const std::set lowerSourceExtensions = utility::toSet(utility::convert( + sourceGroupSettings->getSourceExtensions(), + [](const std::wstring& e) { return utility::toLowerCase(e); } + )); const std::set indexedHeaderPaths = utility::toSet(sourceGroupSettings->getIndexedHeaderPathsExpandedAndAbsolute()); + const std::set excludeFilters = utility::toSet(sourceGroupSettings->getExcludeFiltersExpandedAndAbsolute()); + const std::vector compilerFlags = sourceGroupSettings->getCompilerFlags(); const std::vector systemHeaderSearchPaths = utility::concat( @@ -243,7 +249,7 @@ namespace Codeblocks } const FilePath filePath = FilePath(unit->getFilename()).makeCanonical(); - if (sourceExtensions.find(filePath.getLowerCase().extension()) == sourceExtensions.end()) + if (lowerSourceExtensions.find(filePath.getLowerCase().extension()) == lowerSourceExtensions.end()) { continue; } @@ -266,7 +272,7 @@ namespace Codeblocks indexerCommands.push_back(std::make_shared( filePath, utility::concat(indexedHeaderPaths, { filePath }), - std::set(), + excludeFilters, std::set(), sourceGroupSettings->getCodeblocksProjectPathExpandedAndAbsolute().getParentDirectory(), utility::concat(systemHeaderSearchPaths, headerSearchPathsCache.getValue(targetName)), diff --git a/src/lib_cxx/utility/codeblocks/CodeblocksProject.h b/src/lib_cxx/utility/codeblocks/CodeblocksProject.h index 1b918f4a..2eaa0250 100644 --- a/src/lib_cxx/utility/codeblocks/CodeblocksProject.h +++ b/src/lib_cxx/utility/codeblocks/CodeblocksProject.h @@ -25,10 +25,10 @@ namespace Codeblocks static std::shared_ptr load(std::shared_ptr xmlAccess); std::set getAllSourceFilePathsCanonical( - std::shared_ptr sourceGroupSettings + const std::vector& sourceExtensions ) const; std::set getAllSourceFilePaths( - std::shared_ptr sourceGroupSettings + const std::vector& sourceExtensions ) const; std::set getAllCxxHeaderSearchPathsCanonical() const; diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp index 307f7072..063c8de2 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp @@ -527,6 +527,8 @@ void QtProjectWizzard::selectedSourceGroupChanged(int index) summary->addSpace(); summary->addContent(new QtProjectWizzardContentIndexedHeaderPaths("Code::Blocks project", settingsCxxCodeblocks, this)); summary->addSpace(); + summary->addContent(new QtProjectWizzardContentPathsExclude(group, this)); + summary->addSpace(); summary->addContent(new QtProjectWizzardContentExtensions(settingsCxxCodeblocks, this)); } else if (std::shared_ptr settingsCxxSonargraph = std::dynamic_pointer_cast(group)) @@ -909,6 +911,8 @@ void QtProjectWizzard::emptySourceGroupCxxCodeblocks() contentGroup->addSpace(); contentGroup->addContent(new QtProjectWizzardContentIndexedHeaderPaths("Code::Blocks project", settings, window)); contentGroup->addSpace(); + contentGroup->addContent(new QtProjectWizzardContentPathsExclude(settings, window)); + contentGroup->addSpace(); contentGroup->addContent(new QtProjectWizzardContentExtensions(settings, window)); } } diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp index 0a227ba6..8075a55c 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp @@ -316,7 +316,7 @@ std::vector QtProjectWizzardContentIndexedHeaderPaths::getIndexedPaths return path.getCanonical(); }); - for (const FilePath& path : codeblocksProject->getAllSourceFilePaths(settings)) + for (const FilePath& path : codeblocksProject->getAllSourceFilePaths(settings->getSourceExtensions())) { indexedHeaderPaths.insert(canonicalDirectoryPathCache.getValue(path.getParentDirectory())); }