From 648caa9c35da0e453e13ccf5549b03def79f8b9a Mon Sep 17 00:00:00 2001 From: mlangkabel Date: Tue, 10 Apr 2018 15:52:02 +0200 Subject: [PATCH] logic: fixed bug where adding an empty include path excludes everything --- src/lib/settings/SourceGroupSettings.cpp | 66 +++++++++++---------- src/lib/utility/file/FilePathFilter.h | 2 +- src/lib_cxx/project/SourceGroupCxxCdb.cpp | 6 +- src/lib_cxx/project/SourceGroupCxxEmpty.cpp | 4 +- 4 files changed, 40 insertions(+), 38 deletions(-) diff --git a/src/lib/settings/SourceGroupSettings.cpp b/src/lib/settings/SourceGroupSettings.cpp index 72dddb8f..fa528dcc 100644 --- a/src/lib/settings/SourceGroupSettings.cpp +++ b/src/lib/settings/SourceGroupSettings.cpp @@ -157,52 +157,54 @@ std::vector SourceGroupSettings::getExcludeFiltersExpandedAndAbs { std::vector result; - for (const FilePathFilter& filter : m_excludeFilters) + for (const std::wstring& filterString : m_excludeFilters) { - const std::wstring filterString = filter.wstr(); - const size_t wildcardPos = filterString.find(L"*"); - if (wildcardPos != filterString.npos) + if (!filterString.empty()) { - std::wsmatch match; - if (std::regex_search(filterString, match, std::wregex(L"[\\\\/]")) && !match.empty() && - match.position(0) < int(wildcardPos)) + const size_t wildcardPos = filterString.find(L"*"); + if (wildcardPos != filterString.npos) { - const FilePath p = m_projectSettings->makePathExpandedAndAbsolute(FilePath(match.prefix().str())); + std::wsmatch match; + if (std::regex_search(filterString, match, std::wregex(L"[\\\\/]")) && !match.empty() && + match.position(0) < int(wildcardPos)) + { + const FilePath p = m_projectSettings->makePathExpandedAndAbsolute(FilePath(match.prefix().str())); + std::set symLinkPaths = FileSystem::getSymLinkedDirectories(p); + symLinkPaths.insert(p); + + utility::append(result, + utility::convert( + utility::toVector(symLinkPaths), + [match](const FilePath& filePath) + { + return FilePathFilter(filePath.wstr() + L"/" + match.suffix().str()); + } + ) + ); + } + else + { + result.push_back(FilePathFilter(filterString)); + } + } + else + { + const FilePath p = m_projectSettings->makePathExpandedAndAbsolute(FilePath(filterString)); + const bool isFile = p.exists() && !p.isDirectory(); + std::set symLinkPaths = FileSystem::getSymLinkedDirectories(p); symLinkPaths.insert(p); utility::append(result, utility::convert( utility::toVector(symLinkPaths), - [match](const FilePath& filePath) + [isFile](const FilePath& filePath) { - return FilePathFilter(filePath.wstr() + L"/" + match.suffix().str()); + return FilePathFilter(filePath.wstr() + (isFile ? L"" : L"**")); } ) ); } - else - { - result.push_back(filter); - } - } - else - { - const FilePath p = m_projectSettings->makePathExpandedAndAbsolute(FilePath(filterString)); - const bool isFile = p.exists() && !p.isDirectory(); - - std::set symLinkPaths = FileSystem::getSymLinkedDirectories(p); - symLinkPaths.insert(p); - - utility::append(result, - utility::convert( - utility::toVector(symLinkPaths), - [isFile](const FilePath& filePath) - { - return FilePathFilter(filePath.wstr() + (isFile ? L"" : L"**")); - } - ) - ); } } diff --git a/src/lib/utility/file/FilePathFilter.h b/src/lib/utility/file/FilePathFilter.h index b19e7695..be606756 100644 --- a/src/lib/utility/file/FilePathFilter.h +++ b/src/lib/utility/file/FilePathFilter.h @@ -9,7 +9,7 @@ class FilePathFilter { public: - FilePathFilter(const std::wstring& filterString); + explicit FilePathFilter(const std::wstring& filterString); std::wstring wstr() const; diff --git a/src/lib_cxx/project/SourceGroupCxxCdb.cpp b/src/lib_cxx/project/SourceGroupCxxCdb.cpp index 8e7caa27..893d2c0d 100644 --- a/src/lib_cxx/project/SourceGroupCxxCdb.cpp +++ b/src/lib_cxx/project/SourceGroupCxxCdb.cpp @@ -68,8 +68,8 @@ std::vector> SourceGroupCxxCdb::getIndexerComman const std::vector compilerFlags = m_settings->getCompilerFlags(); - std::set indexedPaths = getIndexedPaths(); - std::set excludeFilters = getExcludeFilters(); + const std::set indexedPaths = getIndexedPaths(); + const std::set excludeFilters = getExcludeFilters(); std::vector> indexerCommands; @@ -108,7 +108,7 @@ std::vector> SourceGroupCxxCdb::getIndexerComman indexerCommands.push_back(std::make_shared( sourcePath, indexedPaths, - getExcludeFilters(), + excludeFilters, FilePath(utility::decodeFromUtf8(command.Directory)), utility::concat( utility::convert(command.CommandLine, [](const std::string& arg) { return utility::decodeFromUtf8(arg); }), diff --git a/src/lib_cxx/project/SourceGroupCxxEmpty.cpp b/src/lib_cxx/project/SourceGroupCxxEmpty.cpp index c67dbcfa..f312520e 100644 --- a/src/lib_cxx/project/SourceGroupCxxEmpty.cpp +++ b/src/lib_cxx/project/SourceGroupCxxEmpty.cpp @@ -51,8 +51,8 @@ std::vector> SourceGroupCxxEmpty::getIndexerComm utility::append(compilerFlags, m_settings->getCompilerFlags()); - std::set indexedPaths = getIndexedPaths(); - std::set excludeFilters = getExcludeFilters(); + const std::set indexedPaths = getIndexedPaths(); + const std::set excludeFilters = getExcludeFilters(); std::vector> indexerCommands; for (const FilePath& sourcePath: getAllSourceFilePaths())